#include <bits/stdc++.h>
using namespace std;
const int N = 1e6, maxn=1e5+5;
int t[N+5],a[maxn];
int n;
void add(int k, int x) {
while (k <= N) {
t[k] += x;
k += k&-k;
}
}
void gosh(int a, int b, int val){
if(a>b) swap(a,b);
add(a,val);
add(b+1,-val);
}
int sum(int k) {
int s = 0;
while (k >= 1) {
s += t[k];
k -= k&-k;
}
return s;
}
int main(){
ios_base :: sync_with_stdio(0), cin.tie(0), cout.tie(0);
cin>>n;
int q;
cin>>q;
for(int i=1;i<=n;i++) cin>>a[i];
for(int i=1;i<n;i++) gosh(a[i],a[i+1],1);
int pos, val, type;
while(q--){
cin>>type;
if(type==1){
cin>>pos>>val;
if(pos>1) gosh(a[pos-1],a[pos],-1);
if(pos<n) gosh(a[pos],a[pos+1],-1);
a[pos] = val;
if(pos>1) gosh(a[pos-1],a[pos],1);
if(pos<n) gosh(a[pos],a[pos+1],1);
}
else{
cin>>pos;
cout << sum(pos) << endl;
}
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
6472 KB |
Output is correct |
2 |
Correct |
6 ms |
6472 KB |
Output is correct |
3 |
Correct |
0 ms |
6472 KB |
Output is correct |
4 |
Correct |
0 ms |
6472 KB |
Output is correct |
5 |
Correct |
13 ms |
6472 KB |
Output is correct |
6 |
Correct |
0 ms |
6472 KB |
Output is correct |
7 |
Correct |
3 ms |
6472 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
6472 KB |
Output is correct |
2 |
Correct |
6 ms |
6472 KB |
Output is correct |
3 |
Correct |
0 ms |
6472 KB |
Output is correct |
4 |
Correct |
0 ms |
6472 KB |
Output is correct |
5 |
Correct |
13 ms |
6472 KB |
Output is correct |
6 |
Correct |
0 ms |
6472 KB |
Output is correct |
7 |
Correct |
3 ms |
6472 KB |
Output is correct |
8 |
Runtime error |
189 ms |
6472 KB |
Execution timed out (wall clock limit exceeded) |
9 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
6472 KB |
Output is correct |
2 |
Correct |
6 ms |
6472 KB |
Output is correct |
3 |
Correct |
0 ms |
6472 KB |
Output is correct |
4 |
Correct |
0 ms |
6472 KB |
Output is correct |
5 |
Correct |
13 ms |
6472 KB |
Output is correct |
6 |
Correct |
0 ms |
6472 KB |
Output is correct |
7 |
Correct |
3 ms |
6472 KB |
Output is correct |
8 |
Runtime error |
189 ms |
6472 KB |
Execution timed out (wall clock limit exceeded) |
9 |
Halted |
0 ms |
0 KB |
- |