QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#73559#4881. Hard Problemaurelion_solWA 3ms7736kbC++141.7kb2023-01-25 20:36:052023-01-25 20:36:08

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:36:08]
  • 评测
  • 测评结果:WA
  • 用时:3ms
  • 内存:7736kb
  • [2023-01-25 20:36:05]
  • 提交

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: 100
Accepted
time: 3ms
memory: 7624kb

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:

144768
745933
448953

result:

ok 3 number(s): "144768 745933 448953"

Test #2:

score: -100
Wrong Answer
time: 3ms
memory: 7736kb

input:

1
500 9
446 46 319 109 370 33 354 55 237 3 438 425 246 9 258 142 228 496 220 142 171 259 477 419 97 108 409 63 386 148 172 11 165 365 330 111 22 86 339 366 356 274 87 124 446 73 325 158 135 445 9 205 316 204 319 346 383 352 211 192 372 225 442 444 115 67 67 14 499 312 431 433 184 316 133 240 36 216 ...

output:

815696378

result:

wrong answer 1st numbers differ - expected: '785335608', found: '815696378'