結果

問題 No.833 かっこいい電車
ユーザー chocoruskchocorusk
提出日時 2019-05-24 22:24:05
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 148 ms / 2,000 ms
コード長 1,834 bytes
コンパイル時間 1,213 ms
コンパイル使用メモリ 98,352 KB
実行使用メモリ 5,452 KB
最終ジャッジ日時 2023-09-14 20:52:58
合計ジャッジ時間 4,539 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 148 ms
4,384 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 1 ms
4,380 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 AC 99 ms
4,384 KB
testcase_11 AC 126 ms
4,856 KB
testcase_12 AC 40 ms
4,380 KB
testcase_13 AC 30 ms
4,380 KB
testcase_14 AC 98 ms
5,124 KB
testcase_15 AC 50 ms
4,376 KB
testcase_16 AC 38 ms
4,604 KB
testcase_17 AC 42 ms
4,380 KB
testcase_18 AC 117 ms
4,376 KB
testcase_19 AC 37 ms
4,484 KB
testcase_20 AC 11 ms
4,376 KB
testcase_21 AC 106 ms
4,376 KB
testcase_22 AC 63 ms
5,120 KB
testcase_23 AC 43 ms
4,656 KB
testcase_24 AC 64 ms
5,080 KB
testcase_25 AC 114 ms
4,432 KB
testcase_26 AC 46 ms
4,656 KB
testcase_27 AC 80 ms
4,376 KB
testcase_28 AC 61 ms
4,376 KB
testcase_29 AC 69 ms
4,376 KB
testcase_30 AC 62 ms
5,452 KB
testcase_31 AC 121 ms
4,480 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>
#define popcount __builtin_popcount
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
ll a[100010];
struct BIT{
    vector<ll> bit;
    int size;
    BIT(int n):size(n), bit(n+1, 0){}
    ll sum(int i){
        ll s=0;
        while(i>0){
            s+=bit[i];
            i-=(i&(-i));
        }
        return s;
    }
    void add(int i, ll x){
        while(i<=size){
            bit[i]+=x;
            i+=(i&(-i));
        }
    }
};
int main()
{
    int n, q; cin>>n>>q;
    BIT b(n), c(n);
    bool nuo[100010];
    fill(nuo, nuo+n, 1);
    for(int i=1; i<n; i++) c.add(i, 1);
    for(int i=1; i<=n; i++){
        cin>>a[i];
        b.add(i, a[i]);
    }
    for(int t=0; t<q; t++){
        int u, x; cin>>u>>x;
        if(u==1){
            if(nuo[x]){
                nuo[x]=0;
                c.add(x, -1);
            }
        }else if(u==2){
            if(!nuo[x]){
                nuo[x]=1;
                c.add(x, 1);
            }
        }else if(u==3){
            b.add(x, 1);
        }else{
            int l=1, r=x;
            while(l!=r){
                int m=(l+r)/2;
                if(c.sum(m-1)==c.sum(x-1)) r=m;
                else l=m+1;
            }
            int l0=l;
            l=x, r=n;
            while(l!=r){
                int m=(l+r+1)/2;
                if(c.sum(x-1)==c.sum(m-1)) l=m;
                else r=m-1;
            }
            int r0=r;
            cout<<b.sum(r0)-b.sum(l0-1)<<endl;
        }
    }
    return 0;
}
0