#include <bits/stdc++.h>
#define Tree int h,int l,int r
#define Left 2*h,l,(l+r)/2
#define Right 2*h+1,(l+r)/2+1,r
using namespace std;
const int N=1e6+5;
int n,m,L,R,type,idx,val,dl,res;
int a[N],v[6*N];
void Upd(Tree) {
if (r<L || R<l) return ;
if (L<=l && r<=R) { v[h]+=dl; return ; }
Upd(Left),Upd(Right);
}
void Get(Tree) {
if (idx<l || r<idx) return ;
if (l==idx && r==idx) { res+=v[h]; return ; }
Get(Left),Get(Right);
res+=v[h];
}
main () {
scanf("%d%d",&n,&m);
for (int i=1; i<=n; i++) {
scanf("%d",&a[i]);
if (i==1) continue;
L=min(a[i],a[i-1])+1,R=max(a[i],a[i-1])-1,dl=1;
if (L<=R) Upd(1,1,1e6);
}
while (m--) {
scanf("%d",&type);
if (type==1) {
scanf("%d%d",&idx,&val);
if (idx!=1) {
L=min(a[idx],a[idx-1])+1;
R=max(a[idx],a[idx-1])-1;
dl=-1;
if (L<=R) Upd(1,1,1e6);
}
if (idx!=n) {
L=min(a[idx],a[idx+1])+1;
R=max(a[idx],a[idx+1])-1;
dl=-1;
if (L<=R) Upd(1,1,1e6);
}
a[idx]=val;
if (idx!=1) {
L=min(a[idx],a[idx-1])+1;
R=max(a[idx],a[idx-1])-1;
dl=1;
if (L<=R) Upd(1,1,1e6);
}
if (idx!=n) {
L=min(a[idx],a[idx+1])+1;
R=max(a[idx],a[idx+1])-1;
dl=1;
if (L<=R) Upd(1,1,1e6);
}
}
else {
scanf("%d",&idx);
res=0;
Get(1,1,1e6);
printf("%d\n",res);
}
}
}
Compilation message
game.cpp:23:7: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
main () {
^
game.cpp: In function 'int main()':
game.cpp:24:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d",&n,&m);
~~~~~^~~~~~~~~~~~~~
game.cpp:27:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d",&a[i]);
~~~~~^~~~~~~~~~~~
game.cpp:34:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d",&type);
~~~~~^~~~~~~~~~~~
game.cpp:36:9: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d",&idx,&val);
~~~~~^~~~~~~~~~~~~~~~~~
game.cpp:69:9: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d",&idx);
~~~~~^~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
10 ms |
6776 KB |
Output is correct |
3 |
Correct |
10 ms |
6520 KB |
Output is correct |
4 |
Correct |
10 ms |
6776 KB |
Output is correct |
5 |
Correct |
10 ms |
6648 KB |
Output is correct |
6 |
Correct |
9 ms |
6648 KB |
Output is correct |
7 |
Correct |
5 ms |
376 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
10 ms |
6776 KB |
Output is correct |
3 |
Correct |
10 ms |
6520 KB |
Output is correct |
4 |
Correct |
10 ms |
6776 KB |
Output is correct |
5 |
Correct |
10 ms |
6648 KB |
Output is correct |
6 |
Correct |
9 ms |
6648 KB |
Output is correct |
7 |
Correct |
5 ms |
376 KB |
Output is correct |
8 |
Correct |
74 ms |
1272 KB |
Output is correct |
9 |
Correct |
153 ms |
11196 KB |
Output is correct |
10 |
Correct |
155 ms |
11132 KB |
Output is correct |
11 |
Correct |
61 ms |
1528 KB |
Output is correct |
12 |
Correct |
112 ms |
3064 KB |
Output is correct |
13 |
Correct |
111 ms |
2808 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
10 ms |
6776 KB |
Output is correct |
3 |
Correct |
10 ms |
6520 KB |
Output is correct |
4 |
Correct |
10 ms |
6776 KB |
Output is correct |
5 |
Correct |
10 ms |
6648 KB |
Output is correct |
6 |
Correct |
9 ms |
6648 KB |
Output is correct |
7 |
Correct |
5 ms |
376 KB |
Output is correct |
8 |
Correct |
74 ms |
1272 KB |
Output is correct |
9 |
Correct |
153 ms |
11196 KB |
Output is correct |
10 |
Correct |
155 ms |
11132 KB |
Output is correct |
11 |
Correct |
61 ms |
1528 KB |
Output is correct |
12 |
Correct |
112 ms |
3064 KB |
Output is correct |
13 |
Correct |
111 ms |
2808 KB |
Output is correct |
14 |
Correct |
239 ms |
11172 KB |
Output is correct |
15 |
Correct |
243 ms |
11232 KB |
Output is correct |
16 |
Correct |
245 ms |
11224 KB |
Output is correct |
17 |
Correct |
250 ms |
11128 KB |
Output is correct |
18 |
Correct |
245 ms |
11128 KB |
Output is correct |