QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#679208#9242. An Easy Geometry Problemlouhao088#WA 1ms7916kbC++234.0kb2024-10-26 17:08:122024-10-26 17:08:16

Judging History

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

  • [2024-10-26 17:08:16]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:7916kb
  • [2024-10-26 17:08:12]
  • 提交

answer

#include<bits/stdc++.h>
#define Lson (now<<1)
#define Rson (now<<1|1)
using namespace std;

const int MAXN=2e5,SIZE=524288;
const int Base=2333,MOD=1e9+7,mod=1019260817;

inline int Read()
{
	int res=0,sgn=1;char c;
	while(1) {c=getchar();if(c=='-') {sgn=-1;break;}if('0'<=c && c<='9') {res=c-'0';break;}}
	while(1) {c=getchar();if('0'<=c && c<='9') res=res*10+c-'0';else break;}
	return sgn*res;
}
inline int plu(int a,int b) {return a+b-(a+b>=MOD)*MOD;}
inline int mul(int a,int b) {return 1ll*a*b%MOD;}
inline int ABS(int x)
{
	if(x>=MOD) x-=MOD;
	if(x<0) x+=MOD;
	return x;
}
inline int plu1(int a,int b) {return a+b-(a+b>=mod)*mod;}
inline int mul1(int a,int b) {return 1ll*a*b%mod;}
inline int ABS1(int x)
{
	if(x>=mod) x-=mod;
	if(x<0) x+=mod;
	return x;
}
int n,q,K,B,A[MAXN+5],pw[MAXN+5],sum[SIZE+5][2];
int pw1[MAXN+5],sum1[SIZE+5][2],A1[MAXN+5];

inline void PushUp(int now,int len)
{
	sum[now][0]=plu(sum[Lson][0],mul(pw[(len+1)>>1],sum[Rson][0]));
	sum[now][1]=plu(mul(pw[len>>1],sum[Lson][1]),sum[Rson][1]);

    sum1[now][0]=plu1(sum1[Lson][0],mul1(pw1[(len+1)>>1],sum1[Rson][0]));
	sum1[now][1]=plu1(mul1(pw1[len>>1],sum1[Lson][1]),sum1[Rson][1]);
}
void Build(int now,int L,int R)
{
	if(L==R) {
        sum[now][0]=sum[now][1]=A[L];
        sum1[now][0]=sum1[now][1]=A1[L];
        return;
    }
	int mid=(L+R)>>1;
	Build(Lson,L,mid);
	Build(Rson,mid+1,R);
	PushUp(now,R-L+1);
}
void Modify(int now,int L,int R,int x,int v,int v1)
{
	if(L==R) {
        sum[now][0]=plu(sum[now][0],v),sum[now][1]=plu(sum[now][1],v);
        sum1[now][0]=plu1(sum1[now][0],v1),sum1[now][1]=plu1(sum1[now][1],v1);
        return;
    }
	int mid=(L+R)>>1;
	if(x<=mid) Modify(Lson,L,mid,x,v,v1);
	else Modify(Rson,mid+1,R,x,v,v1);
	PushUp(now,R-L+1);
}
int Hash0(int now,int L,int R,int QL,int QR)
{
	if(QR<L || R<QL) return 0;
	if(QL<=L && R<=QR) return mul(pw[L-QL],sum[now][0]);
	int mid=(L+R)>>1;
	return plu(Hash0(Lson,L,mid,QL,QR),Hash0(Rson,mid+1,R,QL,QR));
}
int Hash1(int now,int L,int R,int QL,int QR)
{
	if(QR<L || R<QL) return 0;
	if(QL<=L && R<=QR) return mul(pw[QR-R],sum[now][1]);
	int mid=(L+R)>>1;
	return plu(Hash1(Lson,L,mid,QL,QR),Hash1(Rson,mid+1,R,QL,QR));
}
int Hash01(int now,int L,int R,int QL,int QR)
{
	if(QR<L || R<QL) return 0;
	if(QL<=L && R<=QR) return mul1(pw1[L-QL],sum1[now][0]);
	int mid=(L+R)>>1;
	return plu1(Hash01(Lson,L,mid,QL,QR),Hash01(Rson,mid+1,R,QL,QR));
}
int Hash11(int now,int L,int R,int QL,int QR)
{
	if(QR<L || R<QL) return 0;
	if(QL<=L && R<=QR) return mul1(pw1[QR-R],sum1[now][1]);
	int mid=(L+R)>>1;
	return plu1(Hash11(Lson,L,mid,QL,QR),Hash11(Rson,mid+1,R,QL,QR));
}
int Ask(int now,int L,int R,int x)
{
	if(L==R) return sum[now][0];
	int mid=(L+R)>>1;
	if(x<=mid) return Ask(Lson,L,mid,x);
	return Ask(Rson,mid+1,R,x);
}
int Ask1(int now,int L,int R,int x)
{
	if(L==R) return sum1[now][0];
	int mid=(L+R)>>1;
	if(x<=mid) return Ask1(Lson,L,mid,x);
	return Ask1(Rson,mid+1,R,x);
}
int main()
{
	n=Read(),q=Read(),K=Read(),B=Read();
	B=ABS(2*B);
	for(int i=1;i<=n;i++) A[i]=2*Read()-K*i;
	for(int i=n;i;i--) A[i]-=A[i-1];
	for(int i=1;i<=n;i++) A[i]=ABS(A[i]),A1[i]=ABS1(A[i]);
	pw[0]=1;pw1[0]=1; 
    for(int i=1;i<=n;i++){
        pw[i]=mul(pw[i-1],Base);
        pw1[i]=mul1(pw1[i-1],Base);
    }
	Build(1,1,n);
	for(int opt,L,R,x;q--;)
	{
		opt=Read();
		if(opt==1)
		{
			L=Read(),R=Read(),x=Read();
			Modify(1,1,n,L,ABS(2*x),ABS1(2*x)); if(R<n) Modify(1,1,n,R+1,ABS(-2*x),ABS1(-2*x));
		}
		else
		{
			x=Read();
			if(x==1 || x==n) {puts("0");continue;}
			if(plu(Ask(1,1,n,x),Ask(1,1,n,x+1))!=B||plu1(Ask1(1,1,n,x),Ask1(1,1,n,x+1))!=B) {puts("0");continue;}
			//printf("well\n"); 
			L=2,R=min(x,n-x);
			for(int mid;L<=R;)
			{
				mid=(L+R)>>1;
				if(plu(Hash0(1,1,n,x-mid+1,x-1),Hash1(1,1,n,x+2,x+mid))||plu1(Hash01(1,1,n,x-mid+1,x-1),Hash11(1,1,n,x+2,x+mid))) R=mid-1;
				else L=mid+1;
			}
			printf("%d\n",R);
		}
	}
	return 0;
}
/*
6 6 6 2
1 5 9 10 15 18
2 2
1 3 3 -3
2 2
1 3 4 3
2 3
2 4
*/

詳細信息

Test #1:

score: 0
Wrong Answer
time: 1ms
memory: 7916kb

input:

6 6 6 2
1 5 9 10 15 18
2 2
1 3 3 -3
2 2
1 3 4 3
2 3
2 4

output:

1
0
0
0

result:

wrong answer 3rd numbers differ - expected: '2', found: '0'