QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#612016#9425. Generated Stringucup-team4435WA 5ms4008kbC++2023.6kb2024-10-05 02:07:342024-10-05 02:07:35

Judging History

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

  • [2024-10-14 17:49:05]
  • hack成功,自动添加数据
  • (/hack/995)
  • [2024-10-05 02:07:35]
  • 评测
  • 测评结果:WA
  • 用时:5ms
  • 内存:4008kb
  • [2024-10-05 02:07:34]
  • 提交

answer

#pragma GCC optimize("Ofast")

#include "bits/stdc++.h"

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep1(i, n) for (int i = 1; i < (n); ++i)
#define rep1n(i, n) for (int i = 1; i <= (n); ++i)
#define repr(i, n) for (int i = (n) - 1; i >= 0; --i)
#define pb push_back
#define eb emplace_back
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define each(x, a) for (auto &x : a)
#define ar array
#define vec vector
#define range(i, n) rep(i, n)

using namespace std;

using ll = long long;
using ull = unsigned long long;
using ld = long double;
using str = string;
using pi = pair<int, int>;
using pl = pair<ll, ll>;

using vi = vector<int>;
using vl = vector<ll>;
using vpi = vector<pair<int, int>>;
using vvi = vector<vi>;

int Bit(int mask, int b) { return (mask >> b) & 1; }

template<class T>
bool ckmin(T &a, const T &b) {
    if (b < a) {
        a = b;
        return true;
    }
    return false;
}

template<class T>
bool ckmax(T &a, const T &b) {
    if (b > a) {
        a = b;
        return true;
    }
    return false;
}

// [l, r)
template<typename T, typename F>
T FindFirstTrue(T l, T r, const F &predicat) {
    --l;
    while (r - l > 1) {
        T mid = l + (r - l) / 2;
        if (predicat(mid)) {
            r = mid;
        } else {
            l = mid;
        }
    }
    return r;
}


template<typename T, typename F>
T FindLastFalse(T l, T r, const F &predicat) {
    return FindFirstTrue(l, r, predicat) - 1;
}


