QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#602491#9425. Generated Stringucup-team3215WA 1673ms85952kbC++2310.0kb2024-10-01 08:09:072024-10-01 08:09:08

Judging History

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

  • [2024-10-14 17:49:05]
  • hack成功,自动添加数据
  • (/hack/995)
  • [2024-10-01 08:09:08]
  • 评测
  • 测评结果:WA
  • 用时:1673ms
  • 内存:85952kb
  • [2024-10-01 08:09:07]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;
constexpr int LOG = 20;
constexpr int INF = 1e9;

using vi = vector<int>;
#define all(c) c.begin(),c.end()
#define sz(c) (int)c.size()
#define rep(i, l, r) for(int i = l;i < r;++i)

struct SuffixArray {
    vi sa, lcp;

    SuffixArray() = default;

    SuffixArray(string &s, int lim = 256) { // or basic_string<int>
        int n = sz(s) + 1, k = 0, a, b;
        vi x(all(s)), y(n), ws(max(n, lim)), rank(n);
        x.push_back(0), sa = lcp = y, iota(all(sa), 0);
        for (int j = 0, p = 0; p < n; j = max(1, j * 2), lim = p) {
            p = j, iota(all(y), n - j);
            rep(i, 0, n) if (sa[i] >= j) y[p++] = sa[i] - j;
            fill(all(ws), 0);
            rep(i, 0, n) ws[x[i]]++;
            rep(i, 1, lim) ws[i] += ws[i - 1];
            for (int i = n; i--;) sa[--ws[x[y[i]]]] = y[i];
            swap(x, y), p = 1, x[sa[0]] = 0;
            rep(i, 1, n) a = sa[i - 1], b = sa[i], x[b] =
                        (y[a] == y[b] && y[a + j] == y[b + j]) ? p - 1 : p++;
        }
        rep(i, 1, n) rank[sa[i]] = i;
        for (int i = 0, j; i < n - 1; lcp[rank[i++]] = k)
            for (k &&k--, j = sa[rank[i] - 1];
                    s[i + k] == s[j + k];
        k++);
    }
};

struct LCP {
    SuffixArray SA;
    vector<int> pos;
    vector<vector<int>> st;

    LCP() = default;

    LCP(string &s) : SA(s) {
        int n = s.size();
        pos.resize(s.size());
        for (int i = 1; i <= n; ++i) {
            pos[SA.sa[i]] = i;
        }
        st = vector<vector<int>>(LOG, vector<int>(n + 1));
        st[0] = SA.lcp;
        for (int i = 1; i < LOG; ++i) {
            for (int j = 0; j + (1 << i) - 1 <= n; ++j) {
                st[i][j] = min(st[i - 1][j], st[i - 1][j + (1 << (i - 1))]);
            }
        }
    }

    int ask(int l, int r) {
        int len = r - l + 1;
        int lg = __lg(len);
        return min(st[lg][l], st[lg][r - (1 << lg) + 1]);
    }

    int query(int x, int y) {
        if (x == y)return (pos.size() - x);
        int l = pos[x], r = pos[y];
        if (l > r)swap(l, r);
        ++l;
        return ask(l, r);
    }

    int query(int l1, int r1, int l2, int r2) {
        return min({query(l1, l2), r1 - l1 + 1, r2 - l2 + 1});
    }
};

using blocks = vector<array<int, 2>>;

struct query {
    blocks start;
    blocks end;
    int id;
};

int cmp(const blocks &lhs, const blocks &rhs, string &s, LCP &lcp) {
    int i = 0, j = 0;
    int x = 0, y = 0;
    while (i < lhs.size() && j < rhs.size()) {
        int mn = min(lhs[i][1] - lhs[i][0] + 1 - x, rhs[j][1] - rhs[j][0] + 1 - y);
        int lp = lcp.query(lhs[i][0] + x, lhs[i][1], rhs[j][0] + y, rhs[j][1]);
        x += lp, y += lp;
        if (lp == mn) {
            if (x == lhs[i][1] - lhs[i][0] + 1)++i, x = 0;
            if (y == rhs[j][1] - rhs[j][0] + 1)++j, y = 0;
            continue;
        }
        return s[lhs[i][0] + x] < s[rhs[j][0] + y] ? -1 : 1;
    }
    if (i == lhs.size() && j == rhs.size())return 0;
    if (i == lhs.size())return -1;
    return 1;
}

