結果

問題 No.2395 区間二次変換一点取得
ユーザー Carpenters-CatCarpenters-Cat
提出日時 2023-07-29 00:45:38
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 273 ms / 2,000 ms
コード長 770 bytes
コンパイル時間 2,300 ms
コンパイル使用メモリ 195,140 KB
実行使用メモリ 6,656 KB
最終ジャッジ日時 2024-04-16 08:36:15
合計ジャッジ時間 6,081 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 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 2 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 26 ms
5,376 KB
testcase_13 AC 260 ms
6,656 KB
testcase_14 AC 273 ms
6,656 KB
testcase_15 AC 264 ms
6,656 KB
testcase_16 AC 264 ms
6,272 KB
testcase_17 AC 262 ms
6,400 KB
testcase_18 AC 240 ms
6,272 KB
testcase_19 AC 244 ms
6,656 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int bbb[200020];
int si;
void init(int N) {
	si = N;
	fill(bbb, bbb + (N + 1), 0);
}
void add(int id, int a) {
	id ++;
	while (id <= si) {
		bbb[id] += a;
		id += (id & (-id));
	}
}
int sum(int id) {
	int ret = 0;
	while (id) {
		ret += bbb[id];
		id -= (id & (-id));
	}
	return ret;
}
int main() {
	int N, Q; ll B;
	cin >> N >> B >> Q;
	init(N);
	ll X[200020], Y[200020], Z[200020];
	X[0] = Y[0] = Z[0] = 1;
	for (int i = 0; i < Q; i ++) {
		X[i + 1] = (X[i] + 1) % B;
		Y[i + 1] = (3 * Y[i] + 2 * X[i + 1] * Z[i]) % B;
		Z[i + 1] = (3 * Z[i]) % B;
	}
	while (Q--) {
		int l, m, r;
		cin >> l >> m >> r;
		add(--l, 1); add(r, -1);
		int x = sum(m);
		printf("%lld %lld %lld\n", X[x], Y[x], Z[x]);
	}
}
0