#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<set>
#include<unordered_set>
#include<unordered_map>
#include"bubblesort2.h"
using namespace std;
typedef long long ll;
typedef vector<int> vll;
#define chmax(a,b) a=max(a,b)
#define chmin(a,b) a=min(a,b)
#define all(x) x.begin(),x.end()
#define rep(i,n) for(int i=0;i<n;i++)
#define mod 1000000007
#define mad(a,b) a=(a+b)%mod
#define N 100010
class RAQRMQ{
public:
ll dat[2*N],laz[2*N];
void init(){
rep(i,2*N)dat[i]=-1e17,laz[i]=0;
}
ll eval(ll k){
if(k<N)laz[k*2]+=laz[k],laz[k*2+1]+=laz[k];
dat[k]+=laz[k],laz[k]=0;
return dat[k];
}
void add(ll l,ll r,ll x){
l+=N,r+=N+1;
for(ll a=l,b=r;a<b;a>>=1,b>>=1){
if(a&1)laz[a++]+=x;
if(b&1)laz[--b]+=x;
}
for(ll a=l,b=r;a+b;a>>=1,b>>=1){
dat[a/2]=max(eval(a),eval(a^1));
dat[b/2]=max(eval(b),eval(b^1));
}
}
ll qry(ll l,ll r){
l+=N,r+=N+1;
for(ll d=20;~d;d--){eval(l>>d);eval(r>>d);}
ll res=-1e17;
for(ll a=l,b=r;a<b;a>>=1,b>>=1){
if(a&1){chmax(res,eval(a));a++;}
if(b&1){b--;chmax(res,eval(b));}
}
return res;
}
void upd(ll i,ll x){
ll cur=qry(i,i);
add(i,i,-cur+x);
}
};RAQRMQ seg[110];
class RSQ{
public:
ll dat[2*N];
void init(){
rep(i,2*N)dat[i]=0;
}
void upd(ll i,ll x){
i+=N;
dat[i]=x;
for(;i;i>>=1)dat[i/2]=dat[i]+dat[i^1];
}
ll qry(ll l,ll r){
l+=N,r+=N+1;
ll res=0;
for(ll a=l,b=r;a<b;a>>=1,b>>=1){
if(a&1)res+=dat[a++];
if(b&1)res+=dat[--b];
}
return res;
}
};RSQ sub[110];
vll countScans(vll a,vll x,vll v){
ll n=a.size(),q=x.size();
//if(n>8000)return a;
/*vll zs;
for(auto t:a)zs.push_back(t);
for(auto t:v)zs.push_back(t);
sort(all(zs));
zs.erase(unique(all(zs)),zs.end());
for(int i=0;i<a.size();i++)a[i]=lower_bound(all(zs),a[i])-zs.begin();
for(int i=0;i<v.size();i++)v[i]=lower_bound(all(zs),v[i])-zs.begin();*/
rep(i,110){
sub[i].init();
seg[i].init();
}
rep(i,n)sub[a[i]].upd(i,1);
rep(i,n){
ll sum=0;
for(int j=a[i]+1;j<110;j++)sum+=sub[j].qry(0,i-1);
seg[a[i]].upd(i,sum);
}
vll fans;
rep(k,q){
ll id=x[k];
ll befval=a[id];
ll newval=v[k];
a[id]=newval;
for(int i=0;i<befval;i++)seg[i].add(id+1,n-1,-1);
for(int i=0;i<newval;i++)seg[i].add(id+1,n-1,+1);
//cout<<"neeee"<<seg[1].qry(0,n-1)<<endl;
seg[befval].upd(id,-1e17);
ll sum=0;
for(int i=newval+1;i<110;i++)sum+=sub[i].qry(0,id-1);
seg[newval].upd(id,sum);
//cout<<"upp"<<newval<<" "<<id<<" "<<sum<<endl;
ll ans=-1e17;
for(int i=0;i<110;i++)chmax(ans,seg[i].qry(0,n-1));
fans.push_back(ans);
sub[befval].upd(id,0);
sub[newval].upd(id,1);
}
return fans;
}
/*int main(){
ll n,q;
cin>>n>>q;
vll a(n),x(q),v(q);
rep(i,n)cin>>a[i];
rep(i,q)cin>>x[i]>>v[i];
vll res=countScans(a,x,v);
for(auto t:res)cout<<t<<endl;
}*/
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1022 ms |
524288 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1022 ms |
524288 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
789 ms |
517472 KB |
Output is correct |
2 |
Correct |
5238 ms |
518596 KB |
Output is correct |
3 |
Execution timed out |
9044 ms |
519456 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1022 ms |
524288 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |