typedef long long ll;
ll pie(ll army){return (1ll<<army);}
#include <bits/stdc++.h>
#define fr first
#define sc second
#define pb push_back
#define endl '\n'
#define mid ((left+right)>>1)
const ll inf=2000000000000000005;
const int sonsuz=2000000005;
using namespace std;
ll fpow(ll x,ll y,ll m=0){if(y<0){cout<<"powError";return -1;}if(m)x%=m;ll res=1;while(y>0){if(y&1)res*=x;x*=x;if(m){x%=m;res%=m;}y>>=1;}return res;}
struct Fen{
int n;
vector<int>tree;
void init(int N){
n=N;
tree.resize(n+1,0);
}
void update(int tar,int x){
while(tar<=n){
tree[tar]+=x;
tar+=(tar&-tar);
}
}
int query(int tar){
int res=0;
while(tar){
res+=tree[tar];
tar-=(tar&-tar);
}
return res;
}
};
int n,q;
int arr[100023];
Fen fen;
void code(){
cin>>n>>q;
fen.init(1e6);
for(int i=1;i<=n;i++){
cin>>arr[i];
if(i!=1){
int left=min(arr[i],arr[i-1]),right=max(arr[i],arr[i-1]);
fen.update(left,1);
fen.update(right,-1);
}
}
while(q--){
int c;cin>>c;
if(c==1){
int i,y;cin>>i>>y;
if(i!=1){
int left=min(arr[i],arr[i-1]),right=max(arr[i],arr[i-1]);
fen.update(left,-1);
fen.update(right,1);
}
if(i!=n){
int left=min(arr[i],arr[i+1]),right=max(arr[i],arr[i+1]);
fen.update(left,-1);
fen.update(right,1);
}
arr[i]=y;
if(i!=1){
int left=min(arr[i],arr[i-1]),right=max(arr[i],arr[i-1]);
fen.update(left,1);
fen.update(right,-1);
}
if(i!=n){
int left=min(arr[i],arr[i+1]),right=max(arr[i],arr[i+1]);
fen.update(left,1);
fen.update(right,-1);
}
}
else{
int y;cin>>y;
cout<<fen.query(y)<<endl;
}
}
}
int main(){
ios_base::sync_with_stdio(false);cin.tie(NULL);
bool usaco=0;if(usaco){freopen(".in","r",stdin);freopen(".out","w",stdout);}
int t=1;
if(!t)cin>>t;
while(t--){code();}
return 0;
}
Compilation message (stderr)
game.cpp: In function 'int main()':
game.cpp:87:39: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
87 | bool usaco=0;if(usaco){freopen(".in","r",stdin);freopen(".out","w",stdout);}
| ~~~~~~~^~~~~~~~~~~~~~~~~
game.cpp:87:64: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
87 | bool usaco=0;if(usaco){freopen(".in","r",stdin);freopen(".out","w",stdout);}
| ~~~~~~~^~~~~~~~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |