QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#421180 | #7872. 崩坏天际线 | kkkgjyismine4 | 50 | 2794ms | 30664kb | C++14 | 5.2kb | 2024-05-25 14:53:59 | 2024-05-25 14:54:01 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
struct Node{int l,r,v,id;};
const int mod=998244353,inv2=(mod+1)/2,B=250,inf=1e9;
int son[10000005][2],fi[50050];
int sum[10000005],sum1[10000005],tt,tg[10000005];
#define ls(p) son[p][0]
#define rs(p) son[p][1]
#define mid (l+r>>1)
#define pb push_back
int mul(int a,int b){return 1ll*a*b%mod;}
void add(int &x,const int y){if((x+=y)>=mod)x-=mod;}
void sub(int &x,const int y){if((x+=(mod-y))>=mod)x-=mod;}
void init(){
for(int i=1;i<=tt;++i)ls(i)=rs(i)=sum[i]=sum1[i]=0,tg[i]=1;
tt=0;
}
void pp(int p){
sum[p]=sum1[p]=0;
if(ls(p))add(sum[p],sum[ls(p)]),add(sum1[p],sum1[ls(p)]);
if(rs(p))add(sum[p],sum[rs(p)]),add(sum1[p],sum1[rs(p)]);
}
void Mul(int p,int v){
if(!p)return;
sum[p]=mul(sum[p],v),sum1[p]=mul(sum1[p],v);
tg[p]=mul(tg[p],v);
}
void pd(int p){
if(tg[p]==1)return;
Mul(ls(p),tg[p]),Mul(rs(p),tg[p]),tg[p]=1;
}
void ins(int &p,int l,int r,int pos,int v){
if(!p)p=++tt,tg[p]=1;
if(l==r){add(sum[p],v),add(sum1[p],mul(v,l));return;}
pd(p);if(pos<=mid)ins(ls(p),l,mid,pos,v);
else ins(rs(p),mid+1,r,pos,v);pp(p);
}
void split(int p,int l,int r,int v,int &a,int &b){
if(!p){a=b=0;return;}
if(r<=v){a=p,b=0;return;}
if(v<l){a=0,b=p;return;}
pd(p);
if(v<=mid){
b=p,a=++tt,tg[a]=1;
split(ls(p),l,mid,v,ls(a),ls(b));
}else{
b=++tt,a=p,tg[b]=1;
split(rs(p),mid+1,r,v,rs(a),rs(b));
}pp(a),pp(b);
}
int merge(int u,int v,int l,int r){
if(!u||!v)return (u|v);
pd(u),pd(v);
add(sum[u],sum[v]),add(sum1[u],sum1[v]);
if(l==r)return u;
ls(u)=merge(ls(u),ls(v),l,mid),rs(u)=merge(rs(u),rs(v),mid+1,r);
return u;
}
set<int>pos;
int f[50050],n,q;
struct SGT{
int mn[200050];
void bd(int p,int l,int r){
mn[p]=inf;if(l==r)return;
bd(p<<1,l,mid),bd(p<<1|1,mid+1,r);
}
void cg(int p,int l,int r,int pos,int v){
mn[p]=min(mn[p],v);if(l==r)return;
if(pos<=mid)cg(p<<1,l,mid,pos,v);
else cg(p<<1|1,mid+1,r,pos,v);
}
int qry(int p,int l,int r,int a,int b){
if(a>b)return inf;
if(a<=l&&r<=b)return mn[p];
int ans=inf;if(a<=mid)ans=min(ans,qry(p<<1,l,mid,a,b));
if(b>mid)ans=min(ans,qry(p<<1|1,mid+1,r,a,b));
return ans;
}
}t;
int opt[50050],tl[50050],tr[50050],tot,Ans,rt[50050],rt1[50050];
vector<int>vec[50050];
int Opt[500500],Tl[500500],Tr[500500],Val[500500],Q,ans,vis[50050],ipw[100050];
set<int>Pos;
int lf[50050],rg[50050],ct[50050],Time[50050],que[50050],tail;
int calc(int l,int r){
memset(lf,0,sizeof(lf));
memset(rg,0,sizeof(rg));
ans=Q=0,Pos.clear(),Pos.insert(0),Pos.insert(n),lf[n]=0,rg[0]=n;
for(int i=r;i>=l;--i){
if(opt[i]&1){
set<int>::iterator it=Pos.lower_bound(tl[i]+1);
if((*it)>=tr[i]){++Q;Opt[Q]=1,Tl[Q]=tl[i],Tr[Q]=tr[i],Val[Q]=1;continue;}
vector<int>vec;for(int j=(*it);j&&j<tr[i];j=rg[j])vec.pb(j);
tail=0;
for(auto v:vec){
ct[v]=tail;
while(tail&&Time[que[tail]]>Time[v])--tail;
que[++tail]=v;
}
int ct1=tail,lst=tl[i];tail=0;
reverse(vec.begin(),vec.end());
for(auto v:vec){
while(tail&&Time[que[tail]]>Time[v])--tail;
que[++tail]=v;
ct[v]+=tail;
}
reverse(vec.begin(),vec.end());
int pq=0;
for(auto v:vec){
++Q;Opt[Q]=1;
Tl[Q]=lst,Tr[Q]=v,Val[Q]=ipw[ct[v]],lst=v;
add(pq,ipw[ct[v]]);
}
++Q,Opt[Q]=1,Tl[Q]=lst,Tr[Q]=tr[i],Val[Q]=ipw[ct1],add(pq,ipw[ct1]);
assert(pq==1);
}else{
Time[tl[i]]=i;
if(Pos.count(tl[i]))continue;
set<int>::iterator it=Pos.lower_bound(tl[i]);
int nxt=(*it),lst=(*(--it));
rg[lst]=tl[i],rg[tl[i]]=nxt;
lf[nxt]=tl[i],lf[tl[i]]=lst;
Pos.insert(tl[i]);
}
}
for(int i=r+1;i<=q;++i)if(opt[i]==2)++Q,Opt[Q]=2,Tl[Q]=tl[i];
init();
for(int i=1;i<=n;++i)vec[i].clear();
pos.clear();
memset(rt,0,sizeof(rt));
memset(rt1,0,sizeof(rt1));
memset(f,0,sizeof(f));
t.bd(1,1,n);
for(int i=Q;i>=1;--i){
if(Opt[i]==2)t.cg(1,1,n,Tl[i],i);
else{
int mn=t.qry(1,1,n,Tl[i]+1,Tr[i]-1);
if(mn==inf)add(ans,mul(Tr[i]-Tl[i],Val[i]));
else vec[mn].pb(i);
}
}
pos.insert(0),pos.insert(n);
for(int i=1;i<=Q;++i){
if(Opt[i]&1||pos.count(Tl[i]))continue;
set<int>::iterator it=pos.lower_bound(Tl[i]);
int nxt=(*it),lst=(*(--it));
f[nxt]=mul(f[nxt],inv2),f[Tl[i]]=f[nxt];
split(rt[nxt],1,n,Tl[i]-1,rt[Tl[i]],rt[nxt]);
add(f[nxt],mul(sum[rt[Tl[i]]],inv2)),Mul(rt[Tl[i]],inv2);
split(rt1[lst],1,n,Tl[i],rt1[lst],rt1[Tl[i]]);
add(f[Tl[i]],mul(sum[rt1[Tl[i]]],inv2)),Mul(rt1[Tl[i]],inv2);
pos.insert(Tl[i]);
for(auto v:vec[i])ins(rt[Tl[i]],1,n,Tl[v],mul(inv2,Val[v])),ins(rt1[Tl[i]],1,n,Tr[v],mul(inv2,Val[v]));
}
for(int i=1;i<=n;++i){
if(!pos.count(i))continue;
int x=(*(--pos.lower_bound(i)));
add(ans,mul(i-x,f[i]));
}
for(auto v:pos){
add(ans,mul(v,sum[rt[v]]));
sub(ans,sum1[rt[v]]);
add(ans,sum1[rt1[v]]);
sub(ans,mul(v,sum[rt1[v]]));
}
return ans;
}
int main(){
scanf("%d%d",&n,&q);ipw[0]=1;
for(int i=1;i<=n+q;++i)ipw[i]=mul(ipw[i-1],inv2);
for(int i=1;i<=q;++i){
int op,l,r;scanf("%d",&op),opt[i]=op;
if(op&1)scanf("%d%d",&l,&r);
else scanf("%d",&l);
tl[i]=l,tr[i]=r;
}
for(int i=1;i<=q;i+=B)add(Ans,calc(i,min(i+B-1,q)));
cout<<Ans;
return 0;
}
詳細信息
Subtask #1:
score: 10
Accepted
Test #1:
score: 10
Accepted
time: 0ms
memory: 18352kb
input:
500 500 1 119 258 2 134 2 417 2 176 2 61 2 60 2 110 1 335 336 1 96 111 2 202 1 138 344 2 358 2 134 1 29 54 1 73 381 1 179 495 2 490 2 418 2 186 2 183 1 168 340 2 78 1 15 27 2 373 1 245 498 1 372 495 2 244 2 63 1 174 490 2 282 2 417 1 272 408 1 109 134 2 303 2 345 1 238 401 1 36 480 1 21 483 2 10 1 3...
output:
855279801
result:
ok single line: '855279801'
Test #2:
score: 0
Accepted
time: 0ms
memory: 16040kb
input:
495 466 1 35 393 2 236 1 4 335 2 455 1 36 470 1 23 61 2 195 2 109 2 451 1 282 491 2 238 2 117 2 468 1 2 60 1 439 487 2 238 1 209 294 2 321 2 309 1 113 183 2 409 2 87 2 130 2 124 2 176 2 448 2 379 1 181 446 2 146 2 450 1 171 423 2 355 2 332 1 123 387 1 151 269 1 17 417 2 122 1 324 494 1 265 439 2 225...
output:
294468977
result:
ok single line: '294468977'
Test #3:
score: 0
Accepted
time: 0ms
memory: 16300kb
input:
441 467 2 180 1 51 344 2 180 1 16 345 1 39 419 1 64 432 2 176 1 35 372 2 426 1 8 415 1 1 439 1 17 430 2 433 1 89 369 1 83 353 2 292 1 1 421 1 63 430 1 33 345 1 69 421 1 49 373 1 77 343 1 24 393 1 90 375 1 8 425 2 322 2 61 2 112 2 209 1 39 406 1 12 426 1 29 430 1 50 374 1 47 394 1 9 387 2 234 1 19 35...
output:
526117259
result:
ok single line: '526117259'
Test #4:
score: 0
Accepted
time: 0ms
memory: 16436kb
input:
500 500 2 442 1 12 414 1 40 435 2 138 1 79 448 1 16 464 2 163 1 94 492 2 97 2 335 1 7 452 1 25 474 1 78 442 2 286 1 93 430 1 78 438 2 469 2 354 2 270 2 292 2 108 2 301 1 100 480 2 258 1 17 487 2 2 2 409 2 385 2 338 1 83 454 1 41 490 1 95 475 1 43 442 1 66 445 2 406 2 168 1 10 406 2 330 2 20 1 90 491...
output:
810270061
result:
ok single line: '810270061'
Test #5:
score: 0
Accepted
time: 2ms
memory: 16376kb
input:
500 500 1 29 407 1 89 480 1 31 497 1 28 494 1 21 492 1 91 465 1 13 467 1 89 425 1 22 444 1 20 430 1 48 445 1 33 441 1 61 435 1 69 427 1 89 485 1 90 446 1 23 488 1 6 424 1 76 425 1 36 460 1 16 421 1 20 500 1 3 487 1 99 481 1 53 412 1 96 456 1 39 436 1 28 436 1 4 409 1 9 486 1 22 484 1 88 413 1 26 467...
output:
419428992
result:
ok single line: '419428992'
Test #6:
score: 0
Accepted
time: 3ms
memory: 16056kb
input:
500 500 1 85 442 1 20 473 1 10 441 1 31 426 1 95 478 1 60 454 1 54 491 1 97 464 1 14 443 1 88 474 1 28 462 1 97 410 1 99 496 1 96 493 1 62 479 1 12 466 1 64 471 1 43 490 1 50 411 1 85 448 1 48 433 1 30 456 1 39 462 1 46 409 1 63 494 1 39 409 1 36 436 1 27 463 1 37 498 1 69 464 1 8 441 1 99 436 1 84 ...
output:
519347055
result:
ok single line: '519347055'
Subtask #2:
score: 0
Wrong Answer
Dependency #1:
100%
Accepted
Test #7:
score: 20
Accepted
time: 30ms
memory: 17516kb
input:
5000 5000 2 2254 2 4832 2 208 1 335 3080 2 481 1 527 3659 1 2645 3803 1 855 3544 2 3824 2 347 1 1567 4426 1 2184 4493 2 142 2 2451 1 995 4170 2 576 2 999 2 2726 1 278 3540 2 3218 1 922 3302 2 3253 2 4161 2 4505 1 4201 4534 1 1827 3540 2 3241 2 1909 2 2667 1 723 2453 2 3123 1 1017 4791 1 2953 3384 1 ...
output:
275175220
result:
ok single line: '275175220'
Test #8:
score: 0
Accepted
time: 29ms
memory: 18664kb
input:
4753 4704 1 589 2183 1 922 2210 2 2885 2 171 2 1597 2 3601 1 1906 4730 1 411 3615 2 1665 1 87 801 2 3525 2 2426 2 2723 1 323 4345 2 3950 2 460 2 4165 1 1156 2642 1 1490 3965 1 329 4081 1 1206 2077 2 4216 1 996 2254 2 2219 2 1035 2 4074 2 714 1 952 2726 2 3097 2 409 1 3320 4713 2 4061 1 1765 2040 1 2...
output:
840227126
result:
ok single line: '840227126'
Test #9:
score: -20
Wrong Answer
time: 63ms
memory: 21960kb
input:
4141 4610 2 3761 2 2872 1 334 3247 1 273 3914 1 307 3651 1 607 4105 1 458 3269 1 270 3782 2 311 1 533 3332 2 2495 1 991 3573 1 376 3593 1 239 3682 1 259 3350 1 213 3380 2 1904 1 591 3512 1 845 3785 1 189 3335 1 817 3362 1 335 3288 2 3633 1 747 3586 2 4062 2 3812 1 487 3333 1 740 4002 1 847 3937 1 53...
output:
983388536
result:
wrong answer 1st lines differ - expected: '597472157', found: '983388536'
Subtask #3:
score: 40
Accepted
Test #13:
score: 40
Accepted
time: 2660ms
memory: 25968kb
input:
50000 50000 1 24367 33007 1 14396 42256 1 6375 22327 1 7892 42501 1 10100 37998 1 6284 48524 1 7357 18164 1 16200 46424 1 18972 34131 1 16849 32591 1 1917 3018 1 19897 30272 1 45044 45753 1 18999 25448 1 5167 31033 1 6182 35335 1 7270 37270 1 12651 39965 1 28896 38022 1 13853 35426 1 35516 48244 1 1...
output:
733099543
result:
ok single line: '733099543'
Test #14:
score: 0
Accepted
time: 2037ms
memory: 24868kb
input:
49951 43686 1 21796 23464 1 29304 46959 1 5034 41719 1 7779 35334 1 27566 36486 1 20347 26165 1 12508 30387 1 18363 20335 1 8540 21417 1 5728 49086 1 46038 47603 1 10371 15910 1 27293 43572 1 18915 45279 1 7388 48342 1 6802 43746 1 4361 40049 1 41177 43375 1 23287 48354 1 37097 41733 1 2406 11638 1 ...
output:
792296531
result:
ok single line: '792296531'
Test #15:
score: 0
Accepted
time: 1109ms
memory: 21684kb
input:
49914 43874 1 8935 40963 1 4425 44317 1 1769 45855 1 2436 40257 1 1778 47216 1 383 42149 1 5398 40732 1 1079 43346 1 6578 41660 1 9689 45985 1 6131 42681 1 8862 47431 1 3979 46189 1 6456 43485 1 2028 46574 1 3802 47787 1 6990 41659 1 9221 41204 1 2271 43554 1 8018 45280 1 9344 43917 1 6623 41152 1 7...
output:
831211412
result:
ok single line: '831211412'
Test #16:
score: 0
Accepted
time: 2208ms
memory: 22240kb
input:
50000 50000 1 1310 49344 1 5755 44255 1 3582 41465 1 6800 42160 1 1651 44584 1 7967 44410 1 3116 48795 1 1855 41120 1 27 42294 1 2455 49629 1 4196 42487 1 7070 44542 1 136 42053 1 5715 44222 1 8794 43115 1 4048 45579 1 635 46703 1 9246 41055 1 3678 41276 1 4871 41715 1 1659 44679 1 1639 46392 1 2479...
output:
316801136
result:
ok single line: '316801136'
Test #17:
score: 0
Accepted
time: 2467ms
memory: 22284kb
input:
50000 50000 1 8731 40028 1 6575 43815 1 9558 42476 1 7269 47567 1 6597 45567 1 7753 49129 1 9892 47319 1 9438 45710 1 8688 46209 1 75 43653 1 8918 44467 1 2751 43343 1 4433 45172 1 8062 40732 1 3342 41158 1 615 45475 1 7497 44843 1 9201 48262 1 3063 44796 1 9294 48709 1 382 46129 1 5935 48889 1 1195...
output:
680677335
result:
ok single line: '680677335'
Test #18:
score: 0
Accepted
time: 2794ms
memory: 30664kb
input:
50000 50000 1 5934 20406 1 21982 32375 1 7064 32616 1 28419 47337 1 28379 31201 1 40915 47773 1 14903 35558 1 2825 43481 1 28451 29178 1 4872 24238 1 5487 6527 1 33950 35231 1 6301 27246 1 3825 16238 1 3823 46254 1 10988 36002 1 6447 8234 1 4758 20500 1 4816 33750 1 3332 3743 1 723 25813 1 6797 4955...
output:
211908161
result:
ok single line: '211908161'
Subtask #4:
score: 0
Skipped
Dependency #1:
100%
Accepted
Dependency #2:
0%