結果

問題 No.833 かっこいい電車
ユーザー Yumeno UkihashiYumeno Ukihashi
提出日時 2019-05-24 21:49:55
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 100 ms / 2,000 ms
コード長 1,855 bytes
コンパイル時間 1,611 ms
コンパイル使用メモリ 174,728 KB
実行使用メモリ 8,944 KB
最終ジャッジ日時 2023-09-14 20:49:40
合計ジャッジ時間 4,453 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 51 ms
6,588 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 3 ms
4,376 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 3 ms
4,380 KB
testcase_09 AC 2 ms
4,504 KB
testcase_10 AC 71 ms
6,844 KB
testcase_11 AC 100 ms
8,128 KB
testcase_12 AC 28 ms
5,848 KB
testcase_13 AC 19 ms
4,904 KB
testcase_14 AC 79 ms
8,224 KB
testcase_15 AC 38 ms
6,672 KB
testcase_16 AC 32 ms
7,336 KB
testcase_17 AC 22 ms
4,600 KB
testcase_18 AC 84 ms
7,188 KB
testcase_19 AC 32 ms
7,040 KB
testcase_20 AC 9 ms
5,200 KB
testcase_21 AC 64 ms
5,700 KB
testcase_22 AC 57 ms
8,548 KB
testcase_23 AC 38 ms
7,036 KB
testcase_24 AC 55 ms
8,292 KB
testcase_25 AC 79 ms
6,584 KB
testcase_26 AC 39 ms
7,500 KB
testcase_27 AC 59 ms
6,880 KB
testcase_28 AC 40 ms
5,524 KB
testcase_29 AC 48 ms
6,304 KB
testcase_30 AC 86 ms
8,944 KB
testcase_31 AC 49 ms
6,672 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
#define REP(x,y,z) for(int x=y;x<=z;x++)
#define MSET(x,y) memset(x,y,sizeof(x))
#define M 100005
using namespace std;
using LL = long long;
using P = pair<int,int>;
int n,q;
LL tree[M];
int low(int x) { return x&-x; }
void add(int x,int v) {
    for (int i=x; i<=n; i+=low(i))
        tree[i] += v;
}
LL ask(int x) {
    LL res = 0;
    for (int i=x; i>0; i-=low(i))
        res += tree[i];
    return res;
}
LL ask(int x,int y) {
    return ask(y) - ask(x-1);
}
int main()
{
    set<P> s;
    while (~scanf("%d %d", &n, &q)) {
        s.clear();
        MSET(tree, 0);
        REP(i,1,n) {
            int x;
            scanf("%d", &x);
            add(i, x);
        }
        REP(i,1,n) s.insert( make_pair(i,i) );

        auto find_seg = [&](int x) {
            auto it = s.upper_bound( make_pair(x+1, -1) );
            if (it==s.begin()) return make_pair(-1, -1);
            --it;
            return *it;
        };

        REP(i,1,q) {
            int x,y;
            scanf("%d %d",&x,&y);
            if (x==1) {
                auto seg = find_seg(y);
                auto seg2 = find_seg(y+1);
                if (seg!=seg2) {
                    s.erase(seg);
                    s.erase(seg2);
                    s.insert(make_pair(seg.first, seg2.second));
                }
            }
            if (x==2) {
                auto seg = find_seg(y);
                if (y+1 <= seg.second) {
                    s.erase(seg);
                    s.insert(make_pair(seg.first, y));
                    s.insert(make_pair(y+1, seg.second));
                }
            }
            if (x==3) {
                add(y, 1);
            }
            if (x==4) {
                auto seg = find_seg(y);
                printf("%lld\n", ask(seg.first, seg.second));
            }
        }
    }
    return 0;
}
0