求助 RE qwq
查看原帖
求助 RE qwq
230804
Durancer楼主2021/9/17 08:27

RE\text{RE}nn 遍打开题解一看和第一篇题解写的一毛一样,数组还开得更大了一点,但不知道哪里 RE\text{RE} 了 T A T。

/*
	折半搜索:换成 	a*b+c = (f+e) * d 
	忘了会有负数... 
*/ 
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<vector>
#include<algorithm>
#include<map>
#define int long long
using namespace std;
const int N=1e2+9;
const int M=1e6+20;
const int mod=1e6+9;
const int Mod=1e9+7; 
struct node{
	int last;
	int to;
}e[M];
int a[N],n,m;
long long ans;
int cnt;
int val[M],key[M],head[M];
int Cun[N];
int read()
{
	int f=1,x=0;
	char s=getchar();
	while(s<'0'||s>'9'){if(s=='-')f=-1;s=getchar();}
	while(s>='0'&&s<='9'){x=(x<<1)+(x<<3)+(s^'0');s=getchar();}
	return f*x;
}
void add(int x)
{
	for(int i=head[(x+Mod)%mod];i;i=e[i].last)
	{
		if(key[i]==x)
		{
			val[i]++;
			return;
		}
	}
	e[++cnt].last=head[(x+Mod)%mod];
	val[cnt]=1;
	key[cnt]=x;
	head[(x+Mod)%mod]=cnt;
}
int find(int x)
{
	for(int i=head[(x+Mod)%mod];i;i=e[i].last)
		if(key[i]==x)
			return val[i];
	return 0;
}
void work()//折半搜索 = 不搜索 /px 
{
	for(int i=1;i<=n;i++)
		for(int j=1;j<=n;j++)
			for(int k=1;k<=n;k++)
				add(a[i]*a[j]+a[k]);
	for(int i=1;i<=n;i++)
	{
		if(!a[i]) continue;//Maybe RE
		for(int j=1;j<=n;j++)
			for(int k=1;k<=n;k++)
				ans+=find((a[j]+a[k])*a[i]);
	}
}
signed main()
{
	n=read();
	for(int i=1;i<=n;i++)
		a[i]=read();
	work();
	printf("%lld\n",ans);
	return 0;
}

2021/9/17 08:27
加载中...