結果

問題 No.2333 Slime Structure
ユーザー kwm_tkwm_t
提出日時 2023-05-31 21:39:57
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 213 ms / 3,000 ms
コード長 2,600 bytes
コンパイル時間 4,208 ms
コンパイル使用メモリ 269,972 KB
実行使用メモリ 53,828 KB
最終ジャッジ日時 2023-08-28 01:38:51
合計ジャッジ時間 12,989 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 96 ms
27,728 KB
testcase_03 AC 127 ms
31,972 KB
testcase_04 AC 135 ms
31,376 KB
testcase_05 AC 106 ms
29,352 KB
testcase_06 AC 152 ms
33,132 KB
testcase_07 AC 190 ms
52,540 KB
testcase_08 AC 190 ms
52,644 KB
testcase_09 AC 195 ms
52,660 KB
testcase_10 AC 188 ms
52,268 KB
testcase_11 AC 188 ms
52,976 KB
testcase_12 AC 186 ms
53,116 KB
testcase_13 AC 185 ms
52,684 KB
testcase_14 AC 187 ms
53,120 KB
testcase_15 AC 183 ms
52,656 KB
testcase_16 AC 186 ms
53,568 KB
testcase_17 AC 187 ms
53,568 KB
testcase_18 AC 187 ms
53,148 KB
testcase_19 AC 185 ms
52,512 KB
testcase_20 AC 190 ms
53,828 KB
testcase_21 AC 186 ms
53,076 KB
testcase_22 AC 201 ms
53,776 KB
testcase_23 AC 200 ms
52,936 KB
testcase_24 AC 213 ms
52,548 KB
testcase_25 AC 201 ms
53,120 KB
testcase_26 AC 200 ms
53,564 KB
testcase_27 AC 201 ms
53,208 KB
testcase_28 AC 209 ms
52,848 KB
testcase_29 AC 207 ms
52,436 KB
testcase_30 AC 208 ms
52,584 KB
testcase_31 AC 204 ms
53,120 KB
testcase_32 AC 175 ms
53,732 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<int,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; }
struct S {
	long long lmax;
	long long rmax;
	long long max;
	long long sum;
};
S op(S a, S b) {
	return S{ max(a.lmax, a.sum + b.lmax),
			 max(b.rmax, b.sum + a.rmax),
			 max(max(a.max, b.max), a.rmax + b.lmax),
			 a.sum + b.sum };
}
S e() { return S{ -LINF, -LINF, -LINF, 0 }; }

int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	//#pragma warning(disable : 4996)
		//FILE *in = freopen("in/in.txt", "r", stdin);
		//FILE *out = freopen("out/out.txt", "w", stdout);
	int n; cin >> n;
	vector<long long>a(n), b(n), sb(n + 1);
	rep(i, n)cin >> a[i] >> b[i];
	rep(i, n)sb[i + 1] = sb[i] + b[i];
	vector<long long>tmp = { 0 };
	rep(i, n) {
		tmp.push_back(sb[i + 1]);
	}
	int q; cin >> q;
	vector<long long>t(q), l(q), r(q);
	rep(i, q) {
		cin >> t[i] >> l[i] >> r[i];
		l[i]--;
		if (1 == t[i]) {
			tmp.push_back(l[i]);
			tmp.push_back(l[i] + 1);//??
		}
		else {
			tmp.push_back(l[i]);
			tmp.push_back(r[i]);
		}
	}
	sort(all(tmp));
	tmp.erase(unique(all(tmp)), tmp.end());
	//rep(i, n + 1) sb[i] = lower_bound(all(tmp), sb[i]) - tmp.begin();
	int sz = tmp.size();
	segtree<S, op, e>seg(sz);
	auto set = [&](int idx, long long sz, long long val)->void {
		if (val >= 0) {
			seg.set(idx, { sz* val, sz*val, sz*val, sz*val });
		}
		else {
			seg.set(idx, { val, val, val, sz*val });
		}
	};
	rep(i, sz - 1) {
		long long sz = tmp[i + 1] - tmp[i];
		int idx = upper_bound(all(sb), tmp[i]) - sb.begin();
		set(i, sz, a[idx - 1]);
	}
	rep(i, q) {
		if (1 == t[i]) {
			int idx = lower_bound(all(tmp), l[i]) - tmp.begin();
			set(idx, 1, r[i]);
		}
		else {
			int idxl = lower_bound(all(tmp), l[i]) - tmp.begin();
			int idxr = lower_bound(all(tmp), r[i]) - tmp.begin();
			auto get = seg.prod(idxl, idxr);
			cout << get.max << endl;
		}
	}
	return 0;
}
0