QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#421086#7872. 崩坏天际线kkkgjyismine440 49ms27520kbC++143.6kb2024-05-25 11:59:402024-05-25 11:59:40

Judging History

你现在查看的是最新测评结果

  • [2024-05-25 11:59:40]
  • 评测
  • 测评结果:40
  • 用时:49ms
  • 内存:27520kb
  • [2024-05-25 11:59:40]
  • 提交

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;
	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;
vector<Node>va;
vector<int>vb;
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 main(){
	scanf("%d%d",&n,&q);
	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),va.pb(Node{l,r,1,i});
		else scanf("%d",&l),vb.pb(l);tl[i]=l,tr[i]=r;
	}
	t.bd(1,1,n);pos.insert(0),pos.insert(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,tr[i]-tl[i]);else vec[mn].pb(i);
		}
	}
	memset(rt,0,sizeof(rt)),memset(rt1,0,sizeof(rt1));
	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],inv2),ins(rt1[tl[i]],1,n,tr[v],inv2);
	}
    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]]));
	}cout<<Ans;
	return 0;
}

详细

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 0
Wrong Answer
time: 2ms
memory: 7324kb

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:

465867630

result:

wrong answer 1st lines differ - expected: '855279801', found: '465867630'

Subtask #2:

score: 0
Skipped

Dependency #1:

0%

Subtask #3:

score: 40
Accepted

Test #13:

score: 40
Accepted
time: 44ms
memory: 25360kb

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: 47ms
memory: 24924kb

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: 30ms
memory: 11056kb

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: 38ms
memory: 17312kb

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: 40ms
memory: 15340kb

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: 49ms
memory: 27520kb

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:

0%