QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#296248 | #4918. 染色 | MEKHANE | 0 | 0ms | 0kb | C++20 | 4.0kb | 2024-01-02 16:06:53 | 2024-01-02 16:06:54 |
answer
#pragma GCC optimize(3,"inline","Ofast")
#include<bits/stdc++.h>
#define ull unsigned long long
#define ui unsigned int
#define pi pair<int,ui>
#define fi first
#define se second
#define mid (l+r)/2
#define ls k*2
#define rs k*2+1
#define rep(i,j,k) for(int i=j;i<=k;i++)
using namespace std;
const int N=3e5+5,inf=2e9;
int n,q;
struct pq{
priority_queue<int,vector<int>,greater<int>> q1,q2;
void push(int x){q1.push(x);}
void pop(int x){q2.push(x);}
bool empty(){return q1.size()==q2.size();}
int top(){while(!q2.empty()&&q2.top()==q1.top()) q2.pop(),q1.pop(); return q1.top();}
};
pi operator +(pi x,pi y){return x.fi!=y.fi?min(x,y):pi{x.fi,x.se+y.se};}
struct sgt{
pi t[4*N]; ull sum[4*N],tg1[4*N],tg2[4*N]; ui siz[4*N]; pq q[4*N];
void upd(int k){
t[k]=(t[ls]+t[rs]);
if(!q[k].empty()&&q[k].top()<=t[k].fi) t[k]={q[k].top(),siz[k]};
sum[k]=sum[ls]+sum[rs];
}
void adt1(int k,ull z){tg1[k]+=z,sum[k]+=siz[k]*z;}
void adt2(int k,ull z,int mi){
if(!q[k].empty()&&q[k].top()==mi) adt1(k,z);
else if(t[k].fi==mi) tg2[k]+=z,sum[k]+=t[k].se*z;
}
void p_d(int k){
if(tg1[k]) adt1(ls,tg1[k]),adt1(rs,tg1[k]),tg1[k]=0;
if(tg2[k]) adt2(ls,tg2[k],t[k].fi),adt2(rs,tg2[k],t[k].fi),tg2[k]=0;
}
void build(int k,int l,int r){
siz[k]=r-l+1;
if(l==r){t[k]={inf,0}; return ;}
build(ls,l,mid),build(rs,mid+1,r),upd(k);
}
void add(int k,int l,int r,int L,int R,ull z){
if(L<=l&&r<=R){adt1(k,z); return ;}
p_d(k);
if(L<=mid) add(ls,l,mid,L,R,z);
if(mid<R) add(rs,mid+1,r,L,R,z);
upd(k);
}
void gx(int k,int l,int r,int L,int R,int z,ull z1){
if(!q[k].empty()&&q[k].top()==z){add(k,l,r,L,R,z1); return ;}
if(L<=l&&r<=R){adt2(k,z1,z); return ;}
p_d(k);
if(L<=mid) gx(ls,l,mid,L,R,z,z1);
if(mid<R) gx(rs,mid+1,r,L,R,z,z1);
upd(k);
}
void ins(int k,int l,int r,int L,int R,int z,int opt){
if(L<=l&&r<=R){
if(l!=r) p_d(k);
if(opt) q[k].pop(z); else q[k].push(z);
if(l!=r) t[k]=(t[ls]+t[rs]); else t[k]={inf,0};
if(!q[k].empty()&&q[k].top()<=t[k].fi) t[k]={q[k].top(),siz[k]};
return ;
}p_d(k);
if(L<=mid) ins(ls,l,mid,L,R,z,opt);
if(mid<R) ins(rs,mid+1,r,L,R,z,opt);
upd(k);
}
int qry(int k,int l,int r,int L,int R){
if(L<=l&&r<=R) return t[k].fi;
int res=(q[k].empty()?inf:q[k].top()); p_d(k);
if(L<=mid) res=min(res,qry(ls,l,mid,L,R));
if(mid<R) res=min(res,qry(rs,mid+1,r,L,R));
return res;
}
ull qry1(int k,int l,int r,int L,int R){
if(L<=l&&r<=R) return sum[k];
ull res=0; p_d(k);
if(L<=mid) res+=qry1(ls,l,mid,L,R);
if(mid<R) res+=qry1(rs,mid+1,r,L,R);
return res;
}
}T;
struct qj{int l,r; bool friend operator <(qj x,qj y){return x.l==y.l?x.r<y.r:x.l<y.l;}};set<qj> se[N];
void add(int id,int l,int r){se[id].insert({l,r}),T.ins(1,1,n,l,r,id,0);}
void del(int id,int l,int r){se[id].erase({l,r}),T.ins(1,1,n,l,r,id,1);}
void split(int id,int x){
auto it=se[id].lower_bound({x,inf});
if(it!=se[id].begin()){
it--; qj dq=(*it);
if(dq.r>x) del(id,dq.l,dq.r),add(id,dq.l,x),add(id,x+1,dq.r);
}
}
void tp(int id,int l,int r){
split(id,l-1),split(id,r);
while(1){
auto it=se[id].lower_bound({l,0});
if(it==se[id].end()||(*it).r>r) break;
qj dq=(*it); del(id,dq.l,dq.r);
}
}
signed main(){
freopen("minmex.in","r",stdin);
freopen("minmex.out","w",stdout);
ios::sync_with_stdio(false);
cin>>n>>q,T.build(1,1,n);
rep(i,1,q+1) add(i,1,n);
while(q--){
int opt,l,r,x; cin>>opt>>l>>r;
if(opt==1) cin>>x,tp(x,l,r);
else if(opt==2) cin>>x,tp(x,l,r),add(x,l,r);
else if(opt==3){ull c; cin>>c; int dq=T.qry(1,1,n,l,r); T.gx(1,1,n,l,r,dq,c);}
else cout<<T.qry1(1,1,n,l,r)<<'\n';
}
}
详细
Subtask #1:
score: 0
Dangerous Syscalls
Test #1:
score: 0
Dangerous Syscalls
input:
1000 1000 3 722 914 2141556875752121755 3 323 347 6433743606947304931 2 142 206 439 2 117 840 195 2 127 502 56 3 168 707 15142638115094015116 4 190 257 2 88 976 475 1 319 867 351 1 682 889 409 2 406 446 196 3 28 35 4899387534800369959 2 291 546 150 1 528 617 128 1 58 122 251 2 381 400 276 4 510 958 ...
output:
result:
Subtask #2:
score: 0
Dangerous Syscalls
Test #11:
score: 0
Dangerous Syscalls
input:
300000 300000 1 237576 237663 1 3 16150 16208 9270412155482010138 2 175648 175692 1 4 190836 190849 4 199010 199097 1 73976 298801 1 3 89902 89939 6418828085116455990 3 55415 55461 12238963685511262676 3 119825 119875 8146944792877919309 3 135103 135158 218634681842812119 3 127261 127352 13291431184...
output:
result:
Subtask #3:
score: 0
Skipped
Dependency #2:
0%
Subtask #4:
score: 0
Dangerous Syscalls
Test #31:
score: 0
Dangerous Syscalls
input:
300000 300000 1 85444 86076 59 1 41150 41411 71 1 278698 279414 45 1 238445 239202 56 1 29965 29984 49 1 282953 283272 37 1 34668 35653 86 2 198587 198744 28 1 270855 271611 58 1 2130 2965 773 1 161601 162298 937 1 50299 50435 36 1 100759 101198 64 1 120208 120543 84 1 295293 295732 34 1 112185 1129...
output:
result:
Subtask #5:
score: 0
Skipped
Dependency #1:
0%
Subtask #6:
score: 0
Skipped
Dependency #1:
0%