結果

問題 No.2338 Range AtCoder Query
ユーザー hirayuu_ychirayuu_yc
提出日時 2024-05-10 17:39:24
言語 C++23(gcc13)
(gcc 13.2.0 + boost 1.83.0)
結果
TLE  
(最新)
AC  
(最初)
実行時間 -
コード長 11,778 bytes
コンパイル時間 7,949 ms
コンパイル使用メモリ 298,616 KB
実行使用メモリ 292,728 KB
最終ジャッジ日時 2024-12-20 03:58:40
合計ジャッジ時間 94,308 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
153,132 KB
testcase_01 AC 2 ms
13,636 KB
testcase_02 AC 1 ms
153,260 KB
testcase_03 AC 2 ms
13,636 KB
testcase_04 AC 2 ms
13,764 KB
testcase_05 AC 2 ms
13,644 KB
testcase_06 AC 3 ms
13,764 KB
testcase_07 AC 4 ms
153,260 KB
testcase_08 AC 3 ms
13,644 KB
testcase_09 AC 4 ms
153,260 KB
testcase_10 AC 3 ms
13,768 KB
testcase_11 AC 2,787 ms
226,644 KB
testcase_12 AC 3,694 ms
97,916 KB
testcase_13 AC 3,671 ms
228,292 KB
testcase_14 AC 3,509 ms
91,036 KB
testcase_15 TLE -
testcase_16 TLE -
testcase_17 TLE -
testcase_18 TLE -
testcase_19 TLE -
testcase_20 TLE -
testcase_21 TLE -
testcase_22 TLE -
testcase_23 TLE -
testcase_24 TLE -
testcase_25 TLE -
testcase_26 AC 217 ms
140,804 KB
testcase_27 AC 161 ms
140,892 KB
testcase_28 AC 174 ms
140,676 KB
testcase_29 TLE -
testcase_30 TLE -
testcase_31 AC 1,268 ms
146,448 KB
testcase_32 AC 1,388 ms
146,648 KB
testcase_33 AC 328 ms
146,444 KB
testcase_34 AC 326 ms
292,728 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#line 1 "Verify/verify-yuki/2338.test.cpp"
#define PROBLEM "https://yukicoder.me/problems/no/2338"
#line 2 "Misc/Mo.hpp"
#include <cmath>
#include <numeric>
#include <vector>
template <class M>
struct Mo {
    using T = typename M::T;
    int32_t backet;
    std::vector<int32_t> left, right, order;
    Mo(int32_t N, int32_t Q) {
        order.resize(Q);
        backet = std::max<int32_t>(
            1, (double)(N) / std::max<double>(1, std::sqrt(Q * 2.0 / 3)));
        std::iota(order.begin(), order.end(), 0);
    }
    void add_query(int32_t lf, int32_t ri) {
        left.emplace_back(lf);
        right.emplace_back(ri);
    }
    std::vector<T> run() {
        std::vector<T> answer(order.size());
        sort(order.begin(), order.end(), [&](int32_t a, int32_t b) {
            int32_t ab = left[a] / backet, bb = left[b] / backet;
            if (ab != bb) return ab < bb;
            if (ab & 1) return right[a] < right[b];
            return right[a] > right[b];
        });
        int32_t nl = 0, nr = 0;
        for (int32_t i : order) {
            while (nl > left[i]) {
                nl--;
                M::add_left(nl);
            }
            while (right[i] > nr) {
                M::add_right(nr);
                nr++;
            }
            while (nl < left[i]) {
                M::delete_left(nl);
                nl++;
            }
            while (right[i] < nr) {
                nr--;
                M::delete_right(nr);
            }
            answer[i] = M::rem();
        }
        return answer;
    }
};
#line 2 "Template/Template.hpp"
#include <bits/stdc++.h>
using namespace std;

#line 8 "Template/InOut.hpp"
inline void scan() {}
inline void scan(int &a) { std::cin >> a; }
inline void scan(unsigned &a) { std::cin >> a; }
inline void scan(long &a) { std::cin >> a; }
inline void scan(long long &a) { std::cin >> a; }
inline void scan(unsigned long long &a) { std::cin >> a; }
inline void scan(char &a) { std::cin >> a; }
inline void scan(float &a) { std::cin >> a; }
inline void scan(double &a) { std::cin >> a; }
inline void scan(long double &a) { std::cin >> a; }
inline void scan(std::vector<bool> &vec) {
    for (int32_t i = 0; i < vec.size(); i++) {
        int a;
        scan(a);
        vec[i] = a;
    }
}
inline void scan(std::string &a) { std::cin >> a; }
template <class T>
inline void scan(std::vector<T> &vec);
template <class T, size_t size>
inline void scan(std::array<T, size> &vec);
template <class T, class L>
inline void scan(std::pair<T, L> &p);
template <class T, size_t size>
inline void scan(T (&vec)[size]);
template <class T>
inline void scan(std::vector<T> &vec) {
    for (auto &i : vec) scan(i);
}
template <class T>
inline void scan(std::deque<T> &vec) {
    for (auto &i : vec) scan(i);
}
template <class T, size_t size>
inline void scan(std::array<T, size> &vec) {
    for (auto &i : vec) scan(i);
}
template <class T, class L>
inline void scan(std::pair<T, L> &p) {
    scan(p.first);
    scan(p.second);
}
template <class T, size_t size>
inline void scan(T (&vec)[size]) {
    for (auto &i : vec) scan(i);
}
template <class T>
inline void scan(T &a) {
    std::cin >> a;
}
inline void in() {}
template <class Head, class... Tail>
inline void in(Head &head, Tail &...tail) {
    scan(head);
    in(tail...);
}
inline void print() { std::cout << ' '; }
inline void print(const bool &a) { std::cout << a; }
inline void print(const int &a) { std::cout << a; }
inline void print(const unsigned &a) { std::cout << a; }
inline void print(const long &a) { std::cout << a; }
inline void print(const long long &a) { std::cout << a; }
inline void print(const unsigned long long &a) { std::cout << a; }
inline void print(const char &a) { std::cout << a; }
inline void print(const char a[]) { std::cout << a; }
inline void print(const float &a) { std::cout << a; }
inline void print(const double &a) { std::cout << a; }
inline void print(const long double &a) { std::cout << a; }
inline void print(const std::string &a) {
    for (auto &&i : a) print(i);
}
template <class T>
inline void print(const std::vector<T> &vec);
template <class T, size_t size>
inline void print(const std::array<T, size> &vec);
template <class T, class L>
inline void print(const std::pair<T, L> &p);
template <class T, size_t size>
inline void print(const T (&vec)[size]);
template <class T>
inline void print(const std::vector<T> &vec) {
    if (vec.empty()) return;
    print(vec[0]);
    for (auto i = vec.begin(); ++i != vec.end();) {
        std::cout << ' ';
        print(*i);
    }
}
template <class T>
inline void print(const std::deque<T> &vec) {
    if (vec.empty()) return;
    print(vec[0]);
    for (auto i = vec.begin(); ++i != vec.end();) {
        std::cout << ' ';
        print(*i);
    }
}
template <class T, size_t size>
inline void print(const std::array<T, size> &vec) {
    print(vec[0]);
    for (auto i = vec.begin(); ++i != vec.end();) {
        std::cout << ' ';
        print(*i);
    }
}
template <class T, class L>
inline void print(const std::pair<T, L> &p) {
    print(p.first);
    std::cout << ' ';
    print(p.second);
}
template <class T, size_t size>
inline void print(const T (&vec)[size]) {
    print(vec[0]);
    for (auto i = vec; ++i != end(vec);) {
        std::cout << ' ';
        print(*i);
    }
}
template <class T>
inline void print(const T &a) {
    std::cout << a;
}
inline void out() { std::cout << '\n'; }
template <class T>
inline void out(const T &t) {
    print(t);
    std::cout << '\n';
}
template <class Head, class... Tail>
inline void out(const Head &head, const Tail &...tail) {
    print(head);
    std::cout << ' ';
    out(tail...);
}
inline void Yes(bool i = true) { out(i ? "Yes" : "No"); }
inline void No(bool i = true) { out(i ? "No" : "Yes"); }
struct IOsetup {
    IOsetup() {
        std::ios::sync_with_stdio(false);
        std::cin.tie(nullptr);
        std::cout << std::setprecision(10);
    }
} iosetup;
#line 1 "Template/Macro.hpp"
#define _overload3(_1, _2, _3, name, ...) name
#define _overload4(_1, _2, _3, _4, name, ...) name
#define _rep1(i, n) for (ll i = 0; i < (n); i++)
#define _rep2(i, a, b) for (ll i = (a); i < (b); i++)
#define _rep3(i, a, b, c) for (ll i = (a); i < (b); i += (c))
#define rep(...) _overload4(__VA_ARGS__, _rep3, _rep2, _rep1)(__VA_ARGS__)
#define _rrep1(i, n) for (ll i = (n); i-- > 0;)
#define _rrep2(i, a, b) for (ll i = (b); i-- > (a);)
#define rrep(...) _overload3(__VA_ARGS__, _rrep2, _rrep1)(__VA_ARGS__)
#define each(i, ...) for (auto&& i : __VA_ARGS__)
#define all(i) std::begin(i), std::end(i)
#define rall(i) std::rbegin(i), std::rend(i)
#define len(x) ((int)(x).size())
#define fi first
#define se second
#define uniq(x) x.erase(unique(all(x)), std::end(x))
#define vec(type, name, ...) vector<type> name(__VA_ARGS__);
#define vv(type, name, h, ...) \
    std::vector<std::vector<type>> name(h, std::vector<type>(__VA_ARGS__));
#define INT(...)     \
    int __VA_ARGS__; \
    in(__VA_ARGS__)
#define LL(...)     \
    ll __VA_ARGS__; \
    in(__VA_ARGS__)
