結果

問題 No.2080 Simple Nim Query
ユーザー momoyuumomoyuu
提出日時 2023-05-20 01:54:12
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,127 bytes
コンパイル時間 3,124 ms
コンパイル使用メモリ 248,384 KB
実行使用メモリ 6,048 KB
最終ジャッジ日時 2023-08-23 04:33:06
合計ジャッジ時間 6,883 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

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

template< typename T >
struct segtree{
    using F = function<T(T,T)>;
    int n;
    F f;
    T e;
    vector<T> data;
    /*
     * n:鬆らせ謨ー
     * f:貍皮ョ・     * e:蜊倅ス榊・
     */
    segtree(int n,F f,T e):f(f),e(e){
        this->n = 1;
        while(this->n<n) (this->n)<<=1;
        data.assign(2*(this->n),e);
    }

    void set(vector<T> &a){
        for(int i = 0;i<n;i++){
            data[i+n-1] = a[i];
        }
    }

    void set(int i,T x){
        data[i+n-1] = x;
    }

    void build(){
        for(int i = n - 2;i>=0;i--){
            data[i] = f(data[2*i+1],data[2*i+2]);
        }
    }

    void update(int i,T x){
        int ni = i + n - 1;
        data[ni] = x;
        while(ni>0){
            ni = (ni-1)/2;
            data[ni] = f(data[2*ni+1],data[2*ni+2]);
        }
    }

    T query(int a,int b){
        T ans = e;
        a += n-1;
        b--;b += n-1;
        while(a>=0&&b>=0&&a<=b){
            if(a==b){
                ans = f(ans,data[a]);
                break;
            }
            if(!(a&1))ans = f(ans,data[a]);
            if(b&1)ans = f(ans,data[b]);
            a++;b--;
            a = (a-1)/2;b = (b-1)/2;
        }
        return ans;
    }

    T operator[](const int i) const {
        return data[i+n-1];
    }
};

int cmp(int a,int b){return a*b;}
int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n,q;
    cin>>n>>q;
    segtree<int> seg(n,cmp,1);
    vector<int> a(n);
    for(int i = 0;i<n;i++) cin>>a[i];
    for(int i = 0;i<n;i++) seg.update(i,(a[i]%2?-1:1));
    while(q--){
        int op;
        cin>>op;
        if(op==1){
            int x,y;
            cin>>x>>y;
            x--;
            a[x] = y;
            seg.update(x,(a[x]%2?-1:1));
        }else{
            int l,r;
            cin>>l>>r;
            l--;r--;
            int now = 1;
            now *= seg.query(l+1,r+1);
            if(now==1){
                cout<<"F"<<endl;
            }else{
                cout<<"S"<<endl;
            }
        }
    }
}



0