結果

問題 No.230 Splarraay スプラレェーイ
ユーザー machymachy
提出日時 2015-06-20 12:29:24
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 2,375 bytes
コンパイル時間 718 ms
コンパイル使用メモリ 79,996 KB
実行使用メモリ 9,144 KB
最終ジャッジ日時 2023-09-21 22:00:02
合計ジャッジ時間 14,896 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,384 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 TLE -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
#include <iomanip>
#include <map>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;

struct BitSet{
    vector<ULL> data;
    BitSet(int N){
        data = vector<ULL>(N, 0);
    }

    void write(int left, int right, int val){
        int lb = (left+64-1) / 64 * 64;
        int rb = right / 64 * 64;
        for(int i = lb; i < rb; i++){
            data[i/sizeof(ULL)] = (ULL)(-val);
        }
        for(int i = left; i < min(rb, lb); i++){
            setBit(i, val);
        }
        for(int i = max(left, rb); i < right; i++){
            setBit(i, val);
        }
    }

    int count(int left, int right) const{
        int ans = 0;
        int lb = (left+64-1) / 64 * 64;
        int rb = right / 64 * 64;
        for(int i = lb; i < rb; i++){
            ans += __builtin_popcountll(data[i]);
        }
        for(int i = left; i < min(rb, lb); i++){
            ans += getBit(i);
        }
        for(int i = max(left, rb); i < right; i++){
            ans += getBit(i);
        }
        return ans;
    }

    int getBit(int i) const{
        ULL v = data[i/64];
        return (v >> (i % 64) & 1);
    }

    void setBit(int i, int b){
        ULL v = data[i/64];
        v = (v & ~(1ULL << (i % 64))) | ((ULL)(b) << (i % 64));
        data[i/64] = (ULL)(v);
    }

    void print() const{
        for(int i = 0; i < data.size()*64; i++){
            cout << getBit(i);
        }
        cout << endl;
    }
};

int main(){
    LL N, Q;
    cin >> N >> Q;
    BitSet team_a(N);
    BitSet team_b(N);
    LL score_a = 0;
    LL score_b = 0;
    for(int i = 0; i < Q; i++){
        LL x, l, r;
        cin >> x >> l >> r;
        if(x == 0){
            LL cnt_a = team_a.count(l, r+1);
            LL cnt_b = team_b.count(l, r+1);
            if(cnt_a > cnt_b){
                score_a += cnt_a;
            }else if(cnt_b > cnt_a){
                score_b += cnt_b;
            }
        }
        if(x == 1){
            team_a.write(l, r+1, 1);
            team_b.write(l, r+1, 0);
        }
        if(x == 2){
            team_a.write(l, r+1, 0);
            team_b.write(l, r+1, 1);
        }
    }
    score_a += team_a.count(0, N);
    score_b += team_b.count(0, N);
    cout << score_a << " " << score_b << endl;
    return 0;
}
0