結果

問題 No.2080 Simple Nim Query
ユーザー ぷら
提出日時 2022-10-24 22:08:31
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 668 ms / 3,000 ms
コード長 1,075 bytes
コンパイル時間 2,080 ms
コンパイル使用メモリ 201,588 KB
最終ジャッジ日時 2025-02-08 12:27:11
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 8
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

int main() {
    int N,Q;
    cin >> N >> Q;
    vector<int>A(N);
    set<int>st;
    for(int i = 0; i < N; i++) {
        cin >> A[i];
        if(A[i] != 1) st.insert(i);
    }
    for(int i = 0; i < Q; i++) {
        int T,X,Y;
        cin >> T >> X >> Y;
        if(T == 1) {
            X--;
            if(A[X] != 1) {
                st.erase(X);
            }
            A[X] = Y;
            if(A[X] != 1) {
                st.insert(X);
            }
        }
        else {
            X--;
            Y--;
            if(st.empty()) {
                cout << (((Y-X)%2)?"S":"F") << endl;
                continue;
            }
            auto it = st.upper_bound(Y);
            if(it == st.begin()) {
                cout << (((Y-X)%2)?"S":"F") << endl;
                continue;
            }
            it--;
            if(X <= *it) {
                cout << (((Y-*it)%2)?"S":"F") << endl;
            }
            else {
                cout << (((Y-X)%2)?"S":"F") << endl;
            }
        }
    }
}
0