// faster implementation
// source: https://judge.yosupo.jp/submission/42086
void SA_IS(const int *s, int *SA, int n, int K) {
    // s 为字符串数组[0..n-1] 必须保证 s[n-1]=0 且为最小值
    // SA 为存储后缀数组[0..n-1]
    // n 为字符串长度
    // K 为值域

    bool *t = new bool[n]; // 类型数组
    int *bkt = new int[K]; // 桶
    int *bkt_l = new int[K];
    int *bkt_r = new int[K];
    int n1 = 0; // LMS-后缀的数量
    int *p1;    //按出现顺序存储所有 LMS-后缀的索引

#define is_S_type(x) (t[x])
#define is_L_type(x) (!t[x])
#define is_LMS_type(x) (is_S_type(x) && x != 0 && is_L_type(x - 1))

    // 预处理每一个后缀的类型
    t[n - 1] = true; // 0 为 S-型后缀且为 LMS-型后缀
    for (int i = n - 2; i >= 0; --i) {
        t[i] = (s[i] < s[i + 1] || (is_S_type(i + 1) && s[i] == s[i + 1]));
        n1 += is_LMS_type(i + 1); // s[0] 必然不是 LMS-型后缀,不会影响
    }

    // 预处理桶的边界
    for (int i = 0; i != K; ++i) bkt[i] = 0;
    for (int i = 0; i != n; ++i) ++bkt[s[i]];
    for (int i = 0, sum = 0; i != K; ++i) sum += bkt[i], bkt_r[i] = sum, bkt_l[i] = sum - bkt[i];

#define indecud_sort()                                                                             \
  do {                                                                                             \
    for (int i = 0; i != K; ++i) bkt[i] = bkt_l[i];                                                \
    for (int i = 0, j; i != n; ++i)                                                                \
      if ((j = SA[i] - 1) >= 0 && is_L_type(j)) SA[bkt[s[j]]++] = j;                               \
    for (int i = 0; i != K; ++i) bkt[i] = bkt_r[i];                                                \
    for (int i = n - 1, j; i >= 0; --i)                                                            \
      if ((j = SA[i] - 1) >= 0 && is_S_type(j)) SA[--bkt[s[j]]] = j;                               \
  } while (0)

    // 将所有 LMS-后缀放入 SA 对应桶的末尾并诱导排序
    p1 = new int[n1];
    for (int i = 0, j = 0; i != n; ++i) {
        SA[i] = -1;
        if (is_LMS_type(i)) p1[j++] = i;
    }
    for (int i = 0; i != K; ++i) bkt[i] = bkt_r[i];
    for (int i = n1 - 1; i >= 0; --i) SA[--bkt[s[p1[i]]]] = p1[i];
    indecud_sort();

    int *s1 = new int[n1];  // 新的字符串
    int *SA1 = new int[n1]; // 存储新的字符串排的后缀数组
    for (int i = 0, j = 0; i != n; ++i)
        if (is_LMS_type(SA[i])) SA1[j++] = SA[i]; // 存储 LMS-子串的相对顺序
    int name = 0;
    // 对所有 LMS-子串命名
    for (int i = 0, prev = -1; i != n1; ++i) {
        int pos = SA1[i];
        for (int j = 0;; ++j) // 无需设置范围,因为 s[n-1]=0 为最小值且不会出现在其余位置
            if (prev == -1 || s[pos + j] != s[prev + j] || is_S_type(pos + j) != is_S_type(prev + j)) {
                prev = pos, ++name;
                break;
            } else if (j != 0 && (is_LMS_type(pos + j) || is_LMS_type(prev + j))) // 到末尾了停止比较
                break;
        SA[pos] = name - 1; // 利用 SA 暂时存储新字符串的 name
    }
    for (int i = 0; i != n1; ++i) s1[i] = SA[p1[i]];

    if (name != n1)
        SA_IS(s1, SA1, n1, name);
    else
        for (int i = 0; i != n1; ++i) SA1[s1[i]] = i;

    for (int i = 0; i != K; ++i) bkt[i] = bkt_r[i];
    for (int i = 0; i != n; ++i) SA[i] = -1;
    for (int i = n1 - 1; i >= 0; --i) SA[--bkt[s[p1[SA1[i]]]]] = p1[SA1[i]];
    indecud_sort();

    delete[] SA1;
    delete[] s1;
    delete[] p1;
    delete[] bkt_r;
    delete[] bkt_l;
    delete[] bkt;
    delete[] t;

#undef is_S_type
#undef is_L_type
#undef is_LMS_type
#undef indecud_sort
}


const ll INF = 2e18;
const int INFi = 1e9;
const int N = 2e5 + 50;
const int LG = 20;

template<typename T, typename merge_t>
struct sparse_table {
    std::vector<std::vector<T>> sparse;
    const merge_t merge;

    sparse_table(const merge_t &merge) : merge(merge) {}

    sparse_table(const std::vector<T> &a, const merge_t &merge) : merge(merge) {
        if (a.empty())
            return;

        const int n = int(a.size()), lg = std::__lg(n);
        sparse.reserve(lg + 1);
        sparse.push_back(a);

        for (int level = 1; level <= lg; level++) {
            sparse.push_back(std::vector<T>(n - (1 << level) + 1));
            for (int i = 0; i < int(sparse[level].size()); i++)
                sparse[level][i] = merge(sparse[level - 1][i], sparse[level - 1][i + (1 << (level - 1))]);
        }
    }

    sparse_table &operator=(const sparse_table<T, merge_t> &another) {
        sparse = another.sparse;
        return *this;
    }

    T query(int l, int r) const {
        assert(l < r);
        const int level = std::__lg(r - l);
        return merge(sparse[level][l], sparse[level][r - (1 << level)]);
    }
};


std::vector<int> get_sa(const std::string &s) {
    int len = s.size();
    std::vector<int> SA(len + 1), s_cpy(len + 1);
    for (int i = 0; i != len; ++i) s_cpy[i] = s[i];
    s_cpy.back() = 0;
    SA_IS(s_cpy.data(), SA.data(), len + 1, 128);
    return std::vector<int>(SA.begin() + 1, SA.end());
}

auto min_merge = [](int x, int y) {
    return min(x, y);
};

struct suffix_array {
    std::vector<int> order, suffix_position, lcp;
    string s;

    sparse_table<int, decltype(min_merge)> sp;

    suffix_array() : sp(min_merge) {
    }

