結果
| 問題 |
No.255 Splarrraaay スプラーレェーーイ
|
| コンテスト | |
| ユーザー |
maine_honzuki
|
| 提出日時 | 2021-05-04 22:39:21 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 1,828 ms / 10,000 ms |
| コード長 | 2,553 bytes |
| コンパイル時間 | 9,028 ms |
| コンパイル使用メモリ | 267,424 KB |
| 最終ジャッジ日時 | 2025-01-21 06:54:54 |
|
ジャッジサーバー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 ull = unsigned long long;
const ull mod = 1000000000000000009;
struct S {
ull maine, len;
};
S op(S a, S b) {
return {a.maine + b.maine, a.len + b.len};
}
S e() {
return {0, 0};
}
struct F {
ull 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() {
cin.tie(nullptr);
ios::sync_with_stdio(false);
ull N;
int Q;
cin >> N >> Q;
vector<int> X(Q);
vector<ull> L(Q), R(Q);
for (int i = 0; i < Q; i++) {
cin >> X[i] >> L[i] >> R[i];
X[i]--;
R[i]++;
}
vector<ull> 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 = [&](ull 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<ull> bonus(5);
for (int i = 0; i < Q; i++) {
int x = X[i];
ull 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<ull> 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];
}
}
maine_honzuki