結果

問題 No.2101 [Cherry Alpha N] ずっとこの数列だったらいいのに
ユーザー kwm_tkwm_t
提出日時 2022-10-15 18:37:21
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 414 ms / 6,000 ms
コード長 1,911 bytes
コンパイル時間 5,073 ms
コンパイル使用メモリ 267,016 KB
実行使用メモリ 31,936 KB
最終ジャッジ日時 2023-09-09 03:01:30
合計ジャッジ時間 23,758 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 159 ms
21,380 KB
testcase_04 AC 278 ms
24,896 KB
testcase_05 AC 149 ms
16,036 KB
testcase_06 AC 239 ms
23,784 KB
testcase_07 AC 277 ms
25,776 KB
testcase_08 AC 271 ms
25,892 KB
testcase_09 AC 124 ms
14,600 KB
testcase_10 AC 114 ms
13,768 KB
testcase_11 AC 199 ms
19,456 KB
testcase_12 AC 202 ms
20,160 KB
testcase_13 AC 129 ms
14,460 KB
testcase_14 AC 140 ms
11,836 KB
testcase_15 AC 321 ms
27,200 KB
testcase_16 AC 253 ms
24,640 KB
testcase_17 AC 101 ms
10,640 KB
testcase_18 AC 395 ms
30,784 KB
testcase_19 AC 404 ms
30,604 KB
testcase_20 AC 406 ms
31,752 KB
testcase_21 AC 409 ms
31,068 KB
testcase_22 AC 413 ms
30,208 KB
testcase_23 AC 407 ms
30,384 KB
testcase_24 AC 406 ms
30,660 KB
testcase_25 AC 406 ms
31,544 KB
testcase_26 AC 407 ms
31,276 KB
testcase_27 AC 414 ms
30,876 KB
testcase_28 AC 405 ms
30,736 KB
testcase_29 AC 414 ms
30,204 KB
testcase_30 AC 404 ms
31,936 KB
testcase_31 AC 406 ms
30,500 KB
testcase_32 AC 400 ms
30,276 KB
testcase_33 AC 340 ms
31,044 KB
testcase_34 AC 348 ms
30,204 KB
testcase_35 AC 354 ms
30,856 KB
testcase_36 AC 351 ms
30,596 KB
testcase_37 AC 348 ms
30,608 KB
testcase_38 AC 72 ms
13,412 KB
testcase_39 AC 119 ms
14,256 KB
testcase_40 AC 213 ms
30,736 KB
testcase_41 AC 1 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
//using mint = modint1000000007;
//const int mod = 1000000007;
//using mint = modint998244353;
//const int mod = 998244353;
//const int INF = 1e9;
//const long long LINF = 1e18;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep2(i,l,r)for(int i=(l);i<(r);++i)
#define rrep(i, n) for (int i = (n-1); i >= 0; --i)
#define rrep2(i,l,r)for(int i=(r-1);i>=(l);--i)
#define all(x) (x).begin(),(x).end()
#define allR(x) (x).rbegin(),(x).rend()
#define endl "\n"
#define P pair<long long,int>
template<typename A, typename B> inline bool chmax(A & a, const B & b) { if (a < b) { a = b; return true; } return false; }
template<typename A, typename B> inline bool chmin(A & a, const B & b) { if (a > b) { a = b; return true; } return false; }
long long op(long long a, long long b) { return a + b; }
long long e() { return 0; }
int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int n; cin >> n;
	vector<long long>a(n), t(n);
	vector<P>eve;
	rep(i, n) {
		cin >> a[i] >> t[i];
		eve.push_back({ 0 + t[i] * 3 ,i });
		long long t0 = a[i] + t[i];
		eve.push_back({ 1 + t0 * 3 ,i });
	}
	int q; cin >> q;
	vector<long long>d(q), l(q), r(q);
	rep(i, q) {
		cin >> d[i] >> l[i] >> r[i];
		l[i]--; r[i]--;
		eve.push_back({ 2 + d[i] * 3 ,i });
	}
	sort(all(eve));
	segtree<long long, op, e>seg0(a);
	segtree<long long, op, e>seg1(n);
	vector<long long>ans(q);
	rep(i, eve.size()) {
		auto[time, idx] = eve[i];
		if (0 == time % 3) {
			long long val = a[idx] + t[idx] - 1;
			seg0.set(idx, val);
			seg1.set(idx, 1);
		}
		else if (1 == time % 3) {
			seg0.set(idx, 0);
			seg1.set(idx, 0);
		}
		else {
			auto get0 = seg0.prod(l[idx], r[idx] + 1);
			auto get1 = seg1.prod(l[idx], r[idx] + 1);
			ans[idx] = get0;
			time /= 3;
			ans[idx] -= get1 * time;
		}
	}
	rep(i, q)cout << ans[i] << endl;
	return 0;
}
0