QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#296269 | #4918. 染色 | Graygoo | 0 | 1364ms | 198476kb | C++14 | 3.8kb | 2024-01-02 17:23:10 | 2024-01-02 17:23:10 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define pii pair<int,int>
#define ull unsigned long long
struct heap{
priority_queue<int,vector<int>,greater<int> > a,b;
void ins(int x){a.push(x);}
void del(int x){b.push(x);}
int top(){
while(!a.empty() and !b.empty() and a.top()==b.top())a.pop(),b.pop();
return a.top();
}
bool empty(){return a.size()==b.size();}
};
set<pii> e[300005];
heap w[1500005];
ull tag1[1500005];
ull tag2[1500005];
ull sm[1500005];
int mn[1500005];
int num[1500005];
void tg1(int l,int r,int x,ull v){
tag1[x]+=v;
sm[x]+=num[x]*v;
return ;
}
void tg2(int l,int r,int x,ull v){
tag2[x]+=v;
sm[x]+=(r-l+1)*v;
return ;
}
void down(int l,int r,int x){
if(l==r)return ;
int mid=(l+r)>>1;
if(tag1[x]){
int z=w[x].empty()?INT_MAX:w[x].top();
if(z==mn[x]){
tag2[x]+=tag1[x];tag1[x]=0;
}else{
if(mn[x*2]==mn[x])tg1(l,mid,x*2,tag1[x]);
if(mn[x*2+1]==mn[x])tg1(mid+1,r,x*2+1,tag1[x]);
tag1[x]=0;
}
}
if(tag2[x]){
tg2(l,mid,x*2,tag2[x]);
tg2(mid+1,r,x*2+1,tag2[x]);
tag2[x]=0;
}
return ;
}
void up(int l,int r,int x){
if(l==r){
mn[x]=w[x].empty()?INT_MAX:w[x].top();
num[x]=1;return ;
}
int mn1=mn[x*2];
int mn2=mn[x*2+1];
int o=w[x].empty()?INT_MAX:w[x].top();
if(o<=mn1 and o<=mn2){
mn[x]=o;num[x]=r-l+1;
}else{
mn[x]=min(mn1,mn2);num[x]=0;
if(mn1==mn[x])num[x]+=num[x*2];
if(mn2==mn[x])num[x]+=num[x*2+1];
}
sm[x]=sm[x*2]+sm[x*2+1];
return ;
}
void M1(int l,int r,int L,int R,int x,int v,int tp){
if(L>r or R<l)return ;
down(l,r,x);
if(L<=l and R>=r){
if(tp==1)w[x].ins(v);
else w[x].del(v);
up(l,r,x);
return ;
}
int mid=(l+r)>>1;
M1(l,mid,L,R,x*2,v,tp);M1(mid+1,r,L,R,x*2+1,v,tp);
up(l,r,x);
return ;
}
int Qmn(int l,int r,int L,int R,int x){
if(L>r or R<l)return INT_MAX;
if(L<=l and R>=r)return mn[x];
down(l,r,x);
int mid=(l+r)>>1;
return min({Qmn(l,mid,L,R,x*2),Qmn(mid+1,r,L,R,x*2+1),w[x].empty()?INT_MAX:w[x].top()});
}
void M2(int l,int r,int L,int R,int x,ull v,int anc,int tar){
if(L>r or R<l)return ;
down(l,r,x);
if(L<=l and R>=r){
if(min(mn[x],anc)!=tar)return ;
if(mn[x]<anc){
tg1(l,r,x,v);
}else {tg2(l,r,x,v);}
return ;
}
int mid=(l+r)>>1;anc=min(anc,w[x].empty()?INT_MAX:w[x].top());
M2(l,mid,L,R,x*2,v,anc,tar);
M2(mid+1,r,L,R,x*2+1,v,anc,tar);
up(l,r,x);
return ;
}
ull Q(int l,int r,int L,int R,int x){
if(L>r or R<l)return 0;
if(L<=l and R>=r)return sm[x];
down(l,r,x);
int mid=(l+r)>>1;
return Q(l,mid,L,R,x*2)+Q(mid+1,r,L,R,x*2+1);
}
int n,q;
void dl(int l,int r,int x){
vector<pii> y;
auto it=e[x].lower_bound({l,-1});
it--;
if(it->second<l)it++;
while(1){
y.push_back(*it);it++;
if(it->first>r)break;
}
for(auto v:y){
e[x].erase(e[x].find(v));
M1(1,n,v.first,v.second,1,x,-1);
if(v.first<l){
M1(1,n,v.first,l-1,1,x,1);
e[x].insert({v.first,l-1});
}
if(v.second>r){
M1(1,n,r+1,v.second,1,x,1);
e[x].insert({r+1,v.second});
}
}
return ;
}
void ad(int l,int r,int x){
dl(l,r,x);e[x].insert({l,r});M1(1,n,l,r,1,x,1);
return ;
}
void build(int l,int r,int x){
mn[x]=x==1?1:INT_MAX;num[x]=r-l+1;
if(l==r)return ;
int mid=(l+r)>>1;
build(l,mid,x*2);build(mid+1,r,x*2+1);
return ;
}
signed main(){
cin>>n>>q;build(1,n,1);
for(int i=1;i<=150002;i++){
e[i].insert({0,0});e[i].insert({1,n});e[i].insert({n+1,n+1});
M1(1,n,1,n,1,i,1);
}
while(q--){
int tp;cin>>tp;
if(tp==1){
int l,r,x;cin>>l>>r>>x;
dl(l,r,x);
}else if(tp==2){
int l,r,x;cin>>l>>r>>x;
ad(l,r,x);
}else if(tp==3){
int l,r;ull x;cin>>l>>r>>x;
int v=Qmn(1,n,l,r,1);
M2(1,n,l,r,1,x,INT_MAX,v);
}else if(tp==4){
int l,r;cin>>l>>r;
cout<<Q(1,n,l,r,1)<<endl;
}
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 0
Runtime Error
Test #1:
score: 10
Accepted
time: 27ms
memory: 135356kb
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:
15128467772367689008 17361914246216994339 5483226026482017320 3033562207293358603 2081407883485577238 7431958406282818646 4664359672511637691 8517692808398202534 17884251128335023776 3389445997760709607 15161173652136060523 17246899135664170339 16659472119973467421 5618344994614112283 92650283427734...
result:
ok 288 tokens
Test #2:
score: -10
Runtime Error
input:
1000 1000 1 538 681 44 2 112 540 10 1 160 191 28 1 276 867 1 4 118 419 4 62 209 1 575 884 37 1 783 895 45 4 342 410 2 545 870 16 1 273 501 11 3 258 352 13270291835335737625 3 490 514 5208698592597571883 2 629 865 43 3 966 981 14431353048791951405 1 290 809 16 4 468 843 1 607 875 26 2 177 521 6 4 176...
output:
0 0 0 1090256298972435763 147836376791542005 2987455658418197192 17393388322162025577 0 15463425577465259729 5603739312727078592 9162759280430770517 5734982725161877299 17209386033616770563 4838930779004365643 849737692109005723 6426101344117061130 5419322161439603233 5062725202245147693 71096115354...
result:
Subtask #2:
score: 0
Wrong Answer
Test #11:
score: 0
Wrong Answer
time: 1259ms
memory: 198476kb
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:
0 0 0 0 0 0 12272376591028786218 0 0 0 0 0 0 0 0 0 0 0 0 0 0 954290611784159519 11933011047389299715 3778617232493240005 16090278095350766495 8442380184747267006 16938285947326957203 0 0 14783754218831034862 7601682967357904165 0 9546408837911439772 1922461247513984739 14899789459322003663 0 1431961...
result:
wrong answer 23rd words differ - expected: '0', found: '11933011047389299715'
Subtask #3:
score: 0
Skipped
Dependency #2:
0%
Subtask #4:
score: 0
Wrong Answer
Test #31:
score: 0
Wrong Answer
time: 1364ms
memory: 192572kb
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:
0 0 11483072678206810052 13734482383102048304 15330757429201569746 0 25006388255838242 11346236204034351609 0 14064895545243707271 4267825007721372713 0 0 10270101177550224023 11917196698575719908 1013984310976878254 16360293865242066748 0 0 0 2155420403674811693 6359253237460991224 3571104661499166...
result:
wrong answer 3rd words differ - expected: '16968625150574630951', found: '11483072678206810052'
Subtask #5:
score: 0
Skipped
Dependency #1:
0%
Subtask #6:
score: 0
Skipped
Dependency #1:
0%