結果

問題 No.2080 Simple Nim Query
ユーザー ripityripity
提出日時 2022-10-30 10:24:22
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 481 ms / 3,000 ms
コード長 936 bytes
コンパイル時間 2,050 ms
コンパイル使用メモリ 202,608 KB
実行使用メモリ 4,756 KB
最終ジャッジ日時 2023-09-03 02:51:28
合計ジャッジ時間 6,415 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 287 ms
4,376 KB
testcase_04 AC 304 ms
4,376 KB
testcase_05 AC 481 ms
4,716 KB
testcase_06 AC 438 ms
4,624 KB
testcase_07 AC 442 ms
4,756 KB
testcase_08 AC 430 ms
4,640 KB
testcase_09 AC 426 ms
4,700 KB
testcase_10 AC 427 ms
4,576 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include <atcoder/fenwicktree>
using namespace std;
using namespace atcoder;
int main() {
  int N, Q;
  cin >> N >> Q;
  vector<int> A(N);
  fenwick_tree<int> fw(N);
  for( int i = 0; i < N; i++ ) {
    cin >> A[i];
    A[i] = ( A[i] == 1 );
    fw.add(i, A[i]);
  }
  for( int q = 0; q < Q; q++ ) {
    int T, X, Y;
    cin >> T >> X >> Y;
    if( T == 1 ) {
      X--;
      Y = ( Y == 1 );
      if( A[X] == 0 && Y == 1 ) fw.add(X, 1);
      else if( A[X] == 1 && Y == 0 ) fw.add(X, -1);
      A[X] = Y;
    }else {
      X--;
      Y--;
      int l = X, r = Y+1, m;
      while( l < r ) {
        m = (l+r)>>1;
        if( fw.sum(m, Y+1) != Y+1-m ) l = m+1;
        else r = m;
      }
      int k = Y+1-l;
      if( l == X ) {
        if( k&1 ) cout << 'F' << '\n';
        else cout << 'S' << '\n';
      }else {
        if( k&1 ) cout << 'S' << '\n';
        else cout << 'F' << '\n';
      }
    }
  }
}
0