QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#552305#9242. An Easy Geometry Problemucup-team191#WA 13ms9948kbC++232.1kb2024-09-07 21:52:222024-09-07 21:52:27

Judging History

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

  • [2024-09-07 21:52:27]
  • 评测
  • 测评结果:WA
  • 用时:13ms
  • 内存:9948kb
  • [2024-09-07 21:52:22]
  • 提交

answer

#include <bits/stdc++.h>
#define x first
#define y second
using namespace std;
using ll=long long;
using pii=pair<int,int>;
using vi=vector<int>;
using vl=vector<ll>;
#define pb push_back
#define all(a) begin(a),end(a)

const int N=200010,MOD=1e9+7,M=1<<18;
const char en='\n';
const ll LLINF=1ll<<60;
mt19937 rng(37952);
uniform_int_distribution<int> dis(4000,MOD-4000);

int n,q,k,b,a[N],p1[N];
array<int,2> seg[2][M*2+10];

array<int,2> mer1(array<int,2> a,array<int,2> b)
{
	return {(a[0]*1ll*p1[b[1]]+b[0])%MOD,a[1]+b[1]};
}

array<int,2> mer2(array<int,2> a,array<int,2> b)
{
	return {(b[0]*1ll*p1[a[1]]+a[0])%MOD,a[1]+b[1]};
}

void upd(int i,int x)
{
	i+=M;
	seg[0][i][1]=1;
	seg[1][i][1]=1;
	seg[0][i][0]=(seg[0][i][0]+x)%MOD;
	seg[1][i][0]=(seg[1][i][0]+MOD-x)%MOD;
	for (i/=2;i;i/=2) seg[0][i]=mer1(seg[0][i*2],seg[0][i*2+1]),seg[1][i]=mer2(seg[1][i*2],seg[1][i*2+1]);
}

array<int,2> ge(int j,int l,int r,int lo=0,int hi=M,int i=1)
{
	if (lo>=l && hi<=r) return seg[j][i];
	if (lo>=r || hi<=l) return {0,0};
	int mid=(lo+hi)/2;
	if (j==0) return mer1(ge(j,l,r,lo,mid,i*2),ge(j,l,r,mid,hi,i*2+1));
	else return mer2(ge(j,l,r,lo,mid,i*2),ge(j,l,r,mid,hi,i*2+1));
}

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int baz=dis(rng);
	p1[0]=1;
	for (int i=1;i<N;++i) p1[i]=(p1[i-1]*1ll*baz)%MOD;
	cin>>n>>q>>k>>b;
	b*=2;
	for (int i=0;i<n;++i)
	{
		cin>>a[i];
		a[i]=a[i]*2-i*k;
	}
	for (int i=1;i<n;++i)
	{
		upd(i,(a[i]-a[i-1]+MOD)%MOD);
	}
	while (q--)
	{
		int ti;
		cin>>ti;
		if (ti==1)
		{
			int l,r,x;
			cin>>l>>r>>x;
			x*=2;
			--l;
			upd(l,x);
			upd(r,-x);
		}
		else
		{
			int i;
			cin>>i;
			--i;
			if (i==0 || i==n-1)
			{
				cout<<0<<en;
				continue;
			}
			int d1=ge(0,i,i+1)[0],d2=ge(0,i+1,i+2)[0];
			if ((d1+d2)%MOD!=b)
			{
				cout<<0<<en;
				continue;
			}
			int lo=0,hi=min(i-1,n-i-2);
			int kr1=i,po2=i+2;
			while (lo<hi)
			{
				int mid=(lo+hi+1)/2;
				//cout<<mid<<' '<<i-mid<<' '<<kr1<<' '<<po2<<' '<<i+mid+2<<en;
				if (ge(0,i-mid,kr1)==ge(1,po2,i+mid+2)) lo=mid;
				else hi=mid-1;
			}
			cout<<lo+1<<en;
		}
	}
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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: 13ms
memory: 9948kb

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 349th numbers differ - expected: '25', found: '1'