QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#412959#7899. Say Hello to the FutureJohnAlfnovTL 1ms11300kbC++203.9kb2024-05-16 22:29:472024-05-16 22:29:47

Judging History

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

  • [2024-05-16 22:29:47]
  • 评测
  • 测评结果:TL
  • 用时:1ms
  • 内存:11300kb
  • [2024-05-16 22:29:47]
  • 提交

answer

#include<bits/stdc++.h>
#define mod 998244353
using namespace std;
int n,a[200005];
int f1[200005],f2[200005];
struct apple{
	int x,y,z;
	apple(int x=0,int y=0,int z=0):x(x),y(y),z(z){}
	bool operator<(const apple &other)const{
		if(x==other.x)return z>other.z;
		return x<other.x;
	}
}e[200005];
int c[200005];
void add(int x,int s){
	while(x<=n){
		c[x]=(c[x]+s)%mod;
		x+=x&-x;
	}
}
int query(int x){
	int ans=0;
	while(x){
		ans=(ans+c[x])%mod;
		x-=x&-x;
	}
	return ans;
}
void solve1(int l,int r){
	if(l==r)return;
	int mid=(l+r)>>1;
	solve1(l,mid);
	int tt=0;
	int m1=0;
	for(int i=mid;i>=l;--i){
		int l1=mid-i;
		e[++tt]=apple(l1,max(m1-l1,1),i);
		m1=max(m1,a[i]);
	}
	int mm=0;
	for(int i=mid+1;i<=r;++i){
		mm=max(mm,a[i]);
		int l2=i-mid;
		e[++tt]=apple(max(mm-l2,0),l2,i);
	}
	sort(e+1,e+tt+1);
	for(int i=tt;i>=1;--i){
		if(e[i].z<=mid){
			add(e[i].y,f1[e[i].z]);
		}else{
			f1[e[i].z]=(f1[e[i].z]+query(e[i].y))%mod;
		}
	}
	for(int i=tt;i>=1;--i){
		if(e[i].z<=mid){
			add(e[i].y,mod-f1[e[i].z]);
		}
	}
	solve1(mid+1,r);
}
int ans[200005];
void ADD(int l,int r,int z){
	ans[l]=(ans[l]+z)%mod;
	ans[r+1]=(ans[r+1]+mod-z)%mod;
}
void solve2(int l,int r){
	if(l==r)return;
	int mid=(l+r)>>1;
	solve2(mid+1,r);
	int tt=0;
	int m1=0;
	for(int i=mid+1;i<=r;++i){
		int l1=i-mid-1;
		e[++tt]=apple(l1,max(m1-l1,1),-i);
		m1=max(m1,a[i]);
	}
	int mm=0;
	for(int i=mid;i>=l;--i){
		mm=max(mm,a[i]);
		int l2=mid-i+1;
		e[++tt]=apple(max(mm-l2,0),l2,-i);
	}
	sort(e+1,e+tt+1);
	for(int i=tt;i>=1;--i){
		if(-e[i].z>mid){
			add(e[i].y,f2[-e[i].z]);
		}else{
			f2[-e[i].z]=(f2[-e[i].z]+query(e[i].y))%mod;
		}
	}
	for(int i=tt;i>=1;--i){
		if(-e[i].z>mid){
			add(e[i].y,mod-f2[-e[i].z]);
		}
	}
	solve2(l,mid);
}
apple ee[200005];
void solve(int l,int r){
	if(l==r)return;
	int mid=(l+r)>>1;
	solve(l,mid);solve(mid+1,r);
	int tt=0;
	int m1=0;
	int t1=0,t2=0;
	for(int i=mid;i>=l;--i){
		int l1=mid-i;
		e[++tt]=ee[++t1]=apple(l1,max(m1-l1,1),i);
		m1=max(m1,a[i]);
	}
	sort(ee+1,ee+t1+1);
	int mm=0;
	int zd=1,cd=1,wz=mid+1;
	for(int i=mid+1;i<=r;++i){
		if(zd<a[i])cd=zd,zd=a[i],wz=i;
		else if(cd<a[i])cd=a[i];
		int l2=i-mid;
		int he=0;
		apple a1(zd-l2,l2,i),a2(cd-l2,l2,i);
		for(int j=1;j<=t1;++j){
			if(a1<ee[j])he=(he-f1[ee[j].z]+mod)%mod;
			if(a2<ee[j])he=(he+f1[ee[j].z])%mod;
		}
		ADD(wz,wz,1ll*he*f2[i+1]%mod);
	}
	for(int i=mid+1;i<=r;++i){
		mm=max(mm,a[i]);
		int l2=i-mid;
		e[++tt]=apple(max(mm-l2,0),l2,i);
	}
	sort(e+1,e+tt+1);
	for(int i=tt;i>=1;--i){
		if(e[i].z<=mid){
			add(e[i].y,f1[e[i].z]);
		}else{
			ADD(mid+1,e[i].z,1ll*query(e[i].y)*f2[e[i].z+1]%mod);
		}
	}
	for(int i=tt;i>=1;--i){
		if(e[i].z<=mid){
			add(e[i].y,mod-f1[e[i].z]);
		}
	}
	tt=0;m1=0;mm=0;
	for(int i=mid+1;i<=r;++i){
		mm=max(mm,a[i]);
		int l2=i-mid;
		e[++tt]=ee[++t2]=apple(l2,max(mm-l2,0)+1,-i);
	}
	sort(ee+1,ee+t2+1);
	zd=1,cd=1,wz=mid;
	for(int i=mid;i>=l;--i){
		if(i<mid){
			int l1=mid-i;
			int he=0;
			apple a1(zd-l1,l1+1,i),a2(cd-l1,l1+1,i);
			for(int j=1;j<=t2;++j){
				if(a1<ee[j])he=(he-f2[-ee[j].z+1]+mod)%mod;
				if(a2<ee[j])he=(he+f2[-ee[j].z+1])%mod;
			}
			ADD(wz,wz,1ll*he*f1[i]%mod);
		}
		if(zd<a[i])cd=zd,zd=a[i],wz=i;
		else if(cd<a[i])cd=a[i];
	}
	for(int i=mid;i>=l;--i){
		int l1=mid-i;
		e[++tt]=apple(max(m1-l1,1),l1+1,-i);
		m1=max(m1,a[i]);
	}
	sort(e+1,e+tt+1);
	for(int i=tt;i>=1;--i){
		if(-e[i].z>mid){
			add(e[i].y,f2[-e[i].z+1]);
		}else{
			ADD(-e[i].z+1,mid,1ll*query(e[i].y)*f1[-e[i].z]%mod);
		}
	}
	for(int i=tt;i>=1;--i){
		if(-e[i].z>mid){
			add(e[i].y,mod-f2[-e[i].z+1]);
		}
	}
}
int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;++i)scanf("%d",&a[i]);
	f1[0]=1;solve1(0,n);
	f2[n+1]=1;solve2(1,n+1);
	solve(0,n);
	for(int i=1;i<=n;++i)ans[i]=(ans[i]+ans[i-1])%mod;
	for(int i=1;i<=n;++i)printf("%d ",ans[i]);
	return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 1ms
memory: 11300kb

input:

5
1 3 2 1 2

output:

3 6 3 3 6 

result:

ok 5 tokens

Test #2:

score: -100
Time Limit Exceeded

input:

200000
15922 15391 11782 4758 1973 19909 16800 6438 3821 986 18599 2011 338 19886 12401 4169 11143 12665 3230 12565 15065 15056 5090 16908 13677 12634 11435 1425 8647 3876 10694 12256 3853 19901 5723 11065 6147 13613 13768 15794 14993 5819 8117 13871 14708 15099 7152 9810 14438 10557 3209 1265 13915...

output:


result: