結果

問題 No.2395 区間二次変換一点取得
ユーザー shobonvipshobonvip
提出日時 2023-07-28 22:10:14
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 92 ms / 2,000 ms
コード長 2,595 bytes
コンパイル時間 4,907 ms
コンパイル使用メモリ 256,608 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-04-16 06:07:16
合計ジャッジ時間 7,641 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 2 ms
6,944 KB
testcase_02 AC 2 ms
6,944 KB
testcase_03 AC 2 ms
6,940 KB
testcase_04 AC 2 ms
6,948 KB
testcase_05 AC 2 ms
6,940 KB
testcase_06 AC 2 ms
6,944 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,940 KB
testcase_11 AC 3 ms
6,940 KB
testcase_12 AC 10 ms
6,944 KB
testcase_13 AC 90 ms
6,940 KB
testcase_14 AC 90 ms
6,940 KB
testcase_15 AC 92 ms
6,944 KB
testcase_16 AC 91 ms
6,944 KB
testcase_17 AC 88 ms
6,944 KB
testcase_18 AC 67 ms
6,944 KB
testcase_19 AC 67 ms
6,944 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
#include<atcoder/all>
using namespace std;
using namespace atcoder;

typedef modint mint;

typedef long long ll;

#define rep(i, s, n) for (int i = (int)(s); i < (int)(n); i++)
#define rrep(i, s, n) for (int i = (int)(n)-1; i >= (int)(s); i--)

template <typename T> bool chmin(T &a, const T &b) {
	if (a <= b) return false;
	a = b;
	return true;
}
template <typename T> bool chmax(T &a, const T &b) {
	if (a >= b) return false;
	a = b;
	return true;
}


// [ DUAL SEGMENT TREE ] BY SHOBON
// REFERENCE --- ATCODER LIBRARY
// VERSION 1.0 (2022/08/28)

int ceil_pow2(int n) {
	int x = 0;
	while ((1U << x) < (unsigned int)(n)) x++;
	return x;
}

template <class F, F (*composition)(F, F), F (*id)()> struct dual_segtree{
		public:
			dual_segtree() : dual_segtree(0) {}
			explicit dual_segtree(int n) : dual_segtree(std::vector<F>(n, id())) {}
			explicit dual_segtree(const std::vector<F>& v) : _n(int(v.size())) {
				log = ceil_pow2(_n);
				size = 1 << log;
				lz = std::vector<F>(2 * size, id());
				for (int i = 0; i < _n; i++) lz[size + i] = v[i];
			}
 
			void apply(int l, int r, F f){
				assert (0 <= l && l <= r && r <= _n);
				if (l == r) return;
 
				l += size;
				r += size;
 
				for (int i = log; i >= 1; i--){
					if (((l >> i) << i) != l) push(l >> i);
					if (((r >> i) << i) != r) push((r - 1) >> i);
				}
 
				while (l < r){
					if (l & 1) all_apply(l++, f);
					if (r & 1) all_apply(--r, f);
					l >>= 1;
					r >>= 1;
				}
			}
			
			F get(int p) {
				assert(0 <= p && p < _n);
				p += size;
				for (int i = log; i >= 1; i--) push(p >> i);
				return lz[p];
			}
		
		private:
			int _n, size, log;
			std::vector<F> lz;
 
			void all_apply(int k, F f){
				lz[k] = composition(f, lz[k]);
			}
 
			void push(int k){
				all_apply(2 * k, lz[k]);
				all_apply(2 * k + 1, lz[k]);
				lz[k] = id();
			}
 
};

// ---- END : DUAL SEGMENT TREE ----

struct F{
	mint v[3];
};

int composition(int a, int b){
	return a + b;
}

int id(){
	return 0;
}

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int n, b, q; cin >> n >> b >> q;
	mint::set_mod(b);


	dual_segtree<int,composition,id> seg(n);

	vector<F> tr(q+1);
	tr[0] = {1, 1, 1};
	rep(i,1,q+1){
		tr[i].v[0] = tr[i-1].v[0] + 1;
		tr[i].v[1] = (tr[i-1].v[0] + 1) * tr[i-1].v[2] * 2 + tr[i-1].v[1] * 3;
		tr[i].v[2] = tr[i-1].v[2] * 3;
	}

	rep(i,0,q){
		int l, m, r; cin >> l >> m >> r;
		l--;
		m--;
		seg.apply(l, r, 1);
		//cout << seg.get(m) << endl;
		F s = tr[seg.get(m)];
		cout << s.v[0].val() << " " << s.v[1].val() << " " << s.v[2].val() << "\n";
	}
	
}
0