社区讨论

有符号自然溢出哈希

学术版参与者 3已保存回复 3

讨论操作

快速查看讨论及其快照的属性,并进行相关操作。

当前回复
3 条
当前快照
1 份
快照标识符
@mhj1ybz8
此快照首次捕获于
2025/11/03 19:24
4 个月前
此快照最后确认于
2025/11/03 19:24
4 个月前
查看原帖
P3498
CPP
#include <bits/stdc++.h>
#define pb push_back
#define fi first
#define se second
#define ep emplace
#define pii pair<int, int>

#define int long long

using namespace std;

#ifdef ONLINE_JUDGE
#define debug(...) 0
#else
#define debug(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)
#endif

// you need fread or not? no thanks 
// is the range of maxn correct? check it again with the problemn! now!
// will the answer be bigger than 1e18. read the problem agian! NOW!

const int N = 2e5 + 10, B = 1e9 + 7;

int n, s, f = 1;
int a[N], p[N], q[N];
unordered_map<int, bool> m;
vector<int> v; 

signed main() {
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    cin >> n;
    for (int i = 1; i <= n; ++i)
    	cin >> a[i],
    	p[i] = p[i - 1] * B + a[i],assert(p[i]>=0);
    for (int i = n; i >= 1; --i)
    	q[i] = q[i + 1] * B + a[i];
    for (int i = 1, c, l, r; i <= n; ++i) {
    	c = 0, f *= B;
    	if (s > n / i) 
    		break;
    	m.clear();
    	for (int j = 1; j <= n - i + 1; j += i) {
    		l = p[j + i - 1] - p[j - 1] * f, r = q[j] - q[j + i] * f;
			if (!m[l] && !m[r])
				m[l] = m[r] = 1, c++; 
		}
		if (s == c) 
			v.pb(i);
		if (s < c)
			v.clear(), v.pb(i), s = c; 
	}
	cout << s << ' ' << v.size() << '\n';
	for (int e: v) 
		cout << e << ' ';
    cout << '\n' << flush;
    return 0;
}

这一份代码,在哈希的时候加了assert,全部RE了。
但是删掉assert就AC了
注意 #define int long long 而非 unsigned long long

回复

3 条回复,欢迎继续交流。

正在加载回复...