結果

問題 No.2080 Simple Nim Query
ユーザー roarisroaris
提出日時 2022-09-25 22:49:14
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 346 ms / 3,000 ms
コード長 1,514 bytes
コンパイル時間 2,113 ms
コンパイル使用メモリ 202,488 KB
実行使用メモリ 4,628 KB
最終ジャッジ日時 2023-09-03 02:49:53
合計ジャッジ時間 5,657 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 238 ms
4,376 KB
testcase_04 AC 239 ms
4,376 KB
testcase_05 AC 334 ms
4,608 KB
testcase_06 AC 330 ms
4,624 KB
testcase_07 AC 326 ms
4,556 KB
testcase_08 AC 320 ms
4,552 KB
testcase_09 AC 328 ms
4,556 KB
testcase_10 AC 346 ms
4,628 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i=0; i<n; i++)
#define pb push_back
typedef long long ll;

struct BIT {
    int size;
    vector<int> node;
    
    BIT(int n) {
        size = n;
        node.resize(n+1);
    }
    
    void add(int i, int x) {
        i++;
        while (i<=size) {
            node[i] += x;
            i += i&(-i);
        }
    }
    
    int acc(int i) {
        int s = 0;
        while (i>0) {
            s += node[i];
            i -= i&(-i);
        }
        return s;
    }
};

int main() {
    cin.tie(0); ios::sync_with_stdio(false);
    
    int N, Q; cin >> N >> Q;
    int A[N]; 
    rep(i, N) {
        int x; cin >> x;
        A[i] = (x == 1 ? 1 : 0);
    }
    
    BIT bit(N);
    rep(i, N) bit.add(i, A[i]);
    
    while (Q--) {
        int T, X, Y; cin >> T >> X >> Y;
        
        if (T==1) {
            X--;
            bit.add(X, -A[X]);
            A[X] = (Y == 1 ? 1 : 0);
            bit.add(X, A[X]);
        } else {
            int l = 0;
            int r = Y-X+1;
            while (l<=r) {
                int m = (l+r)/2;
                int c = bit.acc(Y)-bit.acc(Y-m);
                if (c==m) l = m+1;
                else r = m-1;
            }
            if (r==Y-X+1) {
                if (r%2==0) cout << "S" << endl;
                else cout << "F" << endl;
            } else {
                if (r%2==0) cout << "F" << endl;
                else cout << "S" << endl;
            }
        }
    }
}
0