結果

問題 No.2395 区間二次変換一点取得
ユーザー SSRSSSRS
提出日時 2023-07-28 21:34:50
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 276 ms / 2,000 ms
コード長 999 bytes
コンパイル時間 1,880 ms
コンパイル使用メモリ 166,404 KB
実行使用メモリ 6,144 KB
最終ジャッジ日時 2024-04-16 05:25:31
合計ジャッジ時間 5,719 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 3 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 3 ms
5,376 KB
testcase_09 AC 2 ms
5,376 KB
testcase_10 AC 2 ms
5,376 KB
testcase_11 AC 5 ms
5,376 KB
testcase_12 AC 27 ms
5,376 KB
testcase_13 AC 270 ms
6,016 KB
testcase_14 AC 275 ms
6,144 KB
testcase_15 AC 270 ms
6,016 KB
testcase_16 AC 272 ms
6,144 KB
testcase_17 AC 276 ms
6,016 KB
testcase_18 AC 250 ms
6,016 KB
testcase_19 AC 258 ms
6,144 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
struct binary_indexed_tree{
  int N;
  vector<int> BIT;
  binary_indexed_tree(int N): N(N), BIT(N + 1, 0){
  }
  int operator [](int i){
    i++;
    int ans = 0;
    while (i <= N){
      ans += BIT[i];
      i += i & -i;
    }
    return ans;
  }
  void add(int i, int x){
    while (i > 0){
      BIT[i] += x;
      i -= i & -i;
    }
  }
  void add(int L, int R, int x){
    add(L, -x);
    add(R, x);
  }
};
int main(){
  int N, B, Q;
  cin >> N >> B >> Q;
  vector<long long> dpX(Q + 1), dpY(Q + 1), dpZ(Q + 1);
  dpX[0] = 1;
  dpY[0] = 1;
  dpZ[0] = 1;
  for (int i = 0; i < Q; i++){
    dpX[i + 1] = (dpX[i] + 1) % B;
    dpY[i + 1] = (dpY[i] * 3 + 2 * dpX[i + 1] * dpZ[i]) % B;
    dpZ[i + 1] = dpZ[i] * 3 % B;
  }
  binary_indexed_tree BIT(N);
  for (int i = 0; i < Q; i++){
    int L, M, R;
    cin >> L >> M >> R;
    L--;
    M--;
    BIT.add(L, R, 1);
    int p = BIT[M];
    cout << dpX[p] << ' ' << dpY[p] << ' ' << dpZ[p] << endl;
  }
}
0