結果

問題 No.1441 MErGe
ユーザー NOSSNOSS
提出日時 2021-03-26 22:38:14
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,488 bytes
コンパイル時間 2,665 ms
コンパイル使用メモリ 206,724 KB
実行使用メモリ 15,668 KB
最終ジャッジ日時 2023-08-19 09:14:02
合計ジャッジ時間 13,297 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 AC 250 ms
15,504 KB
testcase_29 AC 251 ms
15,668 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

using ll = long long int;
using ull = unsigned long long int;
using P = pair<int, int>;
using P3 = pair<int,P>;
using PP = pair<P, P>;
constexpr int INF32 = 1 << 30;
constexpr ll INF64 = 1LL << 62;
// constexpr ll MOD = 1000000007;
constexpr ll MOD = 998244353;
constexpr int di[] = {0, 1, 0, -1};
constexpr int dj[] = {1, 0, -1, 0};
constexpr int di8[] = {0, 1, 1, 1, 0, -1, -1, -1};
constexpr int dj8[] = {1, 1, 0, -1, -1, -1, 0, 1};
constexpr double EPS = 1e-10;
const double PI = acos(-1);

#define ALL(v) (v).begin(),(v).end()
#define REP(i,n) for(int i=0,i_len=n; i<i_len; ++i)

template<typename T1,typename T2> bool chmax(T1 &a, T2 b) { if (a<b) { a=b; return 1; } return 0; }
template<typename T1,typename T2> bool chmin(T1 &a, T2 b) { if (b<a) { a=b; return 1; } return 0; }

template <typename T>
struct BIT {
    int N;
    std::vector<T> bit;

    BIT() = default;
    BIT(int n) {init(n);}
    void init(int n){
        N = n;
        bit.assign(n+1, 0);
    }
    T getSum(int i) {  // i番目までの要素の和を求める(1-index)
        T sum = 0;
        while (i > 0) {
            sum += bit[i];
            i -= i & -i;
        }
        return sum;
    }
    void add(int i, T x) {  // i番目の要素にxを加算
        while (i <= N) {
            bit[i] += x;
            i += i & -i;
        }
    }
};

int n, q;
BIT<ll> bit, cnt;

int getIndex(int x){
    int ok = 0, ng = n;
    while(abs(ok-ng)>1){
        int mid = (ok+ng)/2;
        if(cnt.getSum(mid)<=x){
            ok = mid;
        }else{
            ng = mid;
        }
    }
    return ok;
}

int solve(){
    cin >> n >> q;
    bit.init(n);
    cnt.init(n);
    REP(i,n){
        ll a;
        cin >> a;
        bit.add(i+1, a);
        cnt.add(i+1, 1);
    }
    set<int> st;
    REP(i,n) st.insert(i);
    REP(i,q){
        int t, l, r;
        cin >> t >> l >> r;
        l = getIndex(l-1);
        r = getIndex(r-1);
        if(t==1){
            while(1){
                auto itr = st.lower_bound(l+1);
                if(itr == st.end() || *itr > r) break;
                cnt.add(*itr+1,-1);
                st.erase(itr);
            }
        }else{
            cout << bit.getSum(r+1)-bit.getSum(l) << endl;
        }
    }
    return 0;
}

int main(){
    cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(20);
    // int t; cin >> t; for(int i=0;i<t;i++) solve();
    // while(!solve());
    solve();
    return 0;
}
0