結果

問題 No.833 かっこいい電車
ユーザー kappybarkappybar
提出日時 2020-06-18 21:02:16
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,003 bytes
コンパイル時間 1,497 ms
コンパイル使用メモリ 168,576 KB
実行使用メモリ 6,240 KB
最終ジャッジ日時 2023-09-16 12:19:28
合計ジャッジ時間 4,773 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 129 ms
4,628 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 2 ms
4,376 KB
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 WA -
testcase_29 WA -
testcase_30 AC 75 ms
6,240 KB
testcase_31 AC 126 ms
4,552 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){
        int 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