結果

問題 No.2338 Range AtCoder Query
ユーザー rniyarniya
提出日時 2023-06-05 16:15:15
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 4,394 bytes
コンパイル時間 3,033 ms
コンパイル使用メモリ 210,920 KB
実行使用メモリ 11,968 KB
最終ジャッジ日時 2023-08-28 09:37:32
合計ジャッジ時間 14,485 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 AC 43 ms
7,800 KB
testcase_27 AC 39 ms
7,760 KB
testcase_28 AC 38 ms
7,808 KB
testcase_29 WA -
testcase_30 WA -
testcase_31 AC 272 ms
11,768 KB
testcase_32 AC 249 ms
11,824 KB
testcase_33 WA -
testcase_34 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#ifdef LOCAL
#include <debug.hpp>
#else
#define debug(...) void(0)
#endif

struct Mo {
    Mo(int n) : n(n) {}

    void add(int l, int r) {
        assert(l <= r);
        left.emplace_back(l);
        right.emplace_back(r);
    }

    template <typename AL, typename AR, typename DL, typename DR, typename REM>
    void run(const AL& add_left, const AR& add_right, const DL& del_left, const DR del_right, const REM& rem) {
        int q = left.size(), width = n / std::min(std::max<int>(sqrt(q * 2 / 3), 1), n);
        std::vector<int> order(q);
        std::iota(order.begin(), order.end(), 0);
        std::sort(order.begin(), order.end(), [&](int a, int b) {
            int ablock = left[a] / width, bblock = left[b] / width;
            if (ablock != bblock) return ablock < bblock;
            return (ablock & 1) ? (right[a] > right[b]) : (right[a] < right[b]);
        });

        int l = 0, r = 0;
        for (auto idx : order) {
            while (l > left[idx]) add_left(--l);
            while (r < right[idx]) add_right(r++);
            while (l < left[idx]) del_left(l++);
            while (r > right[idx]) del_right(--r);
            rem(idx);
        }
    }

    template <typename A, typename D, typename REM> void run(const A& add, const D& del, const REM& rem) {
        run(add, add, del, del, rem);
    }

private:
    int n;
    std::vector<int> left, right;
};

using namespace std;

typedef long long ll;
#define all(x) begin(x), end(x)
constexpr int INF = (1 << 30) - 1;
constexpr long long IINF = (1LL << 60) - 1;
constexpr int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};

template <class T> istream& operator>>(istream& is, vector<T>& v) {
    for (auto& x : v) is >> x;
    return is;
}

template <class T> ostream& operator<<(ostream& os, const vector<T>& v) {
    auto sep = "";
    for (const auto& x : v) os << exchange(sep, " ") << x;
    return os;
}

template <class T, class U = T> bool chmin(T& x, U&& y) { return y < x and (x = forward<U>(y), true); }

template <class T, class U = T> bool chmax(T& x, U&& y) { return x < y and (x = forward<U>(y), true); }

template <class T> void mkuni(vector<T>& v) {
    sort(begin(v), end(v));
    v.erase(unique(begin(v), end(v)), end(v));
}

template <class T> int lwb(const vector<T>& v, const T& x) { return lower_bound(begin(v), end(v), x) - begin(v); }

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int N, M, Q;
    cin >> N >> M >> Q;
    vector<int> P(N), S(N);
    for (int i = 0; i < N; i++) {
        string tmp;
        cin >> P[i] >> tmp;
        P[i]--;
        S[i] = (tmp == "AC");
    }
    Mo mo(N);
    for (int i = 0; i < Q; i++) {
        int L, R;
        cin >> L >> R;
        mo.add(--L, R);
    }

    vector<int> cnt(M, 0), nxt(N, 0);
    for (int i = N - 1; i >= 0; i--) {
        if (S[i] == 0)
            cnt[P[i]]++;
        else {
            nxt[i] = cnt[P[i]];
            cnt[P[i]] = 0;
        }
    }
    vector<pair<int, int>> ans(Q);
    int AC = 0, penalty = 0;
    vector<int> ac(M, 0), wa(M, 0);
    auto add_left = [&](int idx) {
        int p = P[idx];
        if (S[idx] == 0) {
            if (ac[p]) penalty++;
            wa[p]++;
        } else {
            if (ac[p] == 0)
                AC++;
            else
                penalty -= wa[p];
            ac[p]++;
        }
    };
    auto add_right = [&](int idx) {
        int p = P[idx];
        if (S[idx] == 0) {
            wa[p]++;
        } else {
            if (ac[p] == 0) {
                AC++;
                penalty += wa[p];
            }
            ac[p]++;
        }
    };
    auto del_left = [&](int idx) {
        int p = P[idx];
        if (S[idx] == 0) {
            if (ac[p]) penalty--;
            wa[p]--;
        } else {
            ac[p]--;
            if (ac[p] == 0)
                AC--;
            else
                penalty += nxt[idx];
        }
    };
    auto del_right = [&](int idx) {
        int p = P[idx];
        if (S[idx] == 0) {
            wa[p]--;
        } else {
            ac[p]--;
            if (ac[p] == 0) {
                AC--;
                penalty -= wa[p];
            }
        }
    };
    auto rem = [&](int idx) { ans[idx] = {AC, penalty}; };
    mo.run(add_left, add_right, del_left, del_right, rem);

    for (auto [x, y] : ans) cout << x << ' ' << y << '\n';
    return 0;
}
0