結果

問題 No.3265 地元に帰れば天才扱い!
ユーザー ルビサファせだい
提出日時 2025-09-06 14:39:12
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 1,500 ms / 2,500 ms
コード長 2,116 bytes
コンパイル時間 2,543 ms
コンパイル使用メモリ 209,044 KB
実行使用メモリ 29,936 KB
最終ジャッジ日時 2025-09-06 14:40:03
合計ジャッジ時間 37,581 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 21
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

#include <atcoder/fenwicktree.hpp>
#include <atcoder/segtree.hpp>
#include <atcoder/modint.hpp>
#include <atcoder/dsu.hpp>
#include <atcoder/lazysegtree.hpp>

using namespace atcoder;
using namespace std;
using ll = long long;
using ull = unsigned long long;
template <class T>
using max_heap = priority_queue<T>;
template <class T>
using min_heap = priority_queue<T, vector<T>, greater<>>;
ll ll_min = numeric_limits<ll>::min();
ll ll_max = numeric_limits<ll>::max();
ll ALPHABET_N = 26;
using mint = modint998244353;
#define rep(i, n) for (ll i = (ll)0; i < (ll)n; i++)
#define rep_(i, k, n) for (ll i = (ll)k; i < (ll)n; i++)
#define all(a) a.begin(), a.end()

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; }

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	ll n, m;
	cin >> n >> m;
	lazy_segtree<S, op, e, F, mapping, composition, id> cnt_seg(m), a_seg(m);
	vector<ll> x2idx(m);
	rep(i, m)
	{
		cnt_seg.set(i, {0, 1});
		a_seg.set(i, {0, 1});
		x2idx[i] = i;
	}
	vector<ll> A(n), L(n), R(n);
	ll ans = 0;
	rep(i, n)
	{
		cin >> A[i] >> L[i] >> R[i];
		L[i]--;
		cnt_seg.apply(L[i], R[i], 1);
		a_seg.set(i, {A[i], 1});
		ans += A[i] * (R[i] - L[i]);
	}
	rep(i, m)
	{
		ll k = cnt_seg.get(i).value;
		ans -= a_seg.get(i).value * (k);
	}
	ll q;
	cin >> q;
	rep(_, q)
	{
		ll x, y, u, v;
		cin >> x >> y >> u >> v;
		x--;
		u--;
		y--;
		ll idx = x2idx[x];
		x2idx[x] = y;
		ans -= A[x] * (R[x] - L[x]);
		ans += A[x] * (cnt_seg.get(idx).value - (L[x] <= idx && idx < R[x] ? 1 : 0));
		ans += a_seg.prod(L[x], R[x]).value;
		cnt_seg.apply(L[x], R[x], -1);
		a_seg.set(idx, {0, 1});
		L[x] = u;
		R[x] = v;
		cnt_seg.apply(L[x], R[x], 1);
		a_seg.set(y, {A[x], 1});
		ans += A[x] * (R[x] - L[x]);
		ans -= A[x] * (cnt_seg.get(y).value - (L[x] <= y && y < R[x] ? 1 : 0));
		ans -= a_seg.prod(L[x], R[x]).value;
		cout << ans << endl;
	}
	return 0;
}
0