#include<iostream>
#include<stack>
#include<map>
#include<vector>
#include<string>
#include<unordered_map>
#include <queue>
#include<cstring>
#include<limits.h>
#include<cmath>
#include<set>
#include<algorithm>
#include<bitset>
using namespace std;
#define ll long long
#define f first
#define endl "\n"
#define s second
#define pii pair<int,int>
#define ppii pair<int,pii>
#define vi vector<int>
#define pb push_back
//#define p push
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define F(n) for(int i=0;i<n;i++)
#define lb lower_bound
#define ub upper_bound
#define fastio ios::sync_with_stdio(false);cin.tie(NULL);
using namespace std;
#define int long long
const int mod=9901,mxn=5*1e5+5,inf=1e18,lg=25,minf=-1e18;
int fwk[mxn+10],n;
void update(int pos,int val){for(int i=pos+1;i<=n;i+=i&-i)fwk[i]+=val;}
int qry(int pos){
int sum=0;
for(int i=pos+1;i>0;i-=(i&-i))sum+=fwk[i];
return sum;
}
vector<int>a,v;
vector<ppii>q;
unordered_map<int,int>p;
void upd(int l,int r,int yes){
if(v[r]<v[l])swap(l,r);
update(p[v[l]],yes);
update(p[v[r]]+1,-yes);
}
int32_t main(){
fastio
int m,pos,val;cin>>n>>m;
v.resize(n);
for(int i=0;i<n;i++)cin>>v[i],a.pb(v[i]);
for(int i=0;i<m;i++){
int t;cin>>t;
if(t==1)cin>>pos>>val;
else cin>>val;
a.pb(val);
q.pb({t,{val,pos-1}});
}
sort(all(a));
n=a.size();
for(int i=0;i<a.size();i++)p[a[i]]=i;
for(int i=0;i<v.size()-1;i++)upd(i,i+1,1);
for(auto i:q){
if(i.f==2)cout<<qry(p[i.s.f])<<'\n';
else{
if(i.s.s)upd(i.s.s-1,i.s.s,-1);
if(i.s.s<n-1)upd(i.s.s,i.s.s+1,-1);
v[i.s.s]=i.s.f;
if(i.s.s)upd(i.s.s-1,i.s.s,1);
if(i.s.s<n-1)upd(i.s.s,i.s.s+1,1);
}
}
}
Compilation message
game.cpp: In function 'int32_t main()':
game.cpp:62:15: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
62 | for(int i=0;i<a.size();i++)p[a[i]]=i;
| ~^~~~~~~~~
game.cpp:63:15: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
63 | for(int i=0;i<v.size()-1;i++)upd(i,i+1,1);
| ~^~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
604 KB |
Output is correct |
3 |
Correct |
1 ms |
640 KB |
Output is correct |
4 |
Incorrect |
1 ms |
476 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
604 KB |
Output is correct |
3 |
Correct |
1 ms |
640 KB |
Output is correct |
4 |
Incorrect |
1 ms |
476 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
604 KB |
Output is correct |
3 |
Correct |
1 ms |
640 KB |
Output is correct |
4 |
Incorrect |
1 ms |
476 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |