萌妹刚学OI,在线求调教 QAQ
查看原帖
萌妹刚学OI,在线求调教 QAQ
629377
iamajcer楼主2024/7/19 21:22
#include <bits/stdc++.h>
using namespace std;
const int N=3e5+5;
typedef unsigned long long ull;

int n, a[N], ans=0, flag=0, Max=0, st=0;
ull b[N], h[N], h2[N];
ull Rand()
{
	return ((ull)rand() << 60) + ((ull)rand() << 31) + ((ull)rand() << 15) + ((ull)rand() << 7) + ((ull)rand() << 3) + ((ull)rand() << 1) + (ull)rand();
}
bool check(int L, int R)
{
	return (h2[R]^h2[L-1])==(h[R-L+1]);
}
void get()
{
	int pos=1;
	
	for (int i=1; i<=n; i++) h2[i]=h2[i-1]^b[a[i]];
	while (a[pos]!=1 && pos<=n) pos++;
	while (pos<=n)
	{
		int Max=a[++pos];
		while (a[pos]!=1 && pos<=n)
		{
			Max=max(Max, a[pos]);
			if (check(pos-Max+1, pos)) ans++;
			
			pos++;
		}
	}
}
int main()
{
	srand((ull)time(0));
	
	scanf("%d", &n);
	for (int i=1; i<=n; i++) b[i]=Rand();
	for (int i=1; i<=n; i++) h[i]=h[i-1]^b[i];
/*
	if (n==8) cout<<7;
	if (n==5) cout<<6;
	*/
	for (int i=1; i<=n; i++) 
	{
		scanf("%d", &a[i]);
		ans+=(a[i]==1);
	}
	
	get();
//	for (int i=1; i<=n/2; i++) swap(a[i], a[n-i+1]);
	reverse(a+1, a+1+n);
	get();
	
	printf("%d", ans);
	return 0;
}
/*
8
2 4 1 3 4 2 1 2

*/

为什么这份代码会RE呀?
求大佬调调,玄关!
Thanks♪(・ω・)ノ

2024/7/19 21:22
加载中...