string s, sr;
LCP l, lr;
vector<int> what;

struct cmpf {
    bool operator()(const pair<blocks, int> &lhs, const pair<blocks, int> &rhs) const {
        int it = cmp(lhs.first, rhs.first, s, l);
        if (it == -1)return true;
        if (it == 1)return false;
        if ((what[lhs.second] == -1) == (what[rhs.second] == -1)) {
            return lhs.second < rhs.second;
        }
        if (~what[lhs.second])return true;
        return false;
    }
};

struct cmpr {
    bool operator()(const pair<blocks, int> &lhs, const pair<blocks, int> &rhs) const {
        int it = cmp(lhs.first, rhs.first, sr, lr);
        if (it == -1)return true;
        if (it == 1)return false;
        if ((what[lhs.second] == -1) == (what[rhs.second] == -1)) {
            return lhs.second < rhs.second;
        }
        if (~what[lhs.second])return true;
        return false;
    }
};

struct Fenwick {
    int n;
    vector<int> f;

    Fenwick(int n) : n(n), f(n) {}

    void upd(int i, int x) {
        for (; i < n; i |= i + 1)f[i] += x;
    }

    int get(int i) {
        int res = 0;
        for (; i >= 0; i &= i + 1, --i)res += f[i];
        return res;
    }

    int sum(int l, int r) {
        return get(r) - get(l - 1);
    }
};