    void build(std::string str) {
        order.clear();
        suffix_position.clear();
        lcp.clear();
        s.clear();

        s = str;
        int n = str.size() + 1;
        order = get_sa(str);
        order.insert(order.begin(), n - 1);

        suffix_position.resize(n);
        for (int i = 0; i < n; i++) {
            suffix_position[order[i]] = i;
        }

        lcp.resize(n);
        int current_lcp = 0;
        for (int suffix = 0; suffix < n - 1; suffix++, current_lcp = current_lcp == 0 ? 0 : current_lcp - 1) {
            int previous_suffix = order[suffix_position[suffix] - 1];
            while (str[suffix + current_lcp] == str[previous_suffix + current_lcp])
                current_lcp++;

            lcp[suffix_position[suffix]] = current_lcp;
        }

        sp = sparse_table<int, decltype(min_merge)>(lcp, min_merge);
    }

    int LCP(int l, int r) {
        if (l == r) return (int) suffix_position.size() - 1 - l;
        l = suffix_position[l];
        r = suffix_position[r];
        if (l > r) swap(l, r);
        return sp.query(l + 1, r + 1);
    }

    char Get(int pos) {
        return s[pos];
    }
} S;

namespace rect_solve {
    template<typename Val = long long>
    struct binary_indexed_tree{
        int M, H;
        std::vector<Val> sum;
        binary_indexed_tree(){}
        binary_indexed_tree(int N): M(N), H(31 - __builtin_clz(M)), sum(M + 1 , 0){assert(N > 0);}
        binary_indexed_tree(const std::vector<Val> &v): M(v.size()), H(31 - __builtin_clz(M)), sum(1){
            assert(v.size() > 0);
            sum.insert(sum.begin() + 1, v.begin(), v.end());
            for(int i = 1; i <= v.size();i++){
                int nxt = i + (i & (-i));
                if(nxt <= M) sum[nxt] += sum[i];
            }
        }
        void update(int k, Val x){
            for(int i = k + 1; i <= M; i += (i & (-i))) sum[i] += x;
        }
        Val query(int r){
            Val ret = 0;
            for(int k = r; k > 0; k -= (k & (-k))) ret += sum[k];
            return ret;
        }
        Val query(int l, int r){
            return query(r) - query(l);
        }
        // sum[0, k]がx以上になるような最小のkとsum[0, k], 無い場合は{M, 総和}
        // sumが単調非減少であることが必要
        using p = std::pair<int, Val>;
        p lower_bound(Val x){
            int v = 1 << H, h = H;
            Val s = 0, t = 0;
            while(h--){
                if(M < v) v -= 1 << h;
                else if(x <= s + sum[v]) t = s + sum[v], v -= 1 << h;
                else s += sum[v], v += 1 << h;
            }
            if(v == M + 1) return {M, s};
            return (x <= s + sum[v] ? p{v - 1, s + sum[v]} : p{v, t});
        }
    };
//#line 3 ".lib/minior/map_sum_cache.hpp"
//#include <limits>
//#line 5 ".lib/minior/map_sum_cache.hpp"

