#include <bits/stdc++.h>
using namespace std;
#define a first
#define b second
#define pb push_back
typedef long long llo;
//#define endl '\n'
int n,m;
int it[100001];
int tree[1000001];
void u(int i,int j){
while(i<1000001){
tree[i]+=j;
i+=(i&-i);
}
}
int ss(int i){
int su=0;
while(i>0){
su+=tree[i];
i-=(i&-i);
}
return su;
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin>>n>>m;
for(int i=0;i<n;i++){
cin>>it[i];
}
for(int i=0;i<n-1;i++){
int aa=min(it[i],it[i+1]);
int bb=max(it[i],it[i+1]);
u(aa,1);
u(bb,-1);
}
for(int ii=0;ii<m;ii++){
int tt;
cin>>tt;
if(tt==1){
int i,val;
cin>>i>>val;
i--;
if(i>0){
int aa=min(it[i],it[i-1]);
int bb=max(it[i],it[i-1]);
u(aa,-1);
u(bb,1);
}
if(i<n-1){
int aa=min(it[i],it[i+1]);
int bb=max(it[i],it[i+1]);
u(aa,-1);
u(bb,1);
}
it[i]=val;
if(i>0){
int aa=min(it[i],it[i-1]);
int bb=max(it[i],it[i-1]);
u(aa,1);
u(bb,-1);
}
if(i<n-1){
int aa=min(it[i],it[i+1]);
int bb=max(it[i],it[i+1]);
u(aa,1);
u(bb,-1);
}
}
else{
int aa;
cin>>aa;
cout<<ss(aa)<<'\n';
}
}
//
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
3 ms |
3968 KB |
Output is correct |
3 |
Correct |
3 ms |
3968 KB |
Output is correct |
4 |
Correct |
3 ms |
3968 KB |
Output is correct |
5 |
Correct |
3 ms |
3840 KB |
Output is correct |
6 |
Correct |
3 ms |
3968 KB |
Output is correct |
7 |
Correct |
1 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
3 ms |
3968 KB |
Output is correct |
3 |
Correct |
3 ms |
3968 KB |
Output is correct |
4 |
Correct |
3 ms |
3968 KB |
Output is correct |
5 |
Correct |
3 ms |
3840 KB |
Output is correct |
6 |
Correct |
3 ms |
3968 KB |
Output is correct |
7 |
Correct |
1 ms |
384 KB |
Output is correct |
8 |
Correct |
38 ms |
1784 KB |
Output is correct |
9 |
Correct |
51 ms |
6904 KB |
Output is correct |
10 |
Correct |
60 ms |
6860 KB |
Output is correct |
11 |
Correct |
44 ms |
1656 KB |
Output is correct |
12 |
Correct |
44 ms |
2808 KB |
Output is correct |
13 |
Correct |
42 ms |
2812 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
3 ms |
3968 KB |
Output is correct |
3 |
Correct |
3 ms |
3968 KB |
Output is correct |
4 |
Correct |
3 ms |
3968 KB |
Output is correct |
5 |
Correct |
3 ms |
3840 KB |
Output is correct |
6 |
Correct |
3 ms |
3968 KB |
Output is correct |
7 |
Correct |
1 ms |
384 KB |
Output is correct |
8 |
Correct |
38 ms |
1784 KB |
Output is correct |
9 |
Correct |
51 ms |
6904 KB |
Output is correct |
10 |
Correct |
60 ms |
6860 KB |
Output is correct |
11 |
Correct |
44 ms |
1656 KB |
Output is correct |
12 |
Correct |
44 ms |
2808 KB |
Output is correct |
13 |
Correct |
42 ms |
2812 KB |
Output is correct |
14 |
Correct |
71 ms |
6904 KB |
Output is correct |
15 |
Correct |
70 ms |
6904 KB |
Output is correct |
16 |
Correct |
69 ms |
6904 KB |
Output is correct |
17 |
Correct |
69 ms |
6904 KB |
Output is correct |
18 |
Correct |
71 ms |
6904 KB |
Output is correct |