Codeforces Gym 100372A
来源:互联网 发布:ubuntu zendstudio 编辑:程序博客网 时间:2024/05/10 06:33
很少有人做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;}
- Codeforces Gym 100372A
- codeforces gym 100645A
- CodeForces Gym 100803A
- codeforces Gym 101102A
- 【Codeforces Gym 100187A】
- Codeforces Gym 100340A Cookies
- codeforces gym 100827A Runes
- Codeforces GYM 100340A Cookies
- Codeforces gym 101343 A 数论
- Codeforces gym 101350A dp
- Codeforces gym 101102 A dp
- Codeforces Rating Gym-101028A
- Codeforces Gym 100889 A. A Beautiful Array
- CodeForces Gym 100989A LCS (A)
- Codeforces Gym 101158 A. Rearranging a Sequence
- Codeforces Gym 100345A BibTeX 模拟
- codeforces Gym 100187 A. Potion of Immortality
- CodeForces Gym 100989H Queue (A)
- 16个Linux服务器监控命令
- 今年是鸡年第一天!
- 关于传值传引用,const的使用
- 浅析JAVA SOCKET及TCP/IP协议
- ABP入门系列(7)——分页实现_0
- Codeforces Gym 100372A
- Codeforces Round #278 (Div. 1) C. Prefix Product Sequence 模逆元,构造 2017/1/25
- leetcode 492 Construct the Rectangle
- 浅谈自己的学习之路
- AI(四)- 微信与luis结合(下)
- pandas基本函数
- 剑指offer——顺时针打印矩阵
- 数组下标越界解析(以C语言为例)
- Andriod ADB Interface驱动安装失败Configure USB Debug for Android