QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#252077#7748. Karshilov's Matching Problem IIucup-team1447#WA 132ms30252kbC++142.1kb2023-11-15 15:27:422023-11-15 15:27:42

Judging History

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

  • [2024-08-25 20:42:18]
  • hack成功,自动添加数据
  • (/hack/789)
  • [2023-11-15 15:27:42]
  • 评测
  • 测评结果:WA
  • 用时:132ms
  • 内存:30252kb
  • [2023-11-15 15:27:42]
  • 提交

answer

// This Code was made by Chinese_zjc_.
#include <bits/stdc++.h>
// #define debug
int n, m, skmp[150005], sZ[150005], tZ[150005], ql[150005], qr[150005];
long long w[150005], sum[150005], fsum[150005], ans[150005];
std::string s, t;
std::vector<int> g[150005], q[150005];
std::set<int> app;
void add(int pos, long long val)
{
    ++pos;
    while (pos <= n)
    {
        sum[pos] += val;
        pos += pos & -pos;
    }
}
long long query(int pos)
{
    long long res = 0;
    while (pos)
    {
        res += sum[pos];
        pos -= pos & -pos;
    }
    return res;
}
signed main()
{
    std::ios::sync_with_stdio(false);
    std::cin >> n >> m >> s >> t;
    for (int i = 1; i <= n; ++i)
        std::cin >> w[i], w[i] += w[i - 1];
    for (int i = 1, j = 0; i != n; ++i)
    {
        while (j && s[i] != s[j])
            j = skmp[j];
        skmp[i + 1] = s[i] == s[j] ? ++j : j;
    }
    for (int i = 1; i <= n; ++i)
        fsum[i] = fsum[skmp[i]] + w[i];
    for (int i = 1, pos = 0; i != n; ++i)
    {
        sZ[i] = std::max(0, std::min(sZ[i - pos], pos + sZ[pos] - i));
        while (i + sZ[i] != n && s[sZ[i]] == s[i + sZ[i]])
            ++sZ[i];
        if (i + sZ[i] > pos + sZ[pos])
            pos = i;
    }
    for (int i = 0, pos = 0; i != n; ++i)
    {
        tZ[i] = std::min(sZ[i - pos], pos + tZ[pos] - i);
        while (i + tZ[i] != n && s[tZ[i]] == t[i + tZ[i]])
            ++tZ[i];
        if (i + tZ[i] > pos + tZ[pos])
            pos = i;
        g[i + tZ[i]].push_back(i);
    }
    for (int i = 1; i <= m; ++i)
    {
        std::cin >> ql[i] >> qr[i];
        --ql[i];
        q[qr[i]].push_back(i);
    }
    for (int i = 0; i <= n; ++i)
    {
        app.insert(i);
        for (auto j : g[i])
            app.erase(j), add(j, w[i - j]);
        for (auto j : q[i])
        {
            ans[j] = query(qr[j]) - query(ql[j]);
            std::set<int>::iterator iter = app.lower_bound(ql[j]);
            if (iter != app.end())
                ans[j] += fsum[i - *iter];
        }
    }
    for (int i = 1; i <= m; ++i)
        std::cout << ans[i] << '\n';
    return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 2ms
memory: 12000kb

input:

8 5
abbabaab
aababbab
1 2 4 8 16 32 64 128
1 1
2 3
3 5
4 7
1 8

output:

1
3
3
16
38

result:

ok 5 lines

Test #2:

score: 0
Accepted
time: 4ms
memory: 10580kb

input:

15 4
heheheheehhejie
heheheheheheheh
3 1 4 1 5 9 2 6 5 3 5 8 9 7 9
2 3
4 8
2 6
1 15

output:

3
13
13
174

result:

ok 4 lines

Test #3:

score: -100
Wrong Answer
time: 132ms
memory: 30252kb

input:

150000 150000
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa...

output:

1935398007491
3047546480277
6796791516818
6152564712015
2263776030934
1214664188656
5005659793397
826003408958
1298311607366
4129548161103
2693630357401
4219950716927
3517822884085
835952236064
6155659928586
3770809168230
451944432359
1500542764866
1101896588692
147488854451
6672155044524
4036176795...

result:

wrong answer 1st lines differ - expected: '108147037823514', found: '1935398007491'