QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#73557#4881. Hard Problemaurelion_solTL 0ms0kbC++141.7kb2023-01-25 20:35:182023-01-25 20:35:20

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-01-25 20:35:20]
  • 评测
  • 测评结果:TL
  • 用时:0ms
  • 内存:0kb
  • [2023-01-25 20:35:18]
  • 提交

answer

#include<bits/stdc++.h>
#define rp(i,a,b) for(int i=a,_=b;i<=_;++i)
#define pr(i,a,b) for(int i=a,_=b;i>=_;--i)
using namespace std;
#define T (1<<21)
#define nc() (ip==iq&&(iq=ibuf+fread(ip=ibuf,1,T,stdin),ip==iq)?-1:*ip++)
char ibuf[T],*ip=ibuf,*iq=ibuf;
int rd(){
	int x=0;char c;bool s=0;
	do c=nc();while(c!=45&&(c<48||c>57));
	if(c==45)c=nc(),s=1;
	do x=10*x+(c&15),c=nc();while(c>=48&&c<=57);
	return s?-x:x;
}
#undef T
typedef long long ll;
const int N=2e5+10,mod=1e9+7;
int T,n,m,a[N],f[N/2],fr[2][N],bk[2][N];
inline int norm(int x){return x+=x>>31&mod;}
int main(){
	f[1]=3240;
	f[2]=3081;
	f[3]=2841;
	f[4]=343;
	rp(i,5,N/2-5){
		f[i]=(223ll*f[i-1]+229ll*f[i-2]+239ll*f[i-3]%mod*f[i-4]+17)%mod;
	}
	rp(i,1,N/2-5){
		f[i]=norm(f[i]+f[i-1]-mod);
	}
	freopen("lovelive.in","r",stdin);
	T=rd();
	while(T--){
		n=rd(),m=rd();
		rp(i,1,n)a[i]=10+rd();
		a[0]=a[n+1]=11+m+n;
		rp(k,0,1)rp(i,1,n){
			fr[k][i]=i-1;
			while(a[fr[k][i]]<a[i]+k)fr[k][i]=fr[k][fr[k][i]];
		}
		rp(k,0,1)pr(i,n,1){
			bk[k][i]=i+1;
			while(a[bk[k][i]]<a[i]+k)bk[k][i]=bk[k][bk[k][i]];
		}
		ll A=0;
		rp(i,1,n){
			int x=fr[0][i],y=x,z=bk[1][i];
			if(a[x]>a[i]+m)continue;
			while(a[y]<=a[i]+m)y=fr[1][y];
			int lm=max(x,(y+i+1)/2);
			int rm=min(i,(x+z)/2);
			rp(j,lm,rm-1){
				int l=max(j-x,i-1-j);
				int r=min(j-y,z-1-j);
				if(l<r)(A+=1ll*a[j]*norm(f[r]-f[l]))%=mod;
			}
		}
		rp(i,1,n){
			int z=fr[1][i],x=bk[0][i],y=x,t=bk[1][i];
			if(a[x]>a[i]+m)continue;
			while(a[y]<=a[i]+m)y=bk[1][y];
			int lm=max(i,(z+t+1)/2);
			int rm=min(x,(i+y)/2);
			rp(j,lm,rm-1){
				int l=max(j-i,t-1-j);
				int r=min(j-z,y-1-j);
				if(l<r)(A+=1ll*a[j]*norm(f[r]-f[l]))%mod;
			}
		}
		printf("%lld\n",A);
	}
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Time Limit Exceeded

input:

3
6 0
3 1 3 1 3 1
8 4
5 8 4 6 5 7 8 5
7 3
2 1 3 2 2 1 3

output:


result: