結果

問題 No.2395 区間二次変換一点取得
ユーザー hari64hari64
提出日時 2023-07-28 21:51:49
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 198 ms / 2,000 ms
コード長 2,875 bytes
コンパイル時間 2,176 ms
コンパイル使用メモリ 204,020 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-16 05:45:12
合計ジャッジ時間 5,307 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,816 KB
testcase_01 AC 2 ms
6,944 KB
testcase_02 AC 2 ms
6,944 KB
testcase_03 AC 2 ms
6,944 KB
testcase_04 AC 2 ms
6,944 KB
testcase_05 AC 2 ms
6,940 KB
testcase_06 AC 2 ms
6,940 KB
testcase_07 AC 2 ms
6,940 KB
testcase_08 AC 2 ms
6,944 KB
testcase_09 AC 2 ms
6,940 KB
testcase_10 AC 2 ms
6,944 KB
testcase_11 AC 4 ms
6,940 KB
testcase_12 AC 20 ms
6,940 KB
testcase_13 AC 194 ms
6,944 KB
testcase_14 AC 195 ms
6,944 KB
testcase_15 AC 196 ms
6,940 KB
testcase_16 AC 198 ms
6,944 KB
testcase_17 AC 195 ms
6,940 KB
testcase_18 AC 186 ms
6,940 KB
testcase_19 AC 184 ms
6,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#ifndef hari64
#include <bits/stdc++.h>
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#define debug(...)
#else
#include "util/viewer.hpp"
#define debug(...) viewer::_debug(__LINE__, #__VA_ARGS__, __VA_ARGS__)
#endif
// clang-format off
using namespace std;
using ll = long long; using ld = long double;
using pii = pair<int, int>; using pll = pair<ll, ll>;
template <typename T> using vc = vector<T>;
template <typename T> using vvc = vector<vc<T>>;
template <typename T> using vvvc = vector<vvc<T>>;
using vi = vc<int>; using vll = vc<ll>; using vpii = vc<pii>; using vpll = vc<pll>;
using vvi = vc<vi>; using vvll = vc<vll>; using vvpi = vc<vpii>; using vvpll = vc<vpll>;
constexpr int INF = 1001001001; constexpr long long INFll = 1001001001001001001;
template <class T> bool chmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }
template <class T> bool chmin(T& a, const T& b) { return a > b ? a = b, 1 : 0; }
// clang-format on

template <class T>
struct fenwick_tree {
    fenwick_tree() : _n(0) {}
    explicit fenwick_tree(int n) : _n(n), data(n) {}
    explicit fenwick_tree(vector<T>& As) : _n(As.size()), data(As) {}
    // A[idx]+=x
    void add(int idx, T x) {
        assert(0 <= idx && idx < _n);
        idx++;
        while (idx <= _n) {
            data[idx - 1] += x;
            idx += idx & -idx;
        }
    }
    // Σ_[l,r)
    T sum(int l, int r) const {
        assert(0 <= l && l <= r && r <= _n);
        return _sum(r) - _sum(l);
    }
    // Σ_[0,r)
    T sum(int r) const {
        assert(0 <= r && r <= _n);
        return _sum(r);
    }
    // A[idx] O(logN)
    T get(int idx) const {
        assert(0 <= idx && idx < _n);
        return sum(idx, idx + 1);
    }
    // debug
    vector<T> state() const {
        vector<T> ret(_n);
        for (int i = 0; i < _n; i++) ret[i] = get(i);
        return ret;
    }

    inline T operator[](int idx) const { return get(idx); }

   private:
    int _n;
    vector<T> data;
    T _sum(int r) const {
        T s = 0;
        while (r > 0) s += data[r - 1], r -= r & -r;
        return s;
    }
};

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);

    ll N, B, Q;
    cin >> N >> B >> Q;
    fenwick_tree<int> count(N + 1);
    vc<tuple<ll, ll, ll>> answers(Q + 10);
    answers[0] = {1, 1, 1};
    for (int i = 0; i < Q + 5; i++) {
        auto [x, y, z] = answers[i];
        answers[i + 1] = {
            (x + 1) % B,
            ((3 * y % B) + (2 * x * z % B) + (2 * z % B)) % B,
            (3 * z) % B,
        };
    }

    for (int i = 0; i < Q; i++) {
        ll L;
        ll M;
        ll R;
        cin >> L >> M >> R;
        count.add(L - 1, 1);
        count.add(R, -1);
        int cnt = count.sum(M);
        auto [x, y, z] = answers[cnt];
        cout << x << " " << y << " " << z << endl;
    }

    return 0;
}
0