int main() {
    cin.tie(0)->sync_with_stdio(false);
    int n, q;
    cin >> n >> q;
    what.resize(q, -1);
    ++n;
    cin >> s;
    s += (char) 120;
    sr = s;
    reverse(sr.begin(), sr.end());
    l = LCP(s), lr = LCP(sr);
    vector<blocks> a;
    vector<query> plus, minus;
    int now = 0;
    for (int i = 0; i < q; ++i) {
        char c;
        cin >> c;
        if (c == '+') {
            int k;
            cin >> k;
            blocks v(k);
            for (auto &[x, y]: v)cin >> x >> y, --x, --y;
            a.push_back(v);
            plus.push_back({v, {}, i});
        } else if (c == '-') {
            int who;
            cin >> who;
            --who;
            auto v = a[who];
            a.emplace_back();
            minus.push_back({v, {}, i});
        } else {
            int k;
            cin >> k;
            blocks start(k);
            for (auto &[x, y]: start)cin >> x >> y, --x, --y;
            int m;
            cin >> m;
            blocks end(m);
            for (auto &[x, y]: end)cin >> x >> y, --x, --y;
            a.emplace_back();
            plus.push_back({start, end, i});
            minus.push_back({start, end, i});
            what[i] = now++;
        }
    }
    auto solve = [&](const vector<query> &v) {
        vector<int> res(now);
        if(v.empty())return res;
        vector<array<int, 2>> fi(now, {INF, -INF}), se(now, {INF, -INF});
        vector<int> pos(q), posr(q);
        {
            vector<pair<blocks, int>> z;
            for (auto [s, _, id]: v) {
                z.push_back({s, id});
                if (~what[id]) {
                    s.push_back({n - 1, n - 1});
                    z.push_back({s, id});
                }
            }
            sort(z.begin(), z.end(), [&](const auto &x, const auto &y) {
                return x.first.size() < y.first.size();
            });
            set<pair<blocks, int>, cmpf> s;
            for (auto &v: z)s.insert(v);
            int ord = 0;
            for (auto &[_, it]: s) {
                if (~what[it]) {
                    fi[what[it]][0] = min(fi[what[it]][0], ord);
                    fi[what[it]][1] = max(fi[what[it]][1], ord);
                }
                pos[it] = ord;
                ++ord;
            }
        }
        {
            vector<pair<blocks, int>> z;
            for (auto [s, e, id]: v) {
                for (auto &[l, r]: s) {
                    l = n - l - 1;
                    r = n - r - 1;
                    swap(l, r);
                }
                for (auto &[l, r]: e) {
                    l = n - l - 1;
                    r = n - r - 1;
                    swap(l, r);
                }
                reverse(s.begin(), s.end());
                reverse(e.begin(), e.end());
                if (~what[id]) {
                    z.push_back({e, id});
                    e.push_back({0,0});
                    z.push_back({e, id});
                } else {
                    z.push_back({s, id});
                }
            }
            sort(z.begin(), z.end(), [&](const auto &x, const auto &y) {
                return x.first.size() < y.first.size();
            });
            set<pair<blocks, int>, cmpr> s;
            for (auto &v: z)s.insert(v);
            int ord = 0;
            for (auto &[_, it]: s) {
                if (~what[it]) {
                    se[what[it]][0] = min(se[what[it]][0], ord);
                    se[what[it]][1] = max(se[what[it]][1], ord);
                }
                posr[it] = ord;
                ++ord;
            }
        }
        vector<int> o(2 * q);
        for (auto &[_, __, id]: v) {
            o[pos[id]] = posr[id];
        }
        auto rec = [&](auto &&rec, int l, int r) -> void {
            if (l + 1 == r)return;
            int m = (r + l) / 2;
            rec(rec, l, m);
            vector<int> all, allr;
            for (int i = l; i < m; ++i) {
                auto &[_, __, id] = v[i];
                if (!~what[id]) {
                    all.push_back(pos[id]);
                    allr.push_back(posr[id]);
                }
            }
            sort(all.begin(), all.end());
            sort(allr.begin(), allr.end());
            int k = all.size();
            vector<vector<array<int, 4>>> Q(k);
            for (int i = m; i < r; ++i) {
                auto &[_, __, id] = v[i];
                if (~what[id]) {
                    int l1 = lower_bound(all.begin(), all.end(), fi[what[id]][0]) - all.begin();
                    int r1 = upper_bound(all.begin(), all.end(), fi[what[id]][1]) - all.begin() - 1;
                    int l2 = lower_bound(allr.begin(), allr.end(), se[what[id]][0]) - allr.begin();
                    int r2 = upper_bound(allr.begin(), allr.end(), se[what[id]][1]) - allr.begin() - 1;
                    if (l1 > r1 || l2 > r2)continue;
                    Q[r1].push_back({l2, r2, what[id], 1});
                    if (--l1 >= 0)Q[l1].push_back({l2, r2, what[id], -1});
                }
            }
            Fenwick fw(k);
            for (int i = 0; i < k; ++i) {
                int it = lower_bound(allr.begin(), allr.end(), o[all[i]]) - allr.begin();
                fw.upd(it, 1);
                for (auto &[lq, rq, id, sgn]: Q[i]) {
                    res[id] += sgn * fw.sum(lq, rq);
                }
            }
            rec(rec, m, r);
        };
        rec(rec, 0, v.size());
        return res;
    };
    auto ra = solve(plus);
    auto rm = solve(minus);
    for (int i = 0; i < now; ++i) {
        cout << ra[i] - rm[i] << "\n";
    }
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3868kb

input:

8 7
abcaabbc
+ 3 1 3 2 4 3 8
+ 2 1 4 1 8
+ 1 2 4
? 1 5 6 1 7 8
- 3
+ 1 2 5
? 1 2 3 1 5 5

output:

2
1

result:

ok 2 lines

Test #2:

score: 0
Accepted
time: 7ms
memory: 4484kb

input:

5 2000
bbaab
+ 1 3 5
+ 2 5 5 3 5
- 2
? 1 1 3 3 3 3 4 5 2 5
- 1
? 3 1 1 2 4 1 5 1 3 4
? 1 1 2 2 2 4 4 4
? 1 1 5 1 5 5
+ 3 1 2 1 5 1 4
? 2 1 5 1 3 2 1 2 5 5
? 1 3 4 1 4 5
- 9
? 1 1 4 1 2 3
+ 2 1 5 1 2
+ 1 1 4
- 15
- 14
? 2 2 5 2 5 1 3 4
+ 1 2 3
- 19
+ 3 1 4 1 5 4 5
- 21
+ 1 2 5
? 3 1 5 5 5 1 5 1 3 5
?...

output:

0
0
0
0
0
0
0
0
0
1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
0
0
0
0
0
0
0
1
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
1
0
0
0
0
0
0
0
1
0
0
0
0
0
0
0
1
0
0
0
4
0
3
0
0
0
1
2
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
4
0
0
0
0
0
0
0
0
2
0
8
0
0
0
0
0
0
0
2
0
0
...

result:

ok 33212 lines

Test #6:

score: 0
Accepted
time: 1422ms
memory: 64152kb

input:

100000 100000
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa...

output:

0
1
0
1
0
1
0
5
0
4
1
1
1
1
2
0
3
0
0
0
0
1
1
0
0
2
2
0
0
1
5
1
0
0
3
3
5
2
5
0
8
2
2
2
13
2
2
0
2
4
11
9
5
3
14
4
9
19
12
4
12
11
6
7
8
2
22
7
3
20
7
9
6
0
5
5
17
2
9
9
0
2
7
10
11
0
9
3
4
5
12
6
10
0
2
21
2
9
1
3
1
2
2
10
22
8
21
4
3
16
3
8
2
12
9
0
2
12
4
5
19
16
7
5
4
4
3
8
5
11
4
6
5
13
0
6
5
1...

result:

ok 33583 lines

Test #7:

score: 0
Accepted
time: 735ms
memory: 66560kb

input:

100000 100000
baabbabaabaaaabbaaababaaabbbbbaabbababbabbbaabbaaabbbbababaababbbbbababaabaaabaaababaabbbbaaababbbbabaabbaaaaaabbbabbbabababababaabbabbbbbaaabababbbaabababbbaaababaabbaaaabbabbaabbababaabbaaaababaabbbbbababbaaabbbaababbaaaaaabbbbabbbbbbabbaabababbbaaaaaabbabbabaaaaaabbbaaaaaabaabaaabab...

output:

0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
...

result:

ok 33381 lines

Test #8:

score: 0
Accepted
time: 1673ms
memory: 66372kb

input:

100000 100000
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa...

output:

2
2
0
2
1
1
2
2
2
2
0
0
0
0
0
1
0
0
1
0
0
0
2
2
2
0
1
0
0
0
0
1
0
2
3
0
1
0
1
0
0
1
1
2
2
2
1
1
1
0
0
0
2
0
3
0
0
0
0
0
1
2
0
0
1
1
0
0
0
1
1
2
0
2
1
2
0
0
1
0
0
0
0
1
0
0
0
0
1
0
0
0
0
1
1
2
2
1
2
4
3
2
0
2
0
0
1
4
0
0
1
1
5
1
0
1
0
0
2
1
0
3
3
1
0
1
1
2
2
3
0
1
3
7
6
0
7
1
1
1
5
2
5
0
2
6
2
2
2
5
...

result:

ok 33565 lines

Test #9:

score: 0
Accepted
time: 721ms
memory: 64616kb

input:

100000 100000
aaabbbabbaababbbbbbaaababbbaaaaaabbaaaabababbabababbabbabbbaababbbbabaabaaabbaaabbabababbaaabbabbaaaaabbabababbaaaaababbbbabbabaaabbbaabaabbbaaababbbbbabaaabaaaaabbaabaabbabababbabaaabbbbbbbbaababaabbbabaabbabaaabbbbbababaaabbbbbaaaaaaabbbabbbaabbaabbaaaaaaabbbaabbbaabbaaaababbabaababb...

output:

0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
...

result:

ok 33118 lines

Test #10:

score: 0
Accepted
time: 1529ms
memory: 63960kb

input:

100000 100000
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa...

output:

0
1
0
0
0
2
0
0
0
0
0
0
0
1
0
0
1
0
0
3
0
0
0
0
1
0
0
0
0
0
0
0
0
0
0
4
0
1
0
0
0
0
2
0
3
4
4
5
8
7
9
5
0
9
3
8
2
9
0
5
7
1
7
9
0
1
4
1
5
8
5
1
0
0
5
0
4
12
0
9
5
11
10
3
1
8
1
9
2
1
0
5
5
5
0
2
5
1
1
0
0
12
8
11
11
1
4
11
10
3
7
9
9
4
12
11
5
9
6
1
2
8
10
11
4
17
11
6
3
2
4
1
1
3
1
3
2
3
6
5
4
8
12...

result:

ok 33215 lines

Test #11:

score: 0
Accepted
time: 681ms
memory: 65900kb

input:

100000 100000
mwtmtwnsgaynckkprtjhfnmyzylblnkmrismcyyksqxcikyhrsannbmflvloshydnfvydmuoyphxpjgxsfmyqozidivsigleuvmnyniccdqjekyzjtytudpjbwjmsulfipurvjuxququmkfbrigctewalryoiilmqapofcwpllcwjnzmbtirmfmyhbuqkwqhzidrqbxnulklkjmrnzzclykjoflrbimnshtruucmjiukgvzoekyjnjpkkpwcgrbidyuyodlqaaywfsnbcczuxwsbnrcprq...

output:

0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
...

result:

ok 33475 lines

Test #12:

score: 0
Accepted
time: 1297ms
memory: 62892kb

input:

100000 100000
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa...

output:

0
0
1
1
1
1
3
1
3
4
3
3
4
5
7
4
4
4
5
3
4
6
1
0
4
4
12
3
9
9
9
3
7
10
6
9
2
9
4
8
8
7
4
7
7
6
1
5
6
6
4
5
4
3
0
1
1
1
0
0
0
0
0
0
0
0
0
1
0
1
1
0
2
0
0
0
0
0
0
0
0
0
0
1
0
1
1
3
1
1
1
4
4
1
0
4
3
2
0
2
1
0
0
0
0
6
5
0
2
4
2
0
0
0
0
1
0
1
0
0
0
2
4
4
1
3
5
1
0
0
0
0
0
0
2
2
2
0
0
0
0
0
0
0
0
2
2
3
1
...

result:

ok 33689 lines

Test #13:

score: 0
Accepted
time: 1093ms
memory: 63892kb

input:

100000 100000
bbbbbaabbbbbaaabaabaaabbbbaabaaabaabbababbaaaaaaaabbababbbbabbababaabbabaabbaaaabbbbabaabbababbbbbbbaaabaabbabbbbbbaaaaababaaabbbabbaabaabaaabbbabbaaabaaaababbaaabaabbabaaaaaaababababbbbaabbaaaabaabbbbaaaababbabbbbabaabbbaaabbbaabaaabbbaaabaabbbbbabbaaabbaabbabbaababbbabbababbabbaabbbb...

output:

0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
...

result:

ok 33438 lines

Test #14:

score: 0
Accepted
time: 564ms
memory: 61024kb

input:

100000 100000
aaabbbbabbaababbabaabbabababaaaaabbababababaabbaaabbbaaaaaabaaabbabbabbbabaabbaabbabbbbbbbaabaaababaaaaabaaaabbbaaaabbaabbaabbbbaaababbabababbaaaaabbbababababaabaabababbabbbbbabbabbbbaaababbbbaabbaaabababaabbbaaabaaaabbabbaabbbaabbbbabbbababbbabaabbaababaaaabbaabaaabbaaabaaaaabbbbbbbab...

output:

0
0
0
0
0
0
0
2
1
4
0
0
1
1
0
0
0
2
0
0
0
8
2
0
2
0
0
0
0
0
0
7
0
0
0
0
10
5
4
4
0
1
4
0
0
2
4
4
0
0
0
6
0
4
0
0
0
7
4
7
3
5
0
0
0
7
0
7
7
0
8
7
3
0
0
11
0
0
4
11
0
2
2
0
11
9
2
11
3
2
12
3
0
13
0
0
3
0
4
5
0
0
0
4
6
0
0
6
0
4
4
0
0
0
5
5
0
0
6
0
7
0
7
8
7
0
6
6
7
7
7
6
17
6
8
7
7
3
15
0
14
6
0
0
14...

result:

ok 33321 lines

Test #15:

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

input:

5 1000
glbdh
+ 2 2 2 1 2
? 2 1 2 3 4 1 1 5
? 1 3 4 3 2 3 4 4 1 5
- 1
? 1 1 2 2 1 2 1 4
+ 1 1 3
+ 2 1 4 1 2
? 2 4 5 1 2 3 2 3 3 4 1 2
? 2 4 4 1 1 2 3 4 1 3
? 1 1 2 1 1 3
- 7
+ 1 1 5
? 1 3 3 1 1 2
? 3 3 4 4 4 2 3 1 1 2
+ 3 1 5 2 5 1 2
? 1 1 1 3 1 2 3 3 1 2
? 2 4 5 3 3 2 3 3 1 2
? 1 2 3 2 3 4 1 2
? 1 1...

output:

0
0
0
0
0
1
0
0
0
0
0
1
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
4
0
0
0
0
0
0
0
0
0
0
0
0
0
11
0
0
0
0
0
0
0
0
0
1
0
0
0
9
0
0
0
0
3
0
1
0
1
0
1
11
0
0
11
0
0
0
0
0
0
12
0
12
0
0
1
0
0
1
0
0
0
0
0
0
0
11
0
0
0
0
0
0
0
3
0
0
13
0
0
0
0
13
0
0
0
0
0
1
0
0
0
0
0
0
5
2
0
0
0
0
0
0
0
0
0
0
0
0
0
0
...

result:

ok 525 lines

Test #16:

score: 0
Accepted
time: 1294ms
memory: 75004kb

input:

100000 100000
mmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm...

output:

0
0
0
1
0
0
0
2
0
0
0
0
2
0
0
0
0
1
0
0
2
0
0
1
1
1
1
0
1
2
2
0
2
1
1
1
0
2
1
1
1
1
1
1
0
2
3
3
1
1
1
1
4
1
3
4
0
2
2
2
2
3
2
3
2
0
2
1
3
4
4
3
1
4
2
0
0
3
2
3
3
3
2
3
0
3
3
3
3
3
5
4
0
4
3
4
3
4
4
1
3
3
4
5
4
5
1
6
5
6
8
6
3
6
8
6
3
5
2
1
6
4
3
6
3
1
1
3
4
3
5
8
4
3
5
6
3
6
1
7
3
7
8
6
4
7
4
3
1
5
...

result:

ok 49940 lines

Test #17:

score: 0
Accepted
time: 878ms
memory: 60344kb

input:

100000 100000
dddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd...

output:

0
6
5
7
5
8
6
6
17
13
14
20
26
23
16
21
20
17
39
26
31
32
46
39
36
52
36
28
28
28
26
29
46
53
48
55
18
43
44
40
49
25
59
42
57
60
42
36
65
50
52
59
25
56
42
42
16
77
43
42
65
57
57
52
44
48
42
19
43
72
65
56
101
69
37
69
73
106
72
55
66
22
70
60
40
73
81
78
60
79
94
63
74
62
74
78
110
76
107
113
108...

result:

ok 9964 lines

Test #18:

score: -100
Wrong Answer
time: 1543ms
memory: 85952kb

input:

100000 100000
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx...

output:

0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
...

result:

wrong answer 3rd lines differ - expected: '1', found: '0'