#include <iostream>
#include <set>
using namespace std;
int N,M;
int H[100005];
int t,x,y;
multiset<int> startUp, startDown, endUp, endDown;
void add(int i){
if(i==-1 or i==N-1)
return;
if(H[i]<H[i+1]){
startUp.insert(H[i]);
endUp.insert(H[i+1]);
}
else{
startDown.insert(H[i]);
endDown.insert(H[i+1]);
}
}
void remove(int i){
if(i==-1 or i==N-1)
return;
if(H[i]<H[i+1]){
startUp.erase(H[i]);
endUp.erase(H[i+1]);
}
else{
startDown.erase(H[i]);
endDown.erase(H[i+1]);
}
}
int query(int h){
int a,b,res=0;
a=b=0;
for(int x:startUp)
if(x<h)
a++;
for(int x:endUp)
if(x<h)
b++;
res+=a-b;
a=b=0;
for(int x:startDown)
if(x>h)
a++;
for(int x:endDown)
if(x>h)
b++;
res+=a-b;
return res;
}
void print(){
cout<<"******\n";
for(int x:startUp)
cout<<x<<" ";
cout<<"\n";
for(int x:startDown)
cout<<x<<" ";
cout<<"\n";
for(int x:endUp)
cout<<x<<" ";
cout<<"\n";
for(int x:endDown)
cout<<x<<" ";
cout<<"\n";
cout<<"******\n";
}
int main(){
cin>>N>>M;
for(int i=0;i<N;i++)
cin>>H[i];
for(int i=0;i<N-1;i++)
add(i);
while(M--){
cin>>t;
if(t==1){
cin>>x>>y;
x--;
remove(x-1);
remove(x);
H[x]=y;
add(x-1);
add(x);
}
else{
cin>>x;
cout<<query(x)<<"\n";
}
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
476 KB |
Output is correct |
2 |
Correct |
17 ms |
248 KB |
Output is correct |
3 |
Incorrect |
17 ms |
376 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
476 KB |
Output is correct |
2 |
Correct |
17 ms |
248 KB |
Output is correct |
3 |
Incorrect |
17 ms |
376 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
476 KB |
Output is correct |
2 |
Correct |
17 ms |
248 KB |
Output is correct |
3 |
Incorrect |
17 ms |
376 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |