QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#679022#9242. An Easy Geometry Problemlouhao088#WA 3ms3992kbC++232.6kb2024-10-26 16:41:352024-10-26 16:41:35

Judging History

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

  • [2024-10-26 16:41:35]
  • 评测
  • 测评结果:WA
  • 用时:3ms
  • 内存:3992kb
  • [2024-10-26 16:41:35]
  • 提交

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;

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;
}

int n,q,K,B,A[MAXN+5],pw[MAXN+5],sum[SIZE+5][2];

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]);
}
void Build(int now,int L,int R)
{
	if(L==R) {sum[now][0]=sum[now][1]=A[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)
{
	if(L==R) {sum[now][0]=plu(sum[now][0],v),sum[now][1]=plu(sum[now][1],v);return;}
	int mid=(L+R)>>1;
	if(x<=mid) Modify(Lson,L,mid,x,v);
	else Modify(Rson,mid+1,R,x,v);
	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 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 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]);
	pw[0]=1; for(int i=1;i<=n;i++) pw[i]=mul(pw[i-1],Base);
	Build(1,1,n);
	for(int opt,L,R,x;q--;)
	{
		opt=Read();
		if(opt==1)
		{
			L=Read(),R=Read(),x=2*Read();
			Modify(1,1,n,L,x); if(R<n) Modify(1,1,n,R+1,ABS(-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) {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))) 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: 100
Accepted
time: 0ms
memory: 3748kb

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
2
0

result:

ok 4 number(s): "1 0 2 0"

Test #2:

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

input:

5000 5000 2 0
-329 -328 -327 -326 -325 -324 -323 -322 -321 -320 -319 -318 -317 -316 -315 -314 -313 -312 -311 -310 -309 -308 -307 -306 -305 -304 -303 -302 -301 -300 -299 -298 -297 -296 -295 -294 -293 -292 -291 -290 -289 -288 -287 -286 -285 -284 -283 -282 -281 -280 -279 -278 -277 -276 -275 -274 -273 -...

output:

2
304
73
29
61
292
139
48
17
99
6
5
53
93
3
91
65
29
33
306
21
24
17
21
281
12
16
1
33
7
18
96
7
40
39
13
7
46
43
16
1
72
33
16
22
5
6
189
27
1
35
107
43
34
3
27
20
21
44
56
96
36
2
27
22
30
32
6
5
105
27
37
12
58
2
21
154
17
110
57
3
7
33
15
24
94
68
25
1
14
10
4
10
2
25
39
36
33
164
11
19
181
11
3...

result:

wrong answer 844th numbers differ - expected: '12', found: '9'