QOJ.ac
QOJ
ID | 提交记录ID | 题目 | Hacker | Owner | 结果 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|
#516 | #307641 | #8000. 平方数 | Qingyu | zhouyuhang | Success! | 2024-01-21 22:25:48 | 2024-01-21 22:25:48 |
详细
Extra Test:
Wrong Answer
time: 391ms
memory: 27848kb
input:
300000 11451419198100000000000000000000000 11451419198100000000000000000000001 11451419198100000000000000000000002 11451419198100000000000000000000003 11451419198100000000000000000000004 11451419198100000000000000000000005 11451419198100000000000000000000006 11451419198100000000000000000000007 11451...
output:
1148403 71923 228065 71923 228066 71923 228067 71923 228068 71923 228069 71923 228070 71923 228071 71923 228072 71923 228073 71923 228074 71923 228075 71923 228076 71923 228077 71924 71924 71924 71925 71924 71926 71924 71927 71924 71928 71924 71929 71924 71930 71924 71931 71924 71932 71924 71933 719...
result:
wrong answer 1st numbers differ - expected: '1148390', found: '1148403'
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#307641 | #8000. 平方数 | zhouyuhang | 97 | 444ms | 32596kb | C++14 | 2.0kb | 2024-01-18 22:36:29 | 2024-01-21 22:26:07 |
answer
#include <bits/stdc++.h>
using namespace std;
using ull = unsigned long long;
using i128 = __int128_t;
const int N = 3e5 + 10;
int n;
i128 a[N];
i128 read() {
i128 x = 0; int ch = getchar();
while (!isdigit(ch)) ch = getchar();
while (isdigit(ch)) x = x * 10 + ch - '0', ch = getchar();
return x;
}
mt19937 Rnd(time(0));
int Rand(int l, int r) { return Rnd() % (r - l + 1) + l;}
bool isPrime(int n) { for (int i = 2; i * i <= n; ++i) if (n % i == 0) return 0; return 1;}
int Pow(int x, int y, int p) {
int r = 1;
for (; y; y >>= 1, x = 1ll * x * x % p) if (y & 1) r = 1ll * r * x % p;
return r;
}
ull v[N];
vector<ull> val;
vector<int> vec[N];
bool np[N];
int tot = 0, prm[N];
int f[N];
int main() {
n = read();
for (int i = 1; i <= n; ++i) a[i] = read();
for (int t = 0; t < 64; ++t) {
int p = Rand(1e5, 3e5);
while (!isPrime(p)) p = Rand(1e5, 3e5);
f[0] = f[1] = 1, tot = 0;
for (int i = 2; i < p; ++i) {
if (!np[i]) { prm[++tot] = i, f[i] = Pow(i, (p - 1) / 2, p);}
for (int j = 1, t; (t = i * prm[j]) < p; ++j) {
np[t] = 1, f[t] = 1ll * f[i] * f[prm[j]] % p;
if (i % prm[j] == 0) break;
}
}
for (int i = 1; i <= n; ++i) {
int c = 0; i128 x = a[i];
while (x % p == 0) x /= p, c ^= 1;
v[i] ^= ((f[x % p] == 1) ^ (c & 1) ? 0 : (i128)1) << t;
}
}
for (int i = n; i >= 1; --i) v[i] ^= v[i + 1];
for (int i = 1; i <= n + 1; ++i) val.push_back(v[i]);
sort(val.begin(), val.end());
for (int i = 1; i <= n + 1; ++i) v[i] = lower_bound(val.begin(), val.end(), v[i]) - val.begin();
long long ans = 0;
vec[0].push_back(n + 1);
for (int i = n; i >= 1; --i) {
ans += vec[v[i]].size();
vec[v[i]].push_back(i);
}
cout << ans << '\n';
int cnt = 1e5;
for (int i = 1; i <= n; ++i) {
vec[v[i]].pop_back();
for (int j = (int)vec[v[i]].size() - 1; j >= 0; --j) {
if (cnt == 0) { return 0;}
cout << i << ' ' << vec[v[i]][j] - 1 << '\n';
--cnt;
}
}
return 0;
}