#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pii pair<int,int>
#define OK puts("OK");
#define fr first
#define sc second
#define ret return
#define scan1(a) scanf("%lld",&a);
#define scan2(a,b) scanf("%lld %lld",&a, &b);
#define scan3(a,b,c) scanf("%lld %lld %lld",&a,&b,&c);
#define all(s) s.begin(),s.end()
#define pb push_back
#define endi puts("");
const int N = 1e6+12,INF=1e9+7;
int q[N],t[N],der[N*4];
void update(int v,int l,int r,int ql,int qr,int x){
if (l > qr || r < ql)ret;
if (ql <= l && r <= qr){
der[v] += x;
ret ;
}
int m = l+r>>1;
update(v<<1,l,m,ql,qr,x);
update((v<<1)+1,m+1,r,ql,qr,x);
}
int get_sum (int v, int l, int r, int pos) {
if (l == r)ret der[v];
int m = l+r>>1;
if (m < pos)
ret der[v]+get_sum((v<<1)+1,m+1,r,pos);
else
ret der[v]+get_sum(v<<1,l,m,pos);
}
main(){
int m,i,j,k,b,n;
scan2(n,m)
for (i=1;i<=n;++i){
scan1(q[i])
if (i!=1)
update(1,1,1000000,min(q[i-1],q[i]),max(q[i-1],q[i]),1);
}
while (m--){
int t,z;
scan2(t,z)
if (t == 1){
if (z != 1)
update(1,1,1000000,min(q[z-1],q[z]),max(q[z-1],q[z]),-1);
if (z != n)
update(1,1,1000000,min(q[z+1],q[z]),max(q[z+1],q[z]),-1);
int x;
scan1(x)
q[z] = x;
if (z != 1)
update(1,1,1000000,min(q[z-1],q[z]),max(q[z-1],q[z]),1);
if (z != n)
update(1,1,1000000,min(q[z+1],q[z]),max(q[z+1],q[z]),1);
}
else
cout <<get_sum(1,1,1000000,z)<<'\n';
}
}
Compilation message
game.cpp: In function 'void update(long long int, long long int, long long int, long long int, long long int, long long int)':
game.cpp:24:14: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
24 | int m = l+r>>1;
| ~^~
game.cpp: In function 'long long int get_sum(long long int, long long int, long long int, long long int)':
game.cpp:31:11: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
31 | int m = l+r>>1;
| ~^~
game.cpp: At global scope:
game.cpp:41:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
41 | main(){
| ^
game.cpp: In function 'int main()':
game.cpp:42:13: warning: unused variable 'j' [-Wunused-variable]
42 | int m,i,j,k,b,n;
| ^
game.cpp:42:15: warning: unused variable 'k' [-Wunused-variable]
42 | int m,i,j,k,b,n;
| ^
game.cpp:42:17: warning: unused variable 'b' [-Wunused-variable]
42 | int m,i,j,k,b,n;
| ^
game.cpp:10:25: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
10 | #define scan2(a,b) scanf("%lld %lld",&a, &b);
| ~~~~~^~~~~~~~~~~~~~~~~~~~
game.cpp:43:5: note: in expansion of macro 'scan2'
43 | scan2(n,m)
| ^~~~~
game.cpp:9:23: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
9 | #define scan1(a) scanf("%lld",&a);
| ~~~~~^~~~~~~~~~~
game.cpp:45:9: note: in expansion of macro 'scan1'
45 | scan1(q[i])
| ^~~~~
game.cpp:10:25: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
10 | #define scan2(a,b) scanf("%lld %lld",&a, &b);
| ~~~~~^~~~~~~~~~~~~~~~~~~~
game.cpp:52:9: note: in expansion of macro 'scan2'
52 | scan2(t,z)
| ^~~~~
game.cpp:9:23: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
9 | #define scan1(a) scanf("%lld",&a);
| ~~~~~^~~~~~~~~~~
game.cpp:59:13: note: in expansion of macro 'scan1'
59 | scan1(x)
| ^~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
8 ms |
9708 KB |
Output is correct |
3 |
Correct |
8 ms |
9324 KB |
Output is correct |
4 |
Correct |
8 ms |
9324 KB |
Output is correct |
5 |
Correct |
8 ms |
9452 KB |
Output is correct |
6 |
Correct |
8 ms |
9580 KB |
Output is correct |
7 |
Correct |
3 ms |
540 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
8 ms |
9708 KB |
Output is correct |
3 |
Correct |
8 ms |
9324 KB |
Output is correct |
4 |
Correct |
8 ms |
9324 KB |
Output is correct |
5 |
Correct |
8 ms |
9452 KB |
Output is correct |
6 |
Correct |
8 ms |
9580 KB |
Output is correct |
7 |
Correct |
3 ms |
540 KB |
Output is correct |
8 |
Correct |
63 ms |
1644 KB |
Output is correct |
9 |
Correct |
133 ms |
18412 KB |
Output is correct |
10 |
Correct |
135 ms |
18548 KB |
Output is correct |
11 |
Correct |
53 ms |
1516 KB |
Output is correct |
12 |
Correct |
92 ms |
2468 KB |
Output is correct |
13 |
Correct |
59 ms |
2028 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
8 ms |
9708 KB |
Output is correct |
3 |
Correct |
8 ms |
9324 KB |
Output is correct |
4 |
Correct |
8 ms |
9324 KB |
Output is correct |
5 |
Correct |
8 ms |
9452 KB |
Output is correct |
6 |
Correct |
8 ms |
9580 KB |
Output is correct |
7 |
Correct |
3 ms |
540 KB |
Output is correct |
8 |
Correct |
63 ms |
1644 KB |
Output is correct |
9 |
Correct |
133 ms |
18412 KB |
Output is correct |
10 |
Correct |
135 ms |
18548 KB |
Output is correct |
11 |
Correct |
53 ms |
1516 KB |
Output is correct |
12 |
Correct |
92 ms |
2468 KB |
Output is correct |
13 |
Correct |
59 ms |
2028 KB |
Output is correct |
14 |
Correct |
261 ms |
18048 KB |
Output is correct |
15 |
Correct |
241 ms |
18028 KB |
Output is correct |
16 |
Correct |
246 ms |
18012 KB |
Output is correct |
17 |
Correct |
240 ms |
18028 KB |
Output is correct |
18 |
Correct |
238 ms |
18008 KB |
Output is correct |