QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#395852 | #7894. Many Many Heads | GenshinImpactsFault# | WA | 3ms | 30288kb | C++20 | 3.2kb | 2024-04-21 21:38:53 | 2024-04-21 21:38:54 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int seed = 131; int mod = 998244353;
int ksm(int a, int b)
{
int ans = 1;
while (b) {if (b & 1) ans = 1LL * ans * a % mod; b >>= 1; a = 1LL * a * a % mod;}
return ans;
}
int iseed = ksm(seed, mod - 2);
#define N 400010
int H[N], iH[N], h[N];
int n, a[N], w[N];
int num[N];
map<int, ll>ma[N];
ll ans[N];
int qhsh(int l, int r, int x, int v)
{
if(l <= x && x <= r)
{
int s = (h[r] + mod - h[l - 1]) % mod;
s = (s + mod - 1LL * a[x] * H[x] % mod) % mod;
s = (s + 1LL * v * H[x]) % mod;
return 1LL * s * iH[l] % mod;
}
else return 1LL * (h[r] + mod - h[l - 1]) * iH[l] % mod;
}
int qry(int st, int x, int v)
{
int l = 1, r = n - st + 1, ans = 0;
while (l <= r)
{
int mid = (l + r) >> 1;
if(qhsh(1, mid, x, v) == qhsh(st, st + mid - 1, x, v)) ans = mid, l = mid + 1;
else r = mid - 1;
}
return ans;
}
void solve() {
cin >> n;
for (int i = 1; i <= n; i ++) cin >> a[i];
H[0] = 1; for (int i = 1; i <= n; i ++) H[i] = 1LL * H[i - 1] * seed % mod;
iH[0] = 1; for (int i = 1; i <= n; i ++)iH[i] = 1LL * iH[i - 1] * iseed % mod;
for (int i = 1; i <= n; i ++) h[i] = (h[i - 1] + 1LL * H[i] * a[i]) % mod;
// for (int i = 1; i <= n; i ++)cout << qhsh(i, i, n + 1, 0) << ' '; cout << endl;
for (int i = 2; i <= n; i ++)w[i] = qry(i, n + 1, 0);
// cout << "X1" << endl;
// for (int i = 1; i <= n; i ++)cout << w[i] << ' '; cout << endl;
for (int i = 2; i <= n; i ++)
{
int j = w[i];
if (i + j > n)continue;
ma[j + 1][a[i + j]] += qry(i, j + 1, a[i + j]);
ma[i + j][a[j + 1]] += qry(i, i + j, a[j + 1]);
cout << "??:" << i << ' ' << w[i] << ' ' << qry(i, j + 1, a[i + j]) << ' ' << qry(i, i + j, a[j + 1]) << endl;
}
int number = 0; ll nowval = 0;
for (int i = 2; i <= n; i ++)
{
num[i + w[i]] ++; number ++;
number -= num[i];
ans[i] += nowval;
nowval += number;
}
number = nowval = 0;
for (int i = 0; i <= n + 1; i ++)num[i] = 0;
for (int i = 1; i <= n; i ++)cout << ans[i] << ' '; cout << '\n';
for (int i = n; i >= 1; i --)
{
ans[i] += nowval;
num[w[i]] ++; nowval += w[i];
number += num[i - 1];
nowval -= number;
}
for (int i = 0; i <= n + 1; i ++)num[i] = 0;
for (int i = 1; i <= n; i ++)cout << ans[i] << ' '; cout << '\n';
for (int i = 1; i <= n; i ++)
{
ll vmx = 0;
for (auto [_, v] : ma[i]) vmx = max(vmx, v);
for (auto [_, v] : ma[i]) cout << "??:" << i << ' ' << _ << ' ' << v << endl;
ans[i] += vmx;
}
for (int i = 1; i <= n; i ++) ans[i] += n;
ll val = 0;
for (int i = 1; i <= n; i ++) val += (i ^ ans[i]);
for (int i = 1; i <= n; i ++)cout << ans[i] << ' '; cout << '\n';
cout << val << '\n';
for (int i = 1; i <= n; i ++)ans[i] = 0, ma[i].clear();
}
int main() {
// ios::sync_with_stdio(0); cin.tie(nullptr);
int T; cin >> T;
for(; T; --T) solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 3ms
memory: 30288kb
input:
6 )) ((() [()] ()[()]() ([()]) ([])([])
output:
0 0 0 0 0 0
result:
wrong output format YES or NO expected, but 0 found [1st token]