QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#303565#7899. Say Hello to the Futureship2077WA 196ms16128kbC++142.6kb2024-01-12 18:48:222024-01-12 18:48:22

Judging History

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

  • [2024-01-24 22:42:06]
  • hack成功,自动添加数据
  • (/hack/523)
  • [2024-01-12 18:48:22]
  • 评测
  • 测评结果:WA
  • 用时:196ms
  • 内存:16128kb
  • [2024-01-12 18:48:22]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
constexpr int M=2e5+5,mod=998244353;
vector<array<int,3>>qry[M];
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=rdc(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);
}
void getans(int l,int r){
	if (l==r) return ans[l]+=a[l]>1?f[l-1]*g[r+1]:0,void();
	int mid=l+r>>1;getans(l,mid);getans(mid+1,r);
	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;
	for (int i=l;i<=r;i++) vector<array<int,3>>().swap(qry[i]);
	init(mid-l+1);
	for (int i=mid,mx1=0,mx2=0,pos;i>=l;i--){
		if (a[i]>mx1) mx2=mx1,mx1=a[i],pos=i;
		else if (a[i]>mx2) mx2=a[i];
		if (max(mid+1,mx1+i-1)==max(mid+1,mx2+i-1)||!f[i-1]) continue;
		if (mx1+i-1<=r) qry[max(mid+1,mx1+i-1)].push_back({i,pos,mod-f[i-1]});
		if (mx2+i-1<=r) qry[max(mid+1,mx2+i-1)].push_back({i,pos,f[i-1]});
	}
	for (int i=r,sum=0;i>mid;i--){
		if (b[i]>=l) update(min(b[i],mid)-l+1,g[i+1]),sum=rdc(sum+g[i+1]);
		for (auto [x,id,coef]:qry[i])
			ans[id]=(ans[id]+1ll*(sum+mod-query(x-l))*coef)%mod;
	}
	init(r-mid);
	for (int i=mid+1,mx1=0,mx2=0,pos;i<=r;i++){
		if (a[i]>mx1) mx2=mx1,mx1=a[i],pos=i;
		else if (a[i]>mx2) mx2=a[i];
		if (min(mid,i-mx1+1)==min(mid,i-mx2+1)||!g[i+1]) continue;
		if (i-mx1+1>=l) qry[min(mid,i-mx1+1)].push_back({i,pos,mod-g[i+1]});
		if (i-mx2+1>=l) qry[min(mid,i-mx2+1)].push_back({i,pos,g[i+1]});
	}
	for (int i=l;i<=mid;i++){
		if (b[i]<=r) update(max(b[i],mid+1)-mid,f[i-1]);
		for (auto [x,id,coef]:qry[i]) ans[id]=(ans[id]+1ll*query(x-mid)*coef)%mod;
	}
}
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]);
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 2ms
memory: 12824kb

input:

5
1 3 2 1 2

output:

3 6 3 3 6 

result:

ok 5 tokens

Test #2:

score: -100
Wrong Answer
time: 196ms
memory: 16128kb

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:

1155366835 826457499 826457499 826457499 826457499 826457499 826457499 826457499 826457499 826457499 826457499 826457499 826457499 826457499 826457499 826457499 826457499 826457499 826457499 826457499 826457499 826457499 826457499 826457499 826457499 826457499 826457499 826457499 826457499 826457499...

result:

wrong answer 1st words differ - expected: '157122482', found: '1155366835'