一直过不了样例,求助!
查看原帖
一直过不了样例,求助!
1101744
xingshuyan000楼主2025/1/27 11:14

不知道咋回事,一直改代码都不对,都是过不了样例,非常难绷。

麻烦大佬帮我调一下,谢谢!

#include<bits/stdc++.h>
using namespace std;
typedef unsigned long long LL;
namespace fast_IO
{
	char buf[1 << 23], *p1 = buf, *p2 = buf;
	char __getchar()
	{
		return p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1 << 21, stdin), p1 == p2) ? EOF : *p1++;
	}
	template <typename T>
	T read()
	{
		T x = 0;
		char ch = __getchar();
		while(!isdigit(ch)) ch = __getchar();
		while(isdigit(ch)) {x = x * 10 + (ch ^ 48); ch = __getchar();}
		return x;
	}
}
const int N = 1e7 + 19;
LL h[N], key[N];
bool exist[N];
void insert(LL x, LL y)
{
	int k = x % N;
	while(exist[k] == true)
	{
		if(key[k] == x) break;
		k ++;
		if(k == N) k = 0;
	}
	key[k] = x, h[k] = y;
	exist[k] = true;
	return;
}
LL find(LL x)
{
	int k = x % N;
	while(exist[k] == true)
	{
		if(key[k] == x) return h[k];
		k ++;
		if(k == N) k = 0;
	}
	return 0;
}
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(nullptr), cout.tie(nullptr);
	int n;
	//n = fast_IO::read<int>();
	cin >> n;
	LL sum = 0;
	for(int i = 1; i <= n; i ++)
	{
		LL x, y;
		//x = fast_IO::read<LL>(), y = fast_IO::read<LL>();
		cin >> x >> y;
		LL ans = i * find(x);
		sum += i * ans;
		insert(x, y);
	}
	cout << sum << "\n";
	return 0;
}
2025/1/27 11:14
加载中...