結果

問題 No.833 かっこいい電車
ユーザー ShibuyapShibuyap
提出日時 2020-01-27 17:53:39
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 145 ms / 2,000 ms
コード長 1,980 bytes
コンパイル時間 1,549 ms
コンパイル使用メモリ 165,084 KB
実行使用メモリ 7,828 KB
最終ジャッジ日時 2023-10-12 13:02:08
合計ジャッジ時間 7,724 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 145 ms
6,716 KB
testcase_01 AC 2 ms
5,416 KB
testcase_02 AC 2 ms
5,432 KB
testcase_03 AC 2 ms
5,404 KB
testcase_04 AC 2 ms
5,536 KB
testcase_05 AC 2 ms
5,480 KB
testcase_06 AC 2 ms
5,460 KB
testcase_07 AC 2 ms
5,480 KB
testcase_08 AC 2 ms
5,464 KB
testcase_09 AC 2 ms
5,464 KB
testcase_10 AC 98 ms
6,744 KB
testcase_11 AC 125 ms
7,416 KB
testcase_12 AC 41 ms
6,204 KB
testcase_13 AC 31 ms
5,696 KB
testcase_14 AC 99 ms
7,600 KB
testcase_15 AC 51 ms
6,524 KB
testcase_16 AC 38 ms
6,864 KB
testcase_17 AC 42 ms
5,568 KB
testcase_18 AC 118 ms
6,764 KB
testcase_19 AC 38 ms
6,724 KB
testcase_20 AC 11 ms
5,828 KB
testcase_21 AC 103 ms
6,052 KB
testcase_22 AC 64 ms
7,492 KB
testcase_23 AC 43 ms
6,852 KB
testcase_24 AC 63 ms
7,520 KB
testcase_25 AC 113 ms
6,568 KB
testcase_26 AC 45 ms
6,980 KB
testcase_27 AC 78 ms
6,804 KB
testcase_28 AC 62 ms
6,000 KB
testcase_29 AC 70 ms
6,412 KB
testcase_30 AC 64 ms
7,828 KB
testcase_31 AC 131 ms
6,752 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
#define yn {puts("Yes");}else{puts("No");}

// long long version
const int MAX_N = 300005;
ll bit[MAX_N+1][2];
int nn = MAX_N; // 1-index

void adds(int a, ll w, int z){
    for(int x = a; x <= nn; x += x & -x) bit[x][z] += w;
}
ll sums(int a, int z){ // bit[1,a]の和を返す.
    ll ret = 0;
    for(int x = a; x > 0; x -= x & -x) ret += bit[x][z];  
    return ret;
}

int main() {
    int n, q;
    cin >> n >> q;

    ll a[n+1] = {};
    srep(i,1,n+1)cin >> a[i];

    srep(i,1,n+1){
        adds(i, 1, 0);
        adds(i, a[i], 1);
    }

    rep(loop, q){
        int query, x;
        cin >> query >> x;
        if(query == 1){
            if(sums(x, 0) != sums(x+1, 0)){
                adds(x+1, -1, 0);
            }
        }
        if(query == 2){
            if(sums(x, 0) == sums(x+1, 0)){
                adds(x+1, 1, 0);
            }
        }
        if(query == 3){
            adds(x, 1, 1);
        }
        if(query == 4){
            ll tmp = sums(x, 0);
            int left, right;
            int l = 1, r = x;
            while(l < r){
                int m = (l + r) / 2;
                if(sums(m, 0) == tmp){
                    r = m;
                }else{
                    l = m + 1;
                }
            }
            left = l;
            l = x, r = n;
            while(l < r){
                int m = (l + r) / 2 + 1;
                if(sums(m, 0) == tmp){
                    l = m;
                }else{
                    r = m - 1;
                }
            }
            right = l;
            ll ans = sums(right, 1);
            if(left > 1){
                ans -= sums(left - 1, 1);
            }
            cout << ans << endl;
        }
    }


    return 0;
}
 
 
0