結果
問題 | No.255 Splarrraaay スプラーレェーーイ |
ユーザー |
|
提出日時 | 2023-01-30 22:37:30 |
言語 | C++14 (gcc 11.2.0 + boost 1.78.0) |
結果 |
AC
|
実行時間 | 1,036 ms / 10,000 ms |
コード長 | 2,178 bytes |
コンパイル時間 | 2,919 ms |
使用メモリ | 161,400 KB |
最終ジャッジ日時 | 2023-01-30 22:37:47 |
合計ジャッジ時間 | 14,309 ms |
ジャッジサーバーID (参考情報) |
judge11 / judge13 |
テストケース
テストケース表示入力 | 結果 | 実行時間 使用メモリ |
---|---|---|
testcase_00 | AC | 1,033 ms
161,292 KB |
testcase_01 | AC | 1,036 ms
161,400 KB |
testcase_02 | AC | 1,008 ms
161,316 KB |
testcase_03 | AC | 990 ms
161,340 KB |
testcase_04 | AC | 2 ms
3,536 KB |
testcase_05 | AC | 1,008 ms
161,324 KB |
testcase_06 | AC | 977 ms
161,256 KB |
testcase_07 | AC | 999 ms
161,340 KB |
testcase_08 | AC | 1,010 ms
161,352 KB |
testcase_09 | AC | 958 ms
161,188 KB |
ソースコード
#include <atcoder/all> using namespace std; using namespace atcoder; using ll = long long; const ll MOD = 1'000'000'000'000'000'009ll; using S = pair<ll, ll>; using F = pair<ll, ll>; S e(){return S({0, 0});} S op(S l, S r) { return make_pair(l.first + r.first, l.second + r.second); } S mapping(F f, S x) { return make_pair(x.first * f.first + x.second * f.second, x.second); } F composition(F f, F g) { return make_pair(f.first * g.first, g.second * f.first + f.second); } F id() {return make_pair(1, 0); } void add(ll &x, ll y){ x += y; while(x >= MOD)x -= MOD; } int main(){ ios::sync_with_stdio(false); cin.tie(0); ll N, l, r; int Q, cmd; cin >> N >> Q; vector<tuple<int, ll, ll>> query(Q); vector<ll> ca = {0, N}; for(int i = 0; i < Q; i++){ cin >> cmd >> l >> r; r++; query[i] = make_tuple(cmd, l, r); ca.push_back(l); ca.push_back(r); } sort(ca.begin(), ca.end()); ca.erase(unique(ca.begin(), ca.end()), ca.end()); vector<S> temp(ca.size(), make_pair(0, 0)); for(int i = 0; i + 1 < ca.size(); i++){ temp[i].second = ca[i + 1] - ca[i]; } vector<lazy_segtree<S, op, e, F, mapping, composition, id>> seg(5, lazy_segtree<S, op, e, F, mapping, composition, id>(temp)); array<ll, 5> score{}, temp2{}; for(int i = 0; i < Q; i++){ tie(cmd, l, r) = query[i]; l = lower_bound(ca.begin(), ca.end(), l) - ca.begin(); r = lower_bound(ca.begin(), ca.end(), r) - ca.begin(); if(cmd == 0){ for(int i = 0; i < 5; i++){ temp2[i] = seg[i].prod(l, r).first; } auto it = max_element(temp2.begin(), temp2.end()); if(count(temp2.begin(), temp2.end(), *it) >= 2)continue; add(score[it - temp2.begin()], *it); }else{ cmd--; for(int i = 0; i < 5; i++){ if(i == cmd)seg[i].apply(l, r, {1, 1}); else seg[i].apply(l, r, {0, 0}); } } } for(int i = 0; i < 5; i++){ add(score[i], seg[i].all_prod().first); cout << score[i] << (i + 1 == 5 ? '\n' : ' '); } }