結果

問題 No.255 Splarrraaay スプラーレェーーイ
ユーザー t98slidert98slider
提出日時 2023-01-30 22:37:30
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 948 ms / 10,000 ms
コード長 2,178 bytes
コンパイル時間 3,240 ms
コンパイル使用メモリ 155,284 KB
実行使用メモリ 162,764 KB
最終ジャッジ日時 2023-09-12 19:03:29
合計ジャッジ時間 13,639 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 944 ms
161,432 KB
testcase_01 AC 948 ms
161,460 KB
testcase_02 AC 901 ms
162,764 KB
testcase_03 AC 921 ms
161,652 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 911 ms
162,020 KB
testcase_06 AC 904 ms
161,304 KB
testcase_07 AC 933 ms
162,264 KB
testcase_08 AC 898 ms
161,400 KB
testcase_09 AC 883 ms
161,704 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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' : ' ');
    }
}
0