結果

問題 No.2942 Sigma Music Game Level Problem
ユーザー srjywrdnprkt
提出日時 2024-10-19 20:54:11
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 1,110 ms / 6,000 ms
コード長 1,441 bytes
コンパイル時間 2,042 ms
コンパイル使用メモリ 196,620 KB
最終ジャッジ日時 2025-02-24 21:42:54
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 24
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;
using ll = long long;

template<class T> struct BIT {
    private:
        vector<T> bit; int N;
        T _sum(int r){
            r++; T res = 0;
            while(r > 0) res += bit[r-1], r -= r & -r;
            return res;
        }

    public:
        BIT (int n){ N = n; bit.resize(N);}
        BIT (vector<T> &a) : BIT(a.size()) { for (int i=0; i<N; i++) add(i, a[i]);}
        void add(int loc, T val){
            loc++;
            while(loc <= N) bit[loc-1] += val, loc += loc & -loc;
        }
        void change(int loc, T val){add(loc, -get(loc)+val);}
        T sum(int l, int r) {return _sum(r) - _sum(l-1);}
        T get(int l) {return sum(l, l);}
        void clear() {for (int i=0; i<N; i++) bit[i] = 0;}
};

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

    ll N, Q, x, y, z, t;
    bool f=0;
    cin >> N >> Q >> x;
    BIT<ll> tc(2e5+1), ts(2e5+1);
    for (int i=0; i<N; i++){
        cin >> x;
        tc.add(x, 1);
        ts.add(x, x);
    }

    while(Q--){
        cin >> t;
        if (t == 1){
            cin >> x;
            tc.add(x, 1);
            ts.add(x, x);
        }
        else if (t == 2){
            cin >> x >> y;
            f=1;
            cout << tc.sum(x, y) << " " << ts.sum(x, y) << endl;
        }
        else{
            cin >> x;
        }
    }
    if (!f) cout << "Not Found!" << endl;

    return 0;
}
0