QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#421179#7872. 崩坏天际线kkkgjyismine4Compile Error//C++145.2kb2024-05-25 14:53:282024-05-25 14:53:28

Judging History

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

  • [2024-05-25 14:53:28]
  • 评测
  • [2024-05-25 14:53:28]
  • 提交

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[ct[v]]);
		    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;
}

Details

answer.code: In function ‘int calc(int, int)’:
answer.code:114:90: error: ‘v’ was not declared in this scope
  114 |                         ++Q,Opt[Q]=1,Tl[Q]=lst,Tr[Q]=tr[i],Val[Q]=ipw[ct1],add(pq,ipw[ct[v]]);
      |                                                                                          ^
answer.code: In function ‘int main()’:
answer.code:169:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
  169 |         scanf("%d%d",&n,&q);ipw[0]=1;
      |         ~~~~~^~~~~~~~~~~~~~
answer.code:172:33: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
  172 |                 int op,l,r;scanf("%d",&op),opt[i]=op;
      |                            ~~~~~^~~~~~~~~~
answer.code:173:30: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
  173 |                 if(op&1)scanf("%d%d",&l,&r);
      |                         ~~~~~^~~~~~~~~~~~~~
answer.code:174:27: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
  174 |                 else scanf("%d",&l);
      |                      ~~~~~^~~~~~~~~