結果

問題 No.3265 地元に帰れば天才扱い!
ユーザー kwm_t
提出日時 2025-09-06 16:08:59
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 917 ms / 2,500 ms
コード長 3,608 bytes
コンパイル時間 5,650 ms
コンパイル使用メモリ 334,844 KB
実行使用メモリ 14,580 KB
最終ジャッジ日時 2025-09-06 16:09:32
合計ジャッジ時間 28,523 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 21
権限があれば一括ダウンロードができます

ソースコード

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 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; }
namespace RangeAddRangeSum {
	// 区間加算・区間和取得
	struct S {
		long long value;
		int size;
	};
	using F = long long;
	S op(S a, S b) { return { a.value + b.value, a.size + b.size }; }
	S e() { return { 0, 0 }; }
	S mapping(F f, S x) { return { x.value + f * x.size, x.size }; }
	F composition(F f, F g) { return f + g; }
	F id() { return 0; }
	using lazy_segtree = atcoder::lazy_segtree<S, op, e, F, mapping, composition, id>;
}
#include <algorithm>
#include <cassert>
#include <vector>
const int INF = 1e9;
const long long LINF = 1e18;
template<class S, S op(S l, S r), S e()>
struct DualSegtree {
private:
	int mn = 0;
	int mN = 0;
	int mlogN = 0;
	std::vector<S> A;
	void propagate(int i) {
		if (i >= mN) return;
		A[i * 2] = op(A[i * 2], A[i]);
		A[i * 2 + 1] = op(A[i * 2 + 1], A[i]);
		A[i] = e();
	}
	void full_propagate(int i) {
		for (int d = mlogN; d > 0; d--) propagate(i >> d);
	}
public:
	DualSegtree(int n = 0) {
		mn = n;
		mlogN = 0; mN = 1;
		while (mN < n) { mN *= 2; mlogN++; }
		A.assign(mN * 2, e());
	}
	void point_init(int p) {
		assert(0 <= p); assert(p < mn);
		p += mN;
		full_propagate(p);
		A[p] = e();
	}
	S get(int p) {
		assert(0 <= p); assert(p < mn);
		p += mN;
		full_propagate(p);
		return A[p];
	}
	void apply(int l, int r, S x) {
		l += mN;
		r += mN;
		if (l != mN) full_propagate(l - 1);
		if (r != mN * 2) full_propagate(r);
		while (l < r) {
			if (l & 1) { A[l] = op(A[l], x); l++; }
			if (r & 1) { r--; A[r] = op(A[r], x); }
			l /= 2; r /= 2;
		}
	}
};
namespace RangeAdd {
	//区間加算、一点取得
	using S = long long;
	S op(S x, S f) { return { x + f }; }
	S e() { return { 0 }; }
}
long long op(long long a, long long b) { return a + b; }
long long e() { return 0; }
//DualSegtree<S, op, e>seg(n);
int main() {
	std::ios::sync_with_stdio(false);
	std::cin.tie(nullptr);
	int n, m; cin >> n >> m;

	segtree<long long, op, e>seg(m);
	DualSegtree<RangeAdd::S, RangeAdd::op, RangeAdd::e> dseg(m);
	vector<int>p(n), a(n), l(n), r(n);

	long long ans = 0;
	auto add = [&](int a, int p, int l, int r)->void {
		// -XXX
		ans -= dseg.get(p) * a;
		dseg.apply(l, r, 1);

		// XXX -
		seg.set(p, a);
		ans += (long long)a  * (r - l);
		ans -= seg.prod(l, r);
	};
	auto remove = [&](int a, int p, int l, int r)->void {
		// -XXX
		dseg.apply(l, r, -1);
		ans += dseg.get(p) * a;

		// XXX -
		ans -= (long long)a  * (r - l);
		ans += seg.prod(l, r);
		seg.set(p, 0);
	};
	rep(i, n) {
		p[i] = i;
		cin >> a[i] >> l[i] >> r[i];
		l[i]--, r[i]--;
		add(a[i], p[i], l[i], r[i] + 1);
	}

	int q; cin >> q;
	while (q--) {
		int x, y, u, v; cin >> x >> y >> u >> v;
		x--, y--, u--, v--;
		remove(a[x], p[x], l[x], r[x] + 1);
		p[x] = y;
		l[x] = u;
		r[x] = v;
		add(a[x], p[x], l[x], r[x] + 1);
		cout << ans << endl;
	}
	return 0;
}
0