QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#346666 | #7901. Basic Substring Structure | oscaryang | WA | 11ms | 22044kb | C++20 | 2.0kb | 2024-03-08 20:56:36 | 2024-03-08 20:56:37 |
Judging History
answer
#include<bits/stdc++.h>
#define ull unsigned long long
#define vc vector
#define pb emplace_back
#define pii pair<int, int>
#define mkp make_pair
#define rep(i, a, b) for(int i = (a); i <= (b); ++i)
#define lep(i, a, b) for(int i = (a); i >= (b); --i)
#define int long long
using namespace std;
inline int read() {
int x = 0, w = 0; char ch = getchar(); while(!isdigit(ch)) w |= (ch == '-'), ch = getchar();
while(isdigit(ch)) x = x * 10 + (ch ^ 48), ch = getchar(); return w ? -x : x;
}
const int N = 2e5 + 5;
const ull Base = 19260817;
int n, ans, sum, a[N], K[N], B[N];
ull hs[N], pw[N];
char str[N];
unordered_map<int, int> f[N];
inline ull Hash(int l, int r, int u = 0, ull v = 0) {
ull res = hs[r] - hs[l - 1] * pw[r - l + 1];
if(u >= l && u <= r) res += (v - a[u]) * pw[r - u];
return res;
}
inline int lcp(int x, int y, int u = 0, ull v = 0) {
int l = 0, r = min(n - y + 1, n - x + 1), mid;
while(l <= r) {
mid = l + r >> 1;
if(Hash(x, x + mid - 1, u, v) == Hash(y, y + mid - 1, u, v)) l = mid + 1;
else r = mid - 1;
}
return r;
}
inline void add(int l, int r, int k, int b) {
K[l] += k; K[r + 1] -= k;
B[l] += b; B[r + 1] -= b;
}
inline void testcase() {
n = read(); ans = 0;
rep(i, 0, n) f[i].clear(), K[i] = B[i] = 0;
rep(i, 1, n) a[i] = read(), hs[i] = 1ull * Base * hs[i - 1] + a[i];
sum = n;
rep(i, 2, n) {
int len = lcp(1, i), c; sum += len;
add(1, min(len, i - 1), -1, len + 1);
add(i, i + len - 1, -1, len + i);
c = a[len + 1], f[i + len][c] += lcp(len + 2, i + len + 1, i + len, c) + 1;
if(len < i)
c = a[i + len], f[len + 1][c] += lcp(len + 2, i + len + 1, len + 1, c) + 1;
}
for(int i = 1, k = 0, b = 0, res; i <= n; i++) {
k += K[i]; b += B[i]; res = 0;
for(auto u : f[i]) res = max(res, u.second);
ans += (sum - k * i - b + res) ^ i;
}
printf("%lld\n", ans);
}
signed main() {
pw[0] = 1;
rep(i, 1, N - 1) pw[i] = 1ull * Base * pw[i - 1];
int t = read(); while(t--) testcase();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 5ms
memory: 21892kb
input:
2 4 2 1 1 2 12 1 1 4 5 1 4 1 9 1 9 8 10
output:
15 217
result:
ok 2 lines
Test #2:
score: -100
Wrong Answer
time: 11ms
memory: 22044kb
input:
10000 8 2 1 2 1 1 1 2 2 9 2 2 1 2 1 2 1 2 1 15 2 1 2 1 1 1 1 2 2 1 2 1 2 2 1 2 1 1 10 2 1 1 1 2 2 1 1 2 2 3 2 1 2 11 1 2 2 1 1 2 1 2 2 1 1 14 2 1 1 1 1 2 1 1 1 2 2 1 2 1 12 2 2 2 1 2 2 2 1 1 2 1 2 4 2 1 1 2 8 1 2 2 2 1 2 1 1 8 1 1 2 1 2 1 1 1 6 2 1 1 1 2 2 14 2 2 1 1 1 1 2 2 2 1 2 2 1 1 10 1 2 2 1 1...
output:
100 133 352 3 211 9 265 363 280 15 95 111 58 352 225 3 341 362 374 316 3 17 122 72 15 83 36 258 16 63 28 94 90 103 252 196 21 47 314 63 102 20 24 65 314 362 265 309 359 281 326 281 230 312 3 330 57 328 3 69 35 147 320 45 351 91 245 3 162 356 246 20 154 3 404 393 392 81 269 357 20 57 21 279 3 17 351 ...
result:
wrong answer 1st lines differ - expected: '94', found: '100'