結果

問題 No.2942 Sigma Music Game Level Problem
ユーザー GOTKAKOGOTKAKO
提出日時 2024-10-18 22:40:04
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 601 ms / 6,000 ms
コード長 4,210 bytes
コンパイル時間 2,451 ms
コンパイル使用メモリ 209,472 KB
実行使用メモリ 11,472 KB
最終ジャッジ日時 2024-10-18 22:53:32
合計ジャッジ時間 11,872 ms
ジャッジサーバーID
(参考情報)
judge6 / judge8
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 5 ms
11,428 KB
testcase_01 AC 5 ms
11,456 KB
testcase_02 AC 5 ms
11,268 KB
testcase_03 AC 5 ms
11,444 KB
testcase_04 AC 5 ms
11,428 KB
testcase_05 AC 5 ms
11,384 KB
testcase_06 AC 5 ms
11,380 KB
testcase_07 AC 5 ms
11,244 KB
testcase_08 AC 5 ms
11,388 KB
testcase_09 AC 6 ms
11,340 KB
testcase_10 AC 6 ms
11,440 KB
testcase_11 AC 242 ms
11,428 KB
testcase_12 AC 572 ms
11,424 KB
testcase_13 AC 445 ms
11,408 KB
testcase_14 AC 221 ms
11,308 KB
testcase_15 AC 235 ms
11,380 KB
testcase_16 AC 433 ms
11,336 KB
testcase_17 AC 108 ms
11,472 KB
testcase_18 AC 329 ms
11,340 KB
testcase_19 AC 579 ms
11,304 KB
testcase_20 AC 184 ms
11,376 KB
testcase_21 AC 601 ms
11,380 KB
testcase_22 AC 571 ms
11,428 KB
testcase_23 AC 177 ms
11,408 KB
testcase_24 AC 35 ms
11,240 KB
testcase_25 AC 5 ms
11,428 KB
testcase_26 AC 379 ms
11,308 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

using SS = pair<long long,long long>;
class SegmentTree{
    public:
    int siz = 1,n;
    vector<SS> dat;
 
    SS op(SS a, SS b){return {a.first+b.first,a.second+b.second};}
    SS e(){return {0,0};}
    void renew (SS &a,SS x){
        a = op(a,x);
        //a = x;
        //その他.
    }
 
    void make(int N){
        while(siz < N) siz *= 2;
        n = N; dat.resize(siz*2,e());
    }
 
    void make2(int N,vector<SS> &A){
        make(N);
        for(int i=0; i<N; i++){
            int pos = i+siz;
            dat.at(pos) = A.at(i);
        }
        for(int i=siz-1; i>0; i--) dat.at(i) = op(dat.at(i*2),dat.at(i*2+1));
    }
 
    void update(int pos,SS x){
        pos = pos+siz;
        renew(dat.at(pos),x);
        while(pos != 1){
            pos = pos/2;
            dat.at(pos) = op(dat.at(pos*2),dat.at(pos*2+1));
        }
    }
 
    SS findans(int l, int r){
        SS retl = e(),retr = e();
        l += siz,r += siz;
        while(l < r){
            if(l&1) retl = op(retl,dat.at(l++));
            if(r&1) retr = op(dat.at(--r),retr);
            l >>= 1; r >>= 1;
        }
        return op(retl,retr);
    }
 
    SS get(int pos){return dat.at(pos+siz);}
    SS rangeans(int l, int r){return findans(l,r);}
    SS allrange(){return dat.at(1);}
 
    //rightは) leftは[で 渡す&返す. 
    int maxright(const function<bool(SS)> f,int l = 0){
        l += siz; int r = n+siz;
        vector<int> ls,rs;
        while(l < r){
            if(l&1) ls.push_back(l++);
            if(r&1) rs.push_back(--r);
            l >>= 1; r >>= 1; 
        }
        SS okl = e();
        for(int i=0; i<ls.size(); i++){
            l = ls.at(i);
            SS now = op(okl,dat.at(l));
            if(!f(now)){
                while(l < siz){
                    l <<= 1;
                    now = op(okl,dat.at(l));
                    if(f(now)){okl = now; l++;}
                }
                return l-siz;
            } 
            okl = now;
        }
        for(int i=rs.size()-1; i>=0; i--){
            l = rs.at(i);
            SS now = op(okl,dat.at(l));
            if(!f(now)){
                while(l < siz){
                    l <<= 1;
                    now = op(okl,dat.at(l));
                    if(f(now)){okl = now; l++;}
                }
                return l-siz;
            } 
            okl = now;
        }
        return n;
    }
    int minleft(const function<bool(SS)> f,int r = -1){
        if(r == -1) r = n;
        int l = siz; r += siz;
        vector<int> ls,rs;
        while(l < r){
            if(l&1) ls.push_back(l++);
            if(r&1) rs.push_back(--r);
            l >>= 1; r >>= 1; 
        }
        SS okr = e();
        for(int i=0; i<rs.size(); i++){
            r = rs.at(i);
            SS now = op(dat.at(r),okr);
            if(!f(now)){
                while(r < siz){
                    r <<= 1; r++;
                    now = op(dat.at(r),okr);
                    if(f(now)){okr = now; r--;}
                }
                return r+1-siz;
            }
        }
        for(int i=ls.size()-1; i>=0; i--){
            r = ls.at(i);
            SS now = op(dat.at(r),okr);
            if(!f(now)){
                while(r < siz){
                    r <<= 1; r++;
                    now = op(dat.at(r),okr);
                    if(f(now)){okr = now; r--;}
                }
                return r+1-siz;
            }
        }
        return 0;
    }
    //ノーマルセグ木.一年の時を経て漸く二分探索実装した.
};

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    int N,Q,L0; cin >> N >> Q >> L0;
    SegmentTree Z; Z.make(200001);
    while(N--){
        int a; cin >> a;
        Z.update(a,{1,a});
    }

    bool f = false;
    while(Q--){
        int t; cin >> t;
        if(t == 1){
            int l; cin >> l;
            Z.update(l,{1,l});
        }
        if(t == 2){
            f = true;
            int l,r; cin >> l >> r; r++;
            auto [a,b] = Z.rangeans(l,r);
            cout << a << " " << b << "\n";
        }
        if(t == 3) cin >> L0;
    }
    if(!f) cout << "Not Found!\n";
} 
0