結果

問題 No.2308 [Cherry 5th Tune B] もしかして、真?
ユーザー srjywrdnprktsrjywrdnprkt
提出日時 2023-06-18 01:55:25
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 294 ms / 2,000 ms
コード長 1,744 bytes
コンパイル時間 3,493 ms
コンパイル使用メモリ 204,968 KB
実行使用メモリ 10,940 KB
最終ジャッジ日時 2023-09-07 20:39:56
合計ジャッジ時間 17,859 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,384 KB
testcase_01 AC 232 ms
5,928 KB
testcase_02 AC 264 ms
6,860 KB
testcase_03 AC 247 ms
7,260 KB
testcase_04 AC 242 ms
7,220 KB
testcase_05 AC 251 ms
7,488 KB
testcase_06 AC 262 ms
8,856 KB
testcase_07 AC 266 ms
8,572 KB
testcase_08 AC 265 ms
9,440 KB
testcase_09 AC 265 ms
9,572 KB
testcase_10 AC 250 ms
7,052 KB
testcase_11 AC 262 ms
7,368 KB
testcase_12 AC 264 ms
7,276 KB
testcase_13 AC 266 ms
7,228 KB
testcase_14 AC 259 ms
7,340 KB
testcase_15 AC 269 ms
7,568 KB
testcase_16 AC 258 ms
7,264 KB
testcase_17 AC 262 ms
7,400 KB
testcase_18 AC 260 ms
7,372 KB
testcase_19 AC 259 ms
7,312 KB
testcase_20 AC 260 ms
7,408 KB
testcase_21 AC 275 ms
10,832 KB
testcase_22 AC 279 ms
10,884 KB
testcase_23 AC 278 ms
10,940 KB
testcase_24 AC 278 ms
10,888 KB
testcase_25 AC 276 ms
10,796 KB
testcase_26 AC 283 ms
10,832 KB
testcase_27 AC 285 ms
10,840 KB
testcase_28 AC 278 ms
10,932 KB
testcase_29 AC 294 ms
10,888 KB
testcase_30 AC 289 ms
10,892 KB
testcase_31 AC 209 ms
10,836 KB
testcase_32 AC 212 ms
10,888 KB
testcase_33 AC 217 ms
10,704 KB
testcase_34 AC 235 ms
10,692 KB
testcase_35 AC 239 ms
10,772 KB
testcase_36 AC 233 ms
10,800 KB
testcase_37 AC 25 ms
4,380 KB
testcase_38 AC 269 ms
7,268 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: 関数 ‘void solve()’ 内:
main.cpp:82:18: 警告: ‘r2’ may be used uninitialized [-Wmaybe-uninitialized]
   82 |     cout << (X[r2] ? "True" : "False") << endl;
      |                  ^
main.cpp:51:30: 備考: ‘r2’ はここで定義されています
   51 |     int N, l, r, c, idx, l2, r2;
      |                              ^~

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;
using ll = long long;

//RSQ (0-indexed)
template<class T> struct BIT {
    vector<T> bit;
    int N;

    BIT (int n){
        N = n;
        bit.resize(N);
    }

    void add(int loc, T val){
        loc++;
        while(loc <= N){
            bit[loc-1] += val;
            loc += loc & -loc;
        }
    }

    T sum(int l, int r){
        T res = _sum(r) - _sum(l-1);
        return res;
    }

    T _sum(int r){
        r++;
        T res = 0;
        while(r > 0){
            res += bit[r-1];
            r -= r & -r;
        }
        return res;
    }
};

int f(int a, int b, string &op){
    if (op == "and") return a & b;
    else if (op == "or") return a | b;
    else if (op == "xor") return a ^ b;
    else{
        if (a) return b;
        else return 1;
    }
}

void solve(){
    int N, l, r, c, idx, l2, r2;
    cin >> N;
    string S;
    vector<int> X(N);
    vector<string> Y(N-1);
    BIT<int> tree(N);
    for (int i=0; i<N; i++){
        tree.add(i, 1);
    }
    for (int i=0; i<N; i++){
        cin >> S;
        X[i] = (S == "True" ? 1 : 0);
    }
    for (int i=0; i<N-1; i++) cin >> Y[i];
    for (int i=0; i<N-1; i++){
        cin >> idx;
        l=-1; r=N-1;
        while(r-l>1){
            c = (l+r)/2;
            if (tree.sum(0, c) >= idx) r=c;
            else l=c;
        }
        l2=-1; r2=N-1;
        while(r2-l2>1){
            c = (l2+r2)/2;
            if (tree.sum(0, c) >= idx+1) r2=c;
            else l2=c;
        }
        tree.add(r, -1);
        X[r2] = f(X[r], X[r2], Y[r]);
    }
    cout << (X[r2] ? "True" : "False") << endl;
}

int main(){

    int T;
    cin >> T;
    while(T){
        T--;
        solve();
    }

    return 0;
}
0