    template<typename Key, typename Val>
    struct map_sum_cache{
        static constexpr Key inf = std::numeric_limits<Key>::max();
        static constexpr Val inf_val = std::numeric_limits<Val>::max();
        static constexpr int limit_size_per_node = 16;
    private:
        struct node{
            int h, sz, sz_sum;
            std::array<Key, limit_size_per_node> keys;
            std::array<Val, limit_size_per_node> vals;
            Val sum, sumsub;
            node *l, *r;
            node(): h(1), l(nullptr), r(nullptr), sum(0){}
            node(Key _key, Val _val): h(1), sz(1), sz_sum(1), l(nullptr), r(nullptr){keys[0] = _key; vals[0] = sum = sumsub = _val;}
            node(const std::vector<std::pair<Key, Val>> &v, int l, int r): h(1), sz(r - l), sz_sum(sz), sum(0), l(nullptr), r(nullptr){
                assert(sz < limit_size_per_node);
                for(int i = 0; i < sz; i++){
                    keys[i] = v[l + i].first;
                    vals[i] = v[l + i].second;
                    sum += vals[i];
                }
                sumsub = sum;
            }
            int balanace_factor(){
                return (l ? l->h : 0) - (r ? r->h : 0);
            }
            node *split_half(){
                assert(sz == limit_size_per_node);
                node *u = new node();
                sz = limit_size_per_node / 2;
                u->sz_sum = u->sz = limit_size_per_node - sz;
                for(int i = 0; i < u->sz; i++){
                    u->keys[i] = keys[sz + i];
                    u->vals[i] = vals[sz + i];
                    u->sum += u->vals[i];
                }
                u->sumsub = u->sum;
                sum -= u->sum;
                return u;
            }
        };
        node *root;
        int size(node *v){return v ? v->sz_sum : 0;}
        void update(node *v){
            v->h = std::max(v->l ? v->l->h : 0,  v->r ? v->r->h : 0) + 1;
            v->sz_sum = (v->l ? v->l->sz_sum : 0) + (v->r ? v->r->sz_sum : 0) + v->sz;
            v->sumsub = (v->l ? v->l->sumsub : 0) + (v->r ? v->r->sumsub : 0) + v->sum;
        }
        node *rotate_right(node *v){
            node *l = v->l;
            v->l = l->r;
            l->r = v;
            update(v);
            update(l);
            return l;
        }
        node *rotate_left(node *v){
            node *r = v->r;
            v->r = r->l;
            r->l = v;
            update(v);
            update(r);
            return r;
        }
        node *balance(node *v){
            int bf = v->balanace_factor();
            assert(-2 <= bf && bf <= 2);
            if(bf == 2){
                if(v->l->balanace_factor() == -1){
                    v->l = rotate_left(v->l);
                    update(v);
                }
                return rotate_right(v);
            }else if(bf == -2){
                if(v->r->balanace_factor() == 1){
                    v->r = rotate_right(v->r);
                    update(v);
                }
                return rotate_left(v);
            }
            return v;
        }
        node *build(const std::vector<node*> &nodes, int l, int r){
            int m = (l + r) >> 1;
            node *v = nodes[m];
            if(m > l) v->l = build(nodes, l, m);
            if(r > m + 1) v->r = build(nodes, m + 1, r);
            update(v);
            return v;
        }
        node *insert_leftmost(node *v, node *u){
            if(!v) return u;
            v->l = insert_leftmost(v->l, u);
            update(v);
            return balance(v);
        }
        node *emplace_inner(node *v, Key k, Val val, bool replace = false){
            if(!v) return new node(k, val);
            if(v->l && k < v->keys[0]){
                v->l = emplace_inner(v->l, k, val, replace);
            }else if(v->r && v->keys[v->sz - 1] < k){
                v->r = emplace_inner(v->r, k, val, replace);
            }else{
                int idx = std::lower_bound(v->keys.begin(), v->keys.begin() + v->sz, k) - v->keys.begin();
                if(idx < v->sz && v->keys[idx] == k){
                    v->vals[idx] += val;
                    v->sum += val;
                    v->sumsub += val;
                    return v;
                }
                for(int i = v->sz; i > idx; i--){
                    v->keys[i] = v->keys[i - 1];
                    v->vals[i] = v->vals[i - 1];
                }
                v->keys[idx] = k;
                v->vals[idx] = val;
                v->sum += val;
                v->sz++;
                if(v->sz == limit_size_per_node){
                    v->r = insert_leftmost(v->r, v->split_half());
                }
            }
            update(v);
            return balance(v);
        }
        Val query_inner(node *v, Key k){
            Val ret = 0;
            while(v){
                if(k < v->keys[0]){
                    v = v->l;
                }else if(k > v->keys[v->sz - 1]){
                    ret += (v->l ? v->l->sumsub : 0) + v->sum;
                    v = v->r;
                }else{
                    ret += (v->l ? v->l->sumsub : 0);
                    for(int i = 0; i < v->sz; i++){
                        if(v->keys[i] >= k) return ret;
                        ret += v->vals[i];
                    }
                }
            }
            return ret;
        }
    public:
        map_sum_cache(): root(nullptr){}
        map_sum_cache(std::vector<std::pair<Key, Val>> v){
            std::sort(v.begin(), v.end());
            init_sorted(v);
        }
        // すでにソート済みかつキーがユニーク
        void init_sorted(const std::vector<std::pair<Key, Val>> &v){
            if(v.empty()){
                root = nullptr;
                return;
            }
            int n = v.size();
            int size_per_node = limit_size_per_node / 2;
            int m = (n + size_per_node - 1) / size_per_node;
            std::vector<node*> nodes(m);
            for(int i = 0; i < m; i++){
                nodes[i] = new node(v, i * size_per_node, std::min((i + 1) * size_per_node, n));
            }
            root = build(nodes, 0, m);
        }
        int size(){
            return size(root);
        }
        void update(Key key, Val val){
            root = emplace_inner(root, key, val);
        }
        Val query(Key l, Key r){
            return query_inner(root, r) - query_inner(root, l);
        }
    };
//#line 8 ".lib/data_structure/range_query/point_add_rectangle_sum.hpp"

