#include<bits/stdc++.h>
using namespace std;
int tr[1000001];
void update(int ind, int val){
while(ind<=1000001){
tr[ind]+=val;
ind+=ind&-ind;
}
}
int get(int ind){
int ans=0;
while(ind){
ans+=tr[ind];
ind-=ind&-ind;
}
return ans;
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
memset(tr, 0, sizeof tr);
int n, m, pos, val, t;
cin >> n >> m;
int a[n+1];
for(int i=1; i<=n; i++){
cin >> a[i];
if(i>1){
update(min(a[i], a[i-1]), 1);
update(max(a[i], a[i-1]), -1);
}
}
while(m--){
cin >> t;
if(t==1){
cin >> pos >> val;
if(pos>1){
update(min(a[pos], a[pos-1]), -1);
update(max(a[pos], a[pos-1])+1, 1);
}
if(pos+1<=n){
update(min(a[pos], a[pos+1]), -1);
update(max(a[pos], a[pos+1])+1, 1);
}
a[pos]=val;
if(pos>1){
update(min(a[pos], a[pos-1]), 1);
update(max(a[pos], a[pos-1])+1, -1);
}
if(pos+1<=n){
update(min(a[pos], a[pos+1]), 1);
update(max(a[pos], a[pos+1])+1, -1);
}
}
else{
cin >> val;
cout << get(val) << endl;
}
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
4220 KB |
Output is correct |
2 |
Correct |
8 ms |
4524 KB |
Output is correct |
3 |
Incorrect |
8 ms |
4532 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
4220 KB |
Output is correct |
2 |
Correct |
8 ms |
4524 KB |
Output is correct |
3 |
Incorrect |
8 ms |
4532 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
4220 KB |
Output is correct |
2 |
Correct |
8 ms |
4524 KB |
Output is correct |
3 |
Incorrect |
8 ms |
4532 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |