結果

問題 No.1441 MErGe
ユーザー chocoruskchocorusk
提出日時 2021-03-26 22:38:42
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 565 ms / 1,000 ms
コード長 2,116 bytes
コンパイル時間 3,265 ms
コンパイル使用メモリ 188,820 KB
実行使用メモリ 7,952 KB
最終ジャッジ日時 2023-08-19 09:14:44
合計ジャッジ時間 14,084 ms
ジャッジサーバーID
(参考情報)
judge10 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,540 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 4 ms
4,380 KB
testcase_04 AC 5 ms
4,376 KB
testcase_05 AC 14 ms
4,376 KB
testcase_06 AC 14 ms
4,380 KB
testcase_07 AC 14 ms
4,380 KB
testcase_08 AC 140 ms
4,380 KB
testcase_09 AC 141 ms
4,376 KB
testcase_10 AC 226 ms
4,384 KB
testcase_11 AC 219 ms
4,376 KB
testcase_12 AC 235 ms
4,380 KB
testcase_13 AC 372 ms
7,496 KB
testcase_14 AC 383 ms
7,552 KB
testcase_15 AC 413 ms
7,228 KB
testcase_16 AC 363 ms
7,488 KB
testcase_17 AC 360 ms
7,324 KB
testcase_18 AC 429 ms
6,588 KB
testcase_19 AC 483 ms
7,132 KB
testcase_20 AC 377 ms
6,220 KB
testcase_21 AC 344 ms
5,640 KB
testcase_22 AC 524 ms
5,572 KB
testcase_23 AC 500 ms
7,924 KB
testcase_24 AC 498 ms
7,896 KB
testcase_25 AC 565 ms
7,952 KB
testcase_26 AC 495 ms
7,828 KB
testcase_27 AC 507 ms
7,872 KB
testcase_28 AC 254 ms
7,756 KB
testcase_29 AC 262 ms
7,804 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#include <utility>
#include <functional>
#include <time.h>
#include <stack>
#include <array>
#include <list>
#include <atcoder/all>
#define popcount __builtin_popcount
using namespace std;
using namespace atcoder;
typedef long long ll;
typedef pair<int, int> P;
template<typename T>
struct BIT{
    vector<T> bit;
    int size;
    BIT(int n):size(n), bit(n+1, 0){}
    T sum(int i){ //[0, i)
        T s=0;
        while(i>0){
            s+=bit[i];
            i-=(i&(-i));
        }
        return s;
    }
    T sum(int l, int r){ //[l, r)
        return sum(r)-sum(l);
    }
    void add(int i, T x){
        i++;
        while(i<=size){
            bit[i]+=x;
            i+=(i&(-i));
        }
    }
};
int main()
{
    int n, q; cin>>n>>q;
    BIT<int> bit(n+1);
    BIT<ll> bits(n+1);
    int nx[200020];
    ll a[200020];
    a[n]=0, nx[n]=n;
    for(int i=0; i<n; i++){
        cin>>a[i];
        bits.add(i, a[i]);
        nx[i]=i+1;
        bit.add(i, 1);
    }

    while(q--){
        int t, l, r; cin>>t>>l>>r;
        l--;
        int ok=0, ng=n;
        while(ng-ok>1){
            int mid=(ok+ng)/2;
            if(bit.sum(mid)<=l) ok=mid;
            else ng=mid;
        }
        if(t==1){
            for(int i=l+1; i<r; i++){
                bits.add(nx[ok], -a[nx[ok]]);
                bits.add(ok, a[nx[ok]]);
                bit.add(nx[ok], -1);
                a[ok]+=a[nx[ok]];
                a[nx[ok]]=0;
                nx[ok]=nx[nx[ok]];
            }
        }else{
            int ok1=0, ng1=n+1;
            while(ng1-ok1>1){
                int mid=(ok1+ng1)/2;
                if(bit.sum(mid)<=r) ok1=mid;
                else ng1=mid;
            }
            printf("%lld\n", bits.sum(ok1)-bits.sum(ok));
        }
    }
    return 0;
}
0