QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#395853#7901. Basic Substring StructureGenshinImpactsFault#WA 15ms32348kbC++203.3kb2024-04-21 21:52:012024-04-21 21:52:01

Judging History

你现在查看的是最新测评结果

  • [2024-04-21 21:52:01]
  • 评测
  • 测评结果:WA
  • 用时:15ms
  • 内存:32348kb
  • [2024-04-21 21:52:01]
  • 提交

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]) - w[i];
        ma[i + j][a[j + 1]] += qry(i, i + j, a[j + 1]) - w[i];
        // 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;
        if(w[i] < i - 1){num[w[i]] ++; nowval += w[i];}
        else {nowval += i - 1; number ++;}
        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;
}

詳細信息

Test #1:

score: 100
Accepted
time: 7ms
memory: 32348kb

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: 15ms
memory: 30248kb

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:

94
127
347
3
211
9
265
363
279
15
95
113
58
351
225
3
334
357
376
316
3
19
123
66
15
82
36
258
11
63
28
85
84
103
251
190
21
48
303
63
102
20
24
67
311
362
266
296
348
281
326
281
231
312
3
330
54
328
3
69
32
147
322
39
329
90
241
3
164
345
250
20
155
3
404
393
390
81
269
359
20
54
21
279
3
17
351
3...

result:

wrong answer 2nd lines differ - expected: '128', found: '127'