結果

問題 No.2395 区間二次変換一点取得
ユーザー anago-pieanago-pie
提出日時 2023-08-02 08:05:34
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,483 bytes
コンパイル時間 1,905 ms
コンパイル使用メモリ 170,108 KB
実行使用メモリ 7,552 KB
最終ジャッジ日時 2024-04-20 07:48:17
合計ジャッジ時間 7,712 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 40 ms
5,376 KB
testcase_13 AC 450 ms
7,296 KB
testcase_14 AC 449 ms
7,296 KB
testcase_15 AC 443 ms
7,424 KB
testcase_16 AC 447 ms
7,296 KB
testcase_17 AC 444 ms
7,296 KB
testcase_18 WA -
testcase_19 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include <iterator>
using namespace std;
#define rep(i, n) for(int i=0; i<n; i++)
#define debug 1
using ll = long long;
using ld = long double;
const int mod = 998244353;
const double pi = atan2(0, -1);
#include <time.h>
#include <chrono>

ll Power(ll x, ll y, ll B) {
	if (y == 0) {
		return 1;
	}
	if (y == 1) {
		return x % B;
	}
	if (y % 2 == 1) {
		return (Power(x, y - 1, B) * (x % B)) % B;
	}
	else {
		ll t = Power(x, y / 2, B) % B;
		return (t*t)%B;
	}
}

ll N, B;
ll n = 1;
struct SegTree {
	vector<ll> Tree;
	SegTree() {
		while (n < N) {
			n *= 2;
		}
		vector<ll> t(n*2, 0);
		Tree = t;
	}

	void Add(int l, int r){
		 AddFunc(l, r, 0, 0, n);
	}
	void AddFunc(int l, int r, int k, int s, int t) {
		if (r<=s || l>=t) {
			return;
		}
		else if (l <= s && r >= t) {
			Tree[k]++;
		}
		else {
			AddFunc(l, r, k * 2 + 1, s, (s+t) / 2);
			AddFunc(l, r, k * 2 + 2, (s+t) / 2, t);
		}
	}

	int Query(int m) {
		int ans = 0;
		int p = m + n - 1;
		while (p>0) {
			ans += Tree[p];
			p = (p - 1) / 2;
		}
		ans += Tree[0];
		return ans;
	}
};

int main() {
	int Q;
	cin >> N >> B >> Q;
	SegTree tree;
	rep(test, Q) {
		int L, M, R;
		cin >> L >> M >> R;
		L--; M--;
		tree.Add(L, R);

		int num = tree.Query(M);
		ll X, Y, Z;
		X = (num + 1)%B;
		Z = Power(3, num, B)%B;
		if (num == 0) {
			Y = 1;
		}
		else {
			Y = (Power(3, num, B) + Power(3, num - 1, B) * (ll)num * ((ll)num + 3)) % B;
		}
		
		cout << X << " " << Y << " " << Z << endl;
	}
}
0