#include <iostream>
#include <set>
using namespace std;
typedef pair<int,int> pii;
int N,M;
int H[100005];
int t,x,y;
multiset<int> A,B;
multiset<pii> P;
void add(int i){
if(i==-1 or i==N-1)
return;
int a=H[i];
int b=H[i+1];
if(a>b)
swap(a,b);
P.insert({a,b});
/*
A.insert(a);
B.insert(b);
*/
}
void remove(int i){
if(i==-1 or i==N-1)
return;
int a=H[i];
int b=H[i+1];
if(a>b)
swap(a,b);
P.erase(P.find({a,b}));
/*
A.erase(a);
B.erase(b);
*/
}
int query(int h){
int res=0;
for(pii p:P)
if(p.first<h and h<p.second)
res++;
return res;
/*
for(int x:A)
if(x<h)
res++;
for(int x:B)
if(x<h)
res--;
return res;
*/
}
/*
void print(){
cout<<"******\n";
cout<<"startUp ";
for(int x:startUp)
cout<<x<<" ";
cout<<"\n";
cout<<"startDown ";
for(int x:startDown)
cout<<x<<" ";
cout<<"\n";
cout<<"endUp ";
for(int x:endUp)
cout<<x<<" ";
cout<<"\n";
cout<<"endDown ";
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 |
376 KB |
Output is correct |
2 |
Correct |
12 ms |
376 KB |
Output is correct |
3 |
Correct |
12 ms |
376 KB |
Output is correct |
4 |
Correct |
13 ms |
380 KB |
Output is correct |
5 |
Correct |
13 ms |
376 KB |
Output is correct |
6 |
Correct |
13 ms |
376 KB |
Output is correct |
7 |
Correct |
13 ms |
376 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
12 ms |
376 KB |
Output is correct |
3 |
Correct |
12 ms |
376 KB |
Output is correct |
4 |
Correct |
13 ms |
380 KB |
Output is correct |
5 |
Correct |
13 ms |
376 KB |
Output is correct |
6 |
Correct |
13 ms |
376 KB |
Output is correct |
7 |
Correct |
13 ms |
376 KB |
Output is correct |
8 |
Execution timed out |
1072 ms |
5392 KB |
Time limit exceeded |
9 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
12 ms |
376 KB |
Output is correct |
3 |
Correct |
12 ms |
376 KB |
Output is correct |
4 |
Correct |
13 ms |
380 KB |
Output is correct |
5 |
Correct |
13 ms |
376 KB |
Output is correct |
6 |
Correct |
13 ms |
376 KB |
Output is correct |
7 |
Correct |
13 ms |
376 KB |
Output is correct |
8 |
Execution timed out |
1072 ms |
5392 KB |
Time limit exceeded |
9 |
Halted |
0 ms |
0 KB |
- |