結果

問題 No.833 かっこいい電車
ユーザー kappybarkappybar
提出日時 2020-06-18 21:05:29
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 129 ms / 2,000 ms
コード長 2,009 bytes
コンパイル時間 1,516 ms
コンパイル使用メモリ 170,044 KB
実行使用メモリ 6,264 KB
最終ジャッジ日時 2023-09-16 12:19:36
合計ジャッジ時間 5,427 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 129 ms
4,616 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 90 ms
4,600 KB
testcase_11 AC 113 ms
5,656 KB
testcase_12 AC 38 ms
4,380 KB
testcase_13 AC 28 ms
4,380 KB
testcase_14 AC 94 ms
5,736 KB
testcase_15 AC 48 ms
4,676 KB
testcase_16 AC 38 ms
5,200 KB
testcase_17 AC 38 ms
4,376 KB
testcase_18 AC 107 ms
4,960 KB
testcase_19 AC 37 ms
4,836 KB
testcase_20 AC 11 ms
4,380 KB
testcase_21 AC 95 ms
4,380 KB
testcase_22 AC 62 ms
5,896 KB
testcase_23 AC 42 ms
4,824 KB
testcase_24 AC 62 ms
5,672 KB
testcase_25 AC 104 ms
4,516 KB
testcase_26 AC 44 ms
5,128 KB
testcase_27 AC 73 ms
4,572 KB
testcase_28 AC 56 ms
4,376 KB
testcase_29 AC 63 ms
4,504 KB
testcase_30 AC 74 ms
6,264 KB
testcase_31 AC 123 ms
4,612 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
using namespace std;
using ll = long long ;
using P = pair<int,int> ;
using pll = pair<long long,long long>;
constexpr int INF = 1e9;
constexpr long long LINF = 1e17;
constexpr int MOD = 1000000007;
constexpr double PI = 3.14159265358979323846;


//1-indexedに注意!!!
struct BIT{
    int n;
    vector<long long> bit;

    BIT(int n):n(n){
        bit.resize(n+1);
    }

    long long sum(int i){
        long long res = 0;
        while(i > 0){
                res += bit[i];
                i -= i&-i;
        }
        return res;
    }

    void add(int i,long long val){
        while(i <= n){
                bit[i] += val;
                i += i&-i;
        }
    }
};

int main(){
    int n,q;
    cin >> n >> q;
    BIT l(n+1); rep(i,n) l.add(i+1,1);
    BIT r(n+1); rep(i,n) r.add(i+1,1);
    BIT S(n);
    vector<ll> a(n);
    rep(i,n){
        cin >> a[i];
        S.add(i+1,a[i]);
    }

    while(q--){
        int t,x;
        cin >> t >> x;
        if(t==1){
            int L = l.sum(x);
            int R = r.sum(x+1);

            int prevR = r.sum(x);
            int prevL = l.sum(x+1);
            r.add(L,R-prevR);
            r.add(x+1,-R+prevR);
            l.add(x+1,L-prevL);
            l.add(R+1,-L+prevL);
        }else if(t==2){
            int prevL = l.sum(x);
            int prevR = r.sum(x);

            r.add(prevL,x-prevR);
            r.add(x+1,-x+prevR);
            l.add(x+1,x+1-prevL);
            l.add(prevR+1,-x-1+prevL);
        }else if(t==3){
            S.add(x,1);
        }else if(t==4){
            int L = l.sum(x);
            int R = r.sum(x);

            if(L==1) cout << S.sum(R) << endl;
            else cout << S.sum(R) - S.sum(L-1) << endl;
        }

        /*
        cout << "start" << endl;
        rep(i,n) cout << l.sum(i+1) << " " ;
        cout << endl;
        rep(i,n) cout << r.sum(i+1) <<  " ";
        cout << endl;
        */

    }


    return 0;
}
0