#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ARRS ((ll)(4e5+100))
#define fr first
#define sc second
#define pb push_back
#define MX ((ll)(1e9+100))
#define MAX ((ll)(1e18+100))
int n,q;
int a[ARRS];
int up[ARRS];
int type[ARRS];
pair<int, int> compress[ARRS];
int fw[2*ARRS];
int quer(int idx){
int pas=0;
for(;idx;idx-=idx&-idx)
pas+=fw[idx];
return pas;
}
void updt(int idx, int val){
for(;idx<ARRS;idx+=idx&-idx)
fw[idx]+=val;
}
void update_quer(int i, int k){
if(i&&a[i-1]>a[i]){
updt(a[i]+1, k);
updt(a[i-1]+1, -k);
//cout<<( a[i]+1 )<<" "<<a[i-1]<<" "<<k<<endl;
}
}
int main(){
cin>>n>>q;
for(int i=0; i<n; i++){
cin>>a[i];
compress[i]={a[i],i};
}
a[n]=0;
compress[n]={a[n],n};
n++;
for(int i=n; i<n+q; i++){
cin>>type[i];
if(type[i] == 1){//query
cin>>a[i];
}
else {//update
cin>>up[i]>>a[i];
up[i]--;
}
compress[i]={a[i],i};
}
sort(compress, compress+n+q);
ll c=1;
for(int i=0; i<n+q; i++){
if(i&&compress[i].fr!=compress[i-1].fr)
c++;
a[compress[i].sc]=c;
}
for(int i=0; i<n+q; i++){
cout<<a[i]<<endl;
}
cout<<endl;
for(int i=0; i<n; i++)
update_quer(i, 1);
for(int i=n; i<n+q; i++){
if(type[i] == 1){
cout<<quer(a[i])<<endl;
}
else {
update_quer(up[i], -1);
update_quer(up[i]+1, -1);
a[up[i]]=a[i];
update_quer(up[i], 1);
update_quer(up[i]+1, 1);
}
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
504 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
27 ms |
504 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
504 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |