关于RE
查看原帖
关于RE
464004
ZepX_D楼主2023/11/16 15:44

实在想不出来为什么会 RE ,求 hack

#include <bits/stdc++.h>
#define LL unsigned long long

using namespace std;

const int N = 500010;
int h[N],n;
LL B[N],c[N],d[N];

void A(int x,int p)
{
	while(x <= n) c[x] += B[x-p],x += x&-x;
	p = x = n-p+1;
	while(x <= n) d[x] += B[x-p],x += x&-x;
}

LL Q1(int x,int p)
{
	LL res = 0;
	while(x) res += c[x]*B[p-x],x -= x&-x;
	return res;
}

LL Q2(int x,int p)
{
	LL res = 0;p = x = n-p+1;
	while(x) res += d[x]*B[p-x],x -= x&-x;
	return res;
}

int main()
{
	ios::sync_with_stdio(0);
	int T;cin >> T;B[0] = 1;
	for (int i = 1;i <= 500000;i++) B[i] = B[i-1]*199;
	while(T--)
	{
		cin >> n;
		bool f = 0;
		for (int i = 1;i <= n && !f;i++)
		{
			cin >> h[i];
			A(h[i],h[i]);
			int k = min(h[i]-1,n-h[i]);
			LL a = Q1(h[i]+k,h[i]+k)-Q1(h[i]-k-1,h[i]-k-1)*B[k*2+1];
			LL b = Q2(h[i]-k,h[i]-k)-Q2(h[i]+k+1,h[i]+k+1)*B[k*2+1];
			if (a != b) cout << "Y" << '\n',f = 1;
		}
		for (int i = 1;i <= n;i++) c[i] = d[i] = 0;
		if (!f) cout << "N" << '\n';
	}
	return 0;
}
2023/11/16 15:44
加载中...