Codeforces Gym 100372A

很少有人做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;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值