#include <bits/stdc++.h>
using namespace std;
#define ios ios::sync_with_stdio(false); cin.tie(NULL);
#define pb push_back
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define fr first
#define sc second
#define int long long
#define endl '\n'
void fopn(string name){
freopen((name+".in").c_str(),"r",stdin);
freopen((name+".out").c_str(),"w",stdout);
}
const int INF=1e18,mod=1e9+7;
vector<int> tree;
int sz;
void innit(int n){
sz=1;
while(sz<n)
sz*=2;
tree.assign(2*sz-1,0);
}
void add(int l, int r, int v,int x, int lx, int rx){
if(l>=rx || r<=lx)
return;
if(lx>=l && rx<=r){
tree[x]+=v;
return;
}
int m=(lx+rx)/2;
add(l,r,v,2*x+1,lx,m);
add(l,r,v,2*x+2,m,rx);
}
void add(int l, int r, int v){
add(l,r+1,v,0,0,sz);
}
int get(int i, int x, int lx, int rx){
if(rx==lx+1)
return tree[x];
int m=(lx+rx)/2;
if(i<m)
return get(i,2*x+1,lx,m)+tree[x];
else
return get(i,2*x+2,m,rx)+tree[x];
}
int get(int i){
return get(i,0,0,sz);
}
void st(int i, int v, int x, int lx, int rx){
if(rx-lx==1){
tree[x]=v;
return;
}
int m=(lx+rx)/2;
if(i<m)
st(i,v,2*x+1,lx,m);
else
st(i,v,2*x+2,m,rx);
tree[x]=tree[2*x+1]+tree[2*x+2];
}
void st(int i, int v){
st(i,v,0,0,sz);
}
int n,m;
void solve(){
cin>>n>>m;
vector<int> vec(n+1);
for(int i=1;i<=n;i++)
cin>>vec[i];
innit(1e6+5);
for(int i=2;i<=n;i++){
add(min(vec[i],vec[i-1]),max(vec[i],vec[i-1]),1);
}
while(m--){
int t;cin>>t;
if(t==2){
int x;cin>>x;
cout<<get(x)<<endl;
}
else{
int pos,val;cin>>pos>>val;
if(pos>1)
add(min(vec[pos],vec[pos-1]),max(vec[pos],vec[pos-1]),-1);
if(pos<n)
add(min(vec[pos],vec[pos+1]),max(vec[pos],vec[pos+1]),-1);
vec[pos]=val;
if(pos>1)
add(min(vec[pos],vec[pos-1]),max(vec[pos],vec[pos-1]),1);
if(pos<n)
add(min(vec[pos],vec[pos+1]),max(vec[pos],vec[pos+1]),1);
}
}
}
main(){
//ios;
int T=1;
//cin>>T;
while(T--){
solve();
}
}
Compilation message
game.cpp:95:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
95 | main(){
| ^~~~
game.cpp: In function 'void fopn(std::string)':
game.cpp:12:9: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
12 | freopen((name+".in").c_str(),"r",stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
game.cpp:13:9: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
13 | freopen((name+".out").c_str(),"w",stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
16724 KB |
Output is correct |
2 |
Correct |
11 ms |
16724 KB |
Output is correct |
3 |
Correct |
10 ms |
16724 KB |
Output is correct |
4 |
Correct |
11 ms |
16656 KB |
Output is correct |
5 |
Correct |
11 ms |
16692 KB |
Output is correct |
6 |
Correct |
11 ms |
16696 KB |
Output is correct |
7 |
Correct |
10 ms |
16724 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
16724 KB |
Output is correct |
2 |
Correct |
11 ms |
16724 KB |
Output is correct |
3 |
Correct |
10 ms |
16724 KB |
Output is correct |
4 |
Correct |
11 ms |
16656 KB |
Output is correct |
5 |
Correct |
11 ms |
16692 KB |
Output is correct |
6 |
Correct |
11 ms |
16696 KB |
Output is correct |
7 |
Correct |
10 ms |
16724 KB |
Output is correct |
8 |
Correct |
201 ms |
18432 KB |
Output is correct |
9 |
Correct |
285 ms |
19676 KB |
Output is correct |
10 |
Correct |
265 ms |
19636 KB |
Output is correct |
11 |
Correct |
184 ms |
18352 KB |
Output is correct |
12 |
Correct |
246 ms |
19448 KB |
Output is correct |
13 |
Correct |
241 ms |
19532 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
16724 KB |
Output is correct |
2 |
Correct |
11 ms |
16724 KB |
Output is correct |
3 |
Correct |
10 ms |
16724 KB |
Output is correct |
4 |
Correct |
11 ms |
16656 KB |
Output is correct |
5 |
Correct |
11 ms |
16692 KB |
Output is correct |
6 |
Correct |
11 ms |
16696 KB |
Output is correct |
7 |
Correct |
10 ms |
16724 KB |
Output is correct |
8 |
Correct |
201 ms |
18432 KB |
Output is correct |
9 |
Correct |
285 ms |
19676 KB |
Output is correct |
10 |
Correct |
265 ms |
19636 KB |
Output is correct |
11 |
Correct |
184 ms |
18352 KB |
Output is correct |
12 |
Correct |
246 ms |
19448 KB |
Output is correct |
13 |
Correct |
241 ms |
19532 KB |
Output is correct |
14 |
Correct |
325 ms |
19628 KB |
Output is correct |
15 |
Correct |
322 ms |
19624 KB |
Output is correct |
16 |
Correct |
318 ms |
19660 KB |
Output is correct |
17 |
Correct |
306 ms |
19708 KB |
Output is correct |
18 |
Correct |
319 ms |
19728 KB |
Output is correct |