#define ULL(...)     \
    ull __VA_ARGS__; \
    in(__VA_ARGS__)
#define STR(...)        \
    string __VA_ARGS__; \
    in(__VA_ARGS__)
#define CHR(...)      \
    char __VA_ARGS__; \
    in(__VA_ARGS__)
#define LD(...)     \
    ld __VA_ARGS__; \
    in(__VA_ARGS__)
#define VEC(type, name, size)     \
    std::vector<type> name(size); \
    in(name)
#define VV(type, name, h, w)                                      \
    std::vector<std::vector<type>> name(h, std::vector<type>(w)); \
    in(name)
#line 8 "Template/Util.hpp"
using ll = long long;
using ld = long double;
using ull = unsigned long long;
using uint = unsigned int;
using pll = std::pair<ll, ll>;
using pii = std::pair<int, int>;
using vl = std::vector<ll>;
using vll = std::vector<ll>;
using pdd = std::pair<ld, ld>;
using tuplis = std::array<ll, 3>;
template <class T>
using pq = std::priority_queue<T, std::vector<T>, std::greater<T>>;
const ll LINF = 1LL << 60;
constexpr int INF = INT_MAX >> 1;
constexpr ll MINF = 1LL << 40;
constexpr ld DINF = std::numeric_limits<ld>::infinity();
constexpr int MODD = 1000000007;
constexpr int MOD = 998244353;
constexpr ld EPS = 1e-9;
constexpr ld PI = 3.1415926535897932;
const ll four[] = {0, 1, 0, -1, 0};
const ll eight[] = {0, 1, 1, 0, -1, -1, 1, -1, 0};
template <class T>
bool chmin(T &a, const T &b) {
    if (a > b) {
        a = b;
        return true;
    } else
        return false;
}
template <class T>
bool chmax(T &a, const T &b) {
    if (a < b) {
        a = b;
        return true;
    } else
        return false;
}
template <class T>
ll sum(const T &a) {
    return accumulate(std::begin(a), std::end(a), 0LL);
}
template <class T>
ld dsum(const T &a) {
    return accumulate(std::begin(a), std::end(a), 0.0L);
}
template <class T>
auto min(const T &a) {
    return *min_element(std::begin(a), std::end(a));
}
template <class T>
auto max(const T &a) {
    return *max_element(std::begin(a), std::end(a));
}
#line 4 "Verify/verify-yuki/2338.test.cpp"
void solve() {
    LL(N, M, Q);
    static vec(ll, P, N);
    static vec(bool, S, N, 0);
    rep(i, N) {
        string s;
        in(P[i], s);
        if (s == "AC") S[i] = 1;
        P[i]--;
    }
    static vec(ll, ac, M, 0);
    static vec(deque<ll>, sub, M);
    static ll ac_ans = 0;
    static ll pena_ans = 0;
    struct raq {
        using T = pll;
        static void add_left(int pos) {
            ll p = P[pos];
            if (S[pos]) {
                if (!ac[p])
                    ac_ans++;
                else
                    pena_ans -= sub[p].front();
                ac[p]++;
                sub[p].push_front(0);
            } else {
                if (sub[p].empty() || sub[p].front() == 0) {
                    sub[p].push_front(0);
                }
                sub[p].front()++;
                if (ac[p]) {
                    pena_ans++;
                }
            }
        }
        static void delete_left(int pos) {
            ll p = P[pos];
            if (S[pos]) {
                sub[p].pop_front();
                ac[p]--;
                if (!ac[p]) {
                    ac_ans--;
                } else {
                    pena_ans += sub[p].front();
                }
            } else {
                sub[p].front()--;
                if (ac[p]) {
                    pena_ans--;
                }
                if (sub[p].front() == 0) {
                    sub[p].pop_front();
                }
            }
        }
        static void add_right(int pos) {
            ll p = P[pos];
            if (S[pos]) {
                if (!ac[p]) {
                    ac_ans++;
                    if (!sub[p].empty()) {
                        pena_ans += sub[p].front();
                    }
                }
                sub[p].push_back(0);
                ac[p]++;
            } else {
                if (sub[p].empty() || sub[p].back() == 0) {
                    sub[p].push_back(0);
                }
                sub[p].back()++;
            }
        }
        static void delete_right(int pos) {
            ll p = P[pos];
            if (S[pos]) {
                sub[p].pop_back();
                ac[p]--;
                if (!ac[p]) {
                    ac_ans--;
                    if (!sub[p].empty()) pena_ans -= sub[p].front();
                }
            } else {
                sub[p].back()--;
                if (sub[p].back() == 0) sub[p].pop_back();
            }
        }
        static T rem() { return pll(ac_ans, pena_ans); }
    };
    Mo<raq> mo(N, Q);
    rep(i, Q) {
        LL(L, R);
        mo.add_query(L - 1, R);
    }
    vector<pll> fin_ans = mo.run();
    for (auto &[a, p] : fin_ans) {
        out(a, p);
    }
}
int main() { solve(); }
0