結果

問題 No.833 かっこいい電車
ユーザー koyoprokoyopro
提出日時 2020-01-11 00:19:23
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 3,619 bytes
コンパイル時間 1,630 ms
コンパイル使用メモリ 163,504 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-05-03 02:07:14
合計ジャッジ時間 5,308 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 414 ms
6,812 KB
testcase_01 AC 2 ms
6,940 KB
testcase_02 AC 2 ms
6,940 KB
testcase_03 WA -
testcase_04 AC 2 ms
6,944 KB
testcase_05 AC 2 ms
6,944 KB
testcase_06 AC 2 ms
6,940 KB
testcase_07 AC 1 ms
6,940 KB
testcase_08 AC 2 ms
6,944 KB
testcase_09 AC 1 ms
6,940 KB
testcase_10 AC 29 ms
6,944 KB
testcase_11 AC 37 ms
6,944 KB
testcase_12 AC 11 ms
6,940 KB
testcase_13 AC 9 ms
6,944 KB
testcase_14 AC 29 ms
6,944 KB
testcase_15 AC 15 ms
6,940 KB
testcase_16 AC 12 ms
6,940 KB
testcase_17 AC 11 ms
6,940 KB
testcase_18 AC 34 ms
6,944 KB
testcase_19 AC 12 ms
6,940 KB
testcase_20 AC 4 ms
6,940 KB
testcase_21 AC 29 ms
6,940 KB
testcase_22 AC 19 ms
6,940 KB
testcase_23 AC 13 ms
6,944 KB
testcase_24 AC 19 ms
6,940 KB
testcase_25 AC 34 ms
6,940 KB
testcase_26 AC 15 ms
6,940 KB
testcase_27 AC 24 ms
6,944 KB
testcase_28 AC 17 ms
6,940 KB
testcase_29 AC 20 ms
6,940 KB
testcase_30 AC 44 ms
6,944 KB
testcase_31 AC 420 ms
6,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include "bits/stdc++.h"
using namespace std;
#define int long long
#define FOR(i, a, b) for(int i=(a);i<(b);i++)
#define RFOR(i, a, b) for(int i=(b-1);i>=(a);i--)
#define REP(i, n) for(int i=0; i<(n); i++)
#define RREP(i, n) for(int i=(n-1); i>=0; i--)
#define ALL(a) (a).begin(),(a).end()
#define UNIQUE_SORT(l) sort(ALL(l)); l.erase(unique(ALL(l)), l.end());
#define CONTAIN(a, b) find(ALL(a), (b)) != (a).end()
#define array2(type, x, y) array<array<type, y>, x>
#define vector2(type) vector<vector<type> >
#define out(...) printf(__VA_ARGS__)

int dxy[] = {0, 1, 0, -1, 0};

void solve();
signed main()
{
#if DEBUG
    std::ifstream in("input.txt");
    std::cin.rdbuf(in.rdbuf());
#endif
    cin.tie(0);
    ios::sync_with_stdio(false);
    solve();
    return 0;
}

/*================================*/

int N,M,Q;


/********************************
 *
 * 平方分割
 *
 *******************************/
class SumCal {
    vector<int> S; // 少ない方
    vector<int> T; // 多い方
    int K;
    
public:
    SumCal(int size) {
        K = sqrt(size);
        T = vector<int>(size, 0);
        S = vector<int>(size/K+1, 0);
    }
    
    int query(int l, int r) {
        int ret = 0;
        while(l < r) {
            int lk = l / K;
            int rk = r / K;
            if (lk == rk) {
                FOR(j, l, r) {
                    ret += T[j];
                }
            }
            else if (l % K == 0) {
                ret += S[lk];
            }
            else {
                FOR(j, l, (lk+1)*K) {
                    ret += T[j];
                }
            }
            l = (lk+1)*K;
        }
        return ret;
    }
    
    void add(int l, int w) {
        T[l]+=w;
        S[l/K]+=w;
    }
};


/********************************
 *
 * 平方分割
 *
 *******************************/
class JointCal {
    vector<int> S; // 少ない方
    vector<int> T; // 多い方
    int K;
    int size;
    
public:
    JointCal(int size): size(size) {
        K = sqrt(size);
        T = vector<int>(size, 0);
        S = vector<int>(size/K+1, 0);
    }
    
    int left(int i) {
        i--;
        if (!T[i]) return i+1;
        while(i >= 0 && T[i]) {
            int ik = i / K;
            if (S[ik]) {
                if (ik == 0) return 0;
                i = (ik-1)*K;
                continue;
            }
            i--;
        }
        return i+1;
    }
    
    int right(int i) {
        if (!T[i]) return i;
        while(T[i]) {
            int ik = i / K;
            if (S[ik]) {
                if (ik == S.size()-1) return size-1;
                i = (ik+1)*K;
                continue;
            }
            i++;
        }
        return i;
    }
    
    void set(int l, int w) {
        T[l]=w;
        int kw = 1;
        int base = l/K * K;
        REP(i,K) kw &= T[base+i];
        S[l / K]=kw;
    }
};

void solve() {
    cin>>N>>Q;
    int a;
    auto A = SumCal(N); // かっこよさ
    auto J = JointCal(N); // Joint
    REP(i,N) {
        cin>>a;
        A.add(i, a);
    }
    int q,x;
    REP(i,Q) {
        cin>>q>>x;
        x--;
        switch (q) {
            case 1:
                J.set(x, 1);
                break;
            case 2:
                J.set(x, 0);
                break;
            case 3:
                A.add(x, 1);
                break;
            default:
                int l = J.left(x);
                int r = J.right(x);
//                out("%lld x %lld = ", l, r);
                out("%lld\n", A.query(l, r+1));
                break;
        }
    }
    
    //cout << ans << endl;
}
0