    template<typename Idx, typename Val>
    struct offline_point_add_rectangle_sum{
    private:
        struct query_type{
            int id;
            Idx lx, rx, ly, ry;
            Val z;
            query_type(int a, Idx b, Idx c, Idx d, Idx e, Val f): id(a), lx(b), rx(c), ly(d), ry(e), z(f){}
        };
        struct event_type{
            Idx x;
            int q, id;
            int lyc, ryc;
            Val z;
            event_type(Idx a, int b, int c, int d, int e, Val f): x(a), q(b), id(c), lyc(d), ryc(e), z(f){}
        };
        std::vector<query_type> q;
        std::vector<int> qcount{0};
        int qs = 0;
        void solve(int l, int r, std::vector<Val> &ans){
            if(r - l < 2) return;
            int mid = (l + r) >> 1;
            solve(l, mid, ans);
            solve(mid, r, ans);
            int left_update = (mid - l) - (qcount[mid] - qcount[l]);
            int right_query= qcount[r] - qcount[mid];
            if(left_update == 0 || right_query == 0) return;

            // compress y
            std::vector<Idx> y;
            for(int i = l; i < mid; i++) if(q[i].id == -1) y.push_back(q[i].ly);
            std::sort(y.begin(), y.end());
            y.erase(std::unique(y.begin(), y.end()), y.end());

            binary_indexed_tree<Val> bit(y.size());
            std::vector<event_type> e;
            for(int i = l; i < mid; i++){
                if(q[i].id == -1){
                    int y_idx = std::lower_bound(y.begin(), y.end(), q[i].ly) - y.begin();
                    e.push_back(event_type(q[i].lx, 2, -1, y_idx, 0, q[i].z));
                }
            }
            for(int i = mid; i < r; i++){
                if(q[i].id != -1){
                    int ly_idx = std::lower_bound(y.begin(), y.end(), q[i].ly) - y.begin();
                    int ry_idx = std::lower_bound(y.begin(), y.end(), q[i].ry) - y.begin();
                    e.push_back(event_type(q[i].lx, 0, q[i].id, ly_idx, ry_idx, 0));
                    e.push_back(event_type(q[i].rx, 1, q[i].id, ly_idx, ry_idx, 0));
                }
            }
            std::sort(e.begin(), e.end(), [](event_type &a, event_type &b){
                if(a.x != b.x) return a.x < b.x;
                return a.q < b.q;
            });
            for(event_type &ei : e){
                if(ei.q == 0){
                    ans[ei.id] -= bit.query(ei.lyc, ei.ryc);
                }else if(ei.q == 1){
                    ans[ei.id] += bit.query(ei.lyc, ei.ryc);
                }else{
                    bit.update(ei.lyc, ei.z);
                }
            }
        }
    public:
        offline_point_add_rectangle_sum(){}
        void update(Idx x, Idx y, Val z){
            q.push_back(query_type(-1, x, 0, y, 0, z));
            qcount.push_back(0);
        }
        void query(Idx lx, Idx rx, Idx ly, Idx ry){
            q.push_back(query_type(qs++, lx, rx, ly, ry, 0));
            qcount.push_back(1);
        }
        std::vector<Val> solve(){
            std::vector<Val> ret(qs, 0);
            for(int i = 1; i < qcount.size(); i++) qcount[i] += qcount[i - 1];
            solve(0, q.size(), ret);
            return ret;
        }
    };
}

struct Element {
    vpi a;
    int idx;
    int priority;

