QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#302427#7899. Say Hello to the Futureship2077TL 1ms7924kbC++142.9kb2024-01-10 21:04:462024-01-10 21:04:48

Judging History

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

  • [2024-01-24 22:42:06]
  • hack成功,自动添加数据
  • (/hack/523)
  • [2024-01-10 21:04:48]
  • 评测
  • 测评结果:TL
  • 用时:1ms
  • 内存:7924kb
  • [2024-01-10 21:04:46]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
constexpr int M=2e5+5,mod=998244353;
int n,N,a[M],b[M],f[M],g[M],tr[M],pos[M],ans[M];
int read(){
	int x=0;char ch=getchar();
	while (!isdigit(ch)) ch=getchar();
	while (isdigit(ch)) x=x*10+ch-48,ch=getchar();
	return x;
}
int rdc(int x){return x>=mod?x-mod:x;}
void init(int n){N=n;for (int i=1;i<=N;i++) tr[i]=0;}
void update(int x,int v){while (x<=N) tr[x]=rdc(tr[x]+v),x+=x&-x;}
int query(int x){int ans=0;while (x) ans+=tr[x],x-=x&-x;return ans;}
bool cmp(int x,int y){return b[x]<b[y];}
void cdq(int *dp,int l,int r){
	if (l==r) return dp[l]=a[l]==1?rdc(dp[l]+dp[l-1]):dp[l],void();
	int mid=l+r>>1;cdq(dp,l,mid);
	for (int i=mid,mx=0;i>=l;i--) mx=max(mx,a[i]),b[i]=mx+i-1;
	for (int i=mid+1,mx=0;i<=r;i++) mx=max(mx,a[i]),b[i]=i-mx+1;
	init(r-mid);iota(pos+mid+1,pos+r+1,mid+1);
	sort(pos+mid+1,pos+r+1,cmp);
	for (int k=mid+1,i=l;k<=r;k++){ int j=pos[k];
		while (i<=mid&&i<=b[j]) update(max(1,b[i]-mid),dp[i-1]),i++;
		dp[j]=rdc(dp[j]+query(j-mid));
	}
	cdq(dp,mid+1,r);
}
struct node{ int x,pos;
	bool operator <(const node &a) const
		{return x<a.x;}
}c1[M],c2[M];
void modify(node &tmp1,node &tmp2,int x,int pos){
	if (tmp1.x<x) tmp2=tmp1,tmp1={x,pos};
	else if (tmp2.x<x) tmp2={x,pos};
	c1[pos]=tmp1;c2[pos]=tmp2;
}
void getans(int l,int r){
	if (l==r) return ;
	int mid=l+r>>1;getans(l,mid);getans(mid+1,r);
	node tmp1={0,mid+1},tmp2={0,mid+1};
	for (int i=mid,mx=0;i>=l;i--) mx=max(mx,a[i]),modify(tmp1,tmp2,a[i]/*mx+i-1*/,i);
	for (int i=l;i<=mid;i++) c1[i].x+=i-1,c2[i].x+=i-1; tmp1=tmp2={0,mid};
	for (int i=mid+1,mx=0;i<=r;i++) mx=max(mx,a[i]),modify(tmp1,tmp2,a[i] /*i-mx+1 */,i);
	for (int i=mid+1;i<=r;i++) c1[i].x=i+1-c1[i].x,c2[i].x=i+1-c2[i].x;
//	init(l-mid);
	for (int i=l;i<=mid;i++)
		if (c1[i].x!=c2[i].x)
			for (int j=mid+1;j<=r;j++){
				if (i<=c1[j].x&&j>=c1[i].x) ans[c1[i].pos]-=f[i-1]*g[j+1];
				if (i<=c1[j].x&&j>=c2[i].x) ans[c1[i].pos]+=f[i-1]*g[j+1];
			}
	for (int j=mid+1;j<=r;j++)
		if (c1[j].x!=c2[j].x)
			for (int i=l;i<=mid;i++){
				if (i<=c1[j].x&&j>=c1[i].x) ans[c1[j].pos]-=f[i-1]*g[j+1];
				if (i<=c2[j].x&&j>=c1[i].x) ans[c1[j].pos]+=f[i-1]*g[j+1];		
			}
}
int main(){ n=read();
	for (int i=1;i<=n;i++) a[i]=read();
	f[0]=1;cdq(f,1,n);reverse(a+1,a+n+1);
	g[0]=1;cdq(g,1,n);reverse(g,g+n+2);
	reverse(a+1,a+n+1);
//	getans(1,n);
//	for (int i=1;i<=n;i++) printf("%d ",ans[i]+f[n]);
	for (int i=1;i<=n;i++){ b[i]=0; int ans=0;
		for (int j=i-1,mx=0;j;j--) mx=max(mx,a[j]),b[j]=mx;
		for (int j=i+1,mx=0;j<=n;j++) mx=max(mx,a[j]),b[j]=mx;
		for (int j=1;j<=i;j++)
			for (int k=i;k<=n;k++)
				if (k-j+1>=b[j]&&k-j+1>=b[k])
					ans=(ans+1ll*f[j-1]*g[k+1])%mod;
		printf("%d ",ans);
	}
	return 0;
}
/*
input1
12
6 4 1 1 2 1 4 6 5 5 5 3
ouput1
10 2 2 2 2 2 2 3 2 2 2 3

input2
20
2 6 3 6 2 4 2 3 2 4 1 3 3 3 2 3 2 1 2 5
output2
90 101 55 55 55 55 64 71 59 96 55 69 59 71 68 55 55 55 55 354
*/

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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: