Codeforces Gym 100372A
2017-01-28 14:49
465 查看
很少有人做Gym的题目,但其实Gym的题目还是不错的,先来水题一道 100372A
Sergey and reduction
Input file: stdinOutput file: stdout
Time limit: 2 sec
Memory limit: 256 Мb
Sergey has an array of n of integers a1, a2, · · · , an. He wants to be able to respond to two types of queries:
• 0 l r e — for each i (l ≤ i ≤ r) execute ai = ai − e
• 1 l r — find out the count of i (l ≤ i ≤ r), that ai ≤ 0
Help Sergey to make an answer to m queries.
Input
The first line contains two integers n, m (2 ≤ n ≤ 4000, 1 ≤ m ≤ 35000). The next line contains n integers a1, a2,
· · · , an (0 ≤ ai ≤ 109
). The next m lines contains queries, as was discovered in legend. If the query is like 0 l r e,
works the following restriction 1 ≤ l ≤ r ≤ n, 0 ≤ e ≤ 109
.
Output
For each query like 1 l r print an answer in a separate line.
Example
stdin stdout
3 6
1 2 3
0 2 3 1
1 1 3
0 2 2 1
1 1 3
0 1 3 1
1 1 2
0
1
2
题目大意如下 : 有0号操作和1号操作 {
0号操作 :将A[l] ~ A[r] 中的数值全部减去e
1号操作 :在A[l]~ A[r] 中查找数值小于0的个数}
#include <iostream> #include <cstdio> #include <cmath> #include <algorithm> #include <vector> #include <queue> #include <stack> #include <string> #include <cstring> using namespace std; const int maxn = 40000; int q[40001]; void input0(int l,int r,int e){ for (int i=l;i<=r;++i){ q[i] -= e; } return; } int input1(int l,int r){ int cnt=0; for (int i=l;i<=r;++i){ cnt += (q[i]<=0); } return cnt; } int main(){ int n,m; cin >> n >> m; for (int i=1;i<=n;++i)cin >> q[i]; for (int i=1;i<=m;++i){ int t; scanf("%d",&t); if (!t){ int l,r,e; scanf("%d%d%d",&l,&r,&e); input0(l,r,e); } else{ int l,r; scanf("%d%d",&l,&r); printf("%d\n",input1(l,r)); } } return 0; }
相关文章推荐
- CodeForces Gym 100646G The Worm Turns DFS
- UVA Live 7958 (Codeforces Gym 101201G) Maximum Islands 二分图染色+匹配
- Codeforces Gym 100803F There is No Alternative 暴力Kruskal
- Codeforces Gym 2015 ACM Arabella Collegiate Programming Contest(二月十日训练赛)
- Codeforces Gym 100463D Evil DFS
- codeforces gym 100357 J (网络流)
- codeforces Gym 100187 A. Potion of Immortality
- Codeforces Gym 100637A A. Nano alarm-clocks 前缀和
- codeforces Gym 100500 J. Bye Bye Russia
- Codeforces Gym 100637A A. Nano alarm-clocks 前缀和的利用
- codeforces Gym 100286J Javanese Cryptoanalysis (二染色)
- 【数位DP】Codeforces Gym 100418J Lucky tickets
- Codeforces Gym 100650C The Game of Efil DFS
- 【模拟】NEERC15 A Adjustment Office (Codeforces GYM 100851)
- 【模拟】NEERC15 G Generators(2015-2016 ACM-ICPC)(Codeforces GYM 100851)
- Codeforces Gym 100203G Good elements 暴力乱搞
- Codeforces Gym 100431D Bubble Sort 水题乱搞
- Codeforces Gym 100338B Geometry Problem 计算几何
- 【宽搜】ECNA 2015 D Rings (Codeforces GYM 100825)
- CodeForcesGym 100548G The Problem to Slow Down You