    void read() {
        int k;
        cin >> k;
        a.resize(k);
        for (auto &[l, r]: a) {
            cin >> l >> r;
            l--;
        }
    }
};

bool operator<(const Element &a, const Element &b) {
    int i = 0;
    int used_i = 0;
    int j = 0;
    int used_j = 0;
    while (true) {
        if (j == b.a.size() && i == a.a.size()) return a.priority < b.priority;
        if (j == b.a.size()) return b.priority > 0 ? true : false;
        if (i == a.a.size()) return a.priority > 0 ? false : true;

        int mx_i = a.a[i].second - a.a[i].first - used_i;
        int mx_j = b.a[j].second - b.a[j].first - used_j;
        int mx = min(mx_i, mx_j);
        int len = S.LCP(a.a[i].first + used_i, b.a[j].first + used_j);
        ckmin(len, mx);
        used_i += len;
        used_j += len;
        if (len < mx) return S.Get(a.a[i].first + used_i) < S.Get(b.a[j].first + used_j);
        if (mx_i == len) {
            i++;
            used_i = 0;
        }
        if (mx_j == len) {
            j++;
            used_j = 0;
        }
    }
    return false;
}

void solve() {
    int n, q;
    cin >> n >> q;
    string s;
    cin >> s;
    vector<Element> elems;
    auto Add = [&](Element e) {
        e.idx = elems.size();
        elems.push_back(e);
        return e.idx;
    };
    vector<ar<int, 5>> qs(q, {-1, -1, -1, -1, -1});
    for (auto &[tp, l1, r1, l2, r2]: qs) {
        char t;
        cin >> t;
        if (t == '+') {
            Element e;
            e.read();
            e.priority = -1;
            tp = 1;
            l1 = Add(e);
        } else if (t == '-') {
            tp = -1;
            int pos;
            cin >> pos;
            pos--;
            l1 = qs[pos][1];
        } else {
            tp = 0;

            Element e1, e2;
            e1.read();
            e2.read();
            e1.priority = -2;
            l1 = Add(e1);
            e1.priority = 2;
            r1 = Add(e1);
            e2.priority = -2;
            l2 = Add(e2);
            e2.priority = 2;
            r2 = Add(e2);
        }
    }
    vector<ar<int, 2>> pos(elems.size());

    rep(rot, 2) {
        {
            string cur = s;
            rep(i, 26) cur.push_back('a' + i);
            S.build(cur);
        }

        sort(all(elems));

        rep(i, elems.size()) pos[elems[i].idx][rot] = i;


        reverse(all(s));
        for(auto &e : elems) {
            for(auto &[l, r] : e.a) {
                r--;
                swap(l, r);
                l = n - 1 - l;
                r = n - 1 - r;
                r++;
            }
            reverse(all(e.a));
        }
    }

    rect_solve::offline_point_add_rectangle_sum<int, ll> rect1, rect2;

    for (auto &[tp, l1, r1, l2, r2]: qs) {
        if (tp == 1) {
            int i = l1;
            l1 = r1 = pos[i][0];
            l2 = r2 = pos[i][1];
//            cerr << "+ " << l1 << ' ' << l2 << endl;
            rect1.update(l1, l2, 1);
        } else if (tp == -1) {
            int i = l1;
            l1 = r1 = pos[i][0];
            l2 = r2 = pos[i][1];
//            cerr << "- " << l1 << ' ' << l2 << endl;
            rect2.update(l1, l2, 1);
        } else {
            l1 = pos[l1][0];
            r1 = pos[r1][1];
            l2 = pos[l2][0];
            r2 = pos[r2][1];
//            cerr << "? " << l1 << ' ' << r1 << ' ' << l2 << ' ' << r2 << endl;
            rect1.query(l1, r1, l2, r2);
            rect2.query(l1, r1, l2, r2);
        }
    }

    auto ans1 = rect1.solve();
    auto ans2 = rect2.solve();
    rep(i, ans1.size()) {
        cout << ans1[i] - ans2[i] << '\n';
    }
}


signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout << setprecision(12) << fixed;
    int t = 1;
//    cin >> t;
    rep(i, t) {
        solve();
    }
    return 0;
}

詳細信息

Test #1:

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

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: -100
Wrong Answer
time: 5ms
memory: 4008kb

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

result:

wrong answer 13th lines differ - expected: '1', found: '0'