您的位置:首页 > 其它

Codeforces Gym 100372A

2017-01-28 14:49 465 查看

很少有人做Gym的题目,但其实Gym的题目还是不错的,先来水题一道 100372A

Sergey and reduction

Input file: stdin

Output 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;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: