結果
問題 | No.255 Splarrraaay スプラーレェーーイ |
ユーザー |
![]() |
提出日時 | 2021-05-04 22:37:26 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 2,023 ms / 10,000 ms |
コード長 | 2,478 bytes |
コンパイル時間 | 7,023 ms |
コンパイル使用メモリ | 265,940 KB |
最終ジャッジ日時 | 2025-01-21 06:54:26 |
ジャッジサーバーID (参考情報) |
judge1 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 10 |
ソースコード
//https://ncode.syosetu.com/n4830bu/255/#include "atcoder/all"#include <bits/stdc++.h>using namespace atcoder;using namespace std;using ll = long long;const ll mod = 1000000000000000009;struct S {ll maine, len;};S op(S a, S b) {return {a.maine + b.maine, a.len + b.len};}S e() {return {0, 0};}struct F {ll book;bool zero;};S mapping(F f, S x) {if (f.zero)x.maine = 0;x.maine += f.book * x.len;return x;}F composition(F f, F g) {if (f.zero)return f;if (g.zero)f.zero = true;f.book += g.book;return f;}F id() {return {0, false};}int main() {ll N;int Q;cin >> N >> Q;vector<int> X(Q);vector<ll> L(Q), R(Q);for (int i = 0; i < Q; i++) {cin >> X[i] >> L[i] >> R[i];X[i]--;R[i]++;}vector<ll> compress{0, N};compress.insert(compress.end(), L.begin(), L.end());compress.insert(compress.end(), R.begin(), R.end());sort(compress.begin(), compress.end());compress.erase(unique(begin(compress), end(compress)), end(compress));auto idx = [&](ll x) { return lower_bound(compress.begin(), compress.end(), x) - compress.begin(); };int M = compress.size();vector<S> initial(M - 1);for (int i = 0; i < M - 1; i++) {initial[i] = {0, compress[i + 1] - compress[i]};}vector segs(5, lazy_segtree<S, op, e, F, mapping, composition, id>(initial));vector<ll> bonus(5);for (int i = 0; i < Q; i++) {int x = X[i];ll l = L[i], r = R[i];int l_idx = idx(l), r_idx = idx(r);if (x >= 0) {for (int y = 0; y < 5; y++) {if (x == y)continue;segs[y].apply(l_idx, r_idx, {0, true});}segs[x].apply(l_idx, r_idx, {1, false});} else {vector<ll> scores(5);for (int x = 0; x < 5; x++) {scores[x] = segs[x].prod(l_idx, r_idx).maine;}int idx_max = max_element(scores.begin(), scores.end()) - scores.begin();int cnt = 0;for (int x = 0; x < 5; x++) {cnt += scores[x] == scores[idx_max];}if (cnt == 1)(bonus[idx_max] += scores[idx_max]) %= mod;}}for (int x = 0; x < 5; x++) {cout << (segs[x].all_prod().maine + bonus[x]) % mod << " \n"[x == 4];}}