結果

問題 No.2281 K → K-1 01 Flip
ユーザー SSRSSSRS
提出日時 2023-04-21 22:15:31
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,278 bytes
コンパイル時間 1,855 ms
コンパイル使用メモリ 172,184 KB
実行使用メモリ 11,648 KB
最終ジャッジ日時 2024-04-24 08:21:48
合計ジャッジ時間 25,757 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 60 ms
8,192 KB
testcase_02 AC 532 ms
7,296 KB
testcase_03 AC 552 ms
10,752 KB
testcase_04 AC 131 ms
5,376 KB
testcase_05 AC 225 ms
8,192 KB
testcase_06 WA -
testcase_07 AC 123 ms
10,880 KB
testcase_08 AC 329 ms
11,008 KB
testcase_09 WA -
testcase_10 AC 407 ms
5,888 KB
testcase_11 WA -
testcase_12 AC 141 ms
10,368 KB
testcase_13 AC 501 ms
5,760 KB
testcase_14 AC 276 ms
8,320 KB
testcase_15 AC 122 ms
5,376 KB
testcase_16 AC 523 ms
7,552 KB
testcase_17 AC 589 ms
8,448 KB
testcase_18 AC 534 ms
6,656 KB
testcase_19 AC 245 ms
10,112 KB
testcase_20 AC 152 ms
5,376 KB
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 AC 9 ms
5,376 KB
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
testcase_37 WA -
testcase_38 WA -
testcase_39 WA -
testcase_40 WA -
testcase_41 WA -
testcase_42 WA -
testcase_43 WA -
testcase_44 WA -
testcase_45 WA -
testcase_46 WA -
testcase_47 WA -
testcase_48 WA -
testcase_49 WA -
testcase_50 WA -
testcase_51 WA -
testcase_52 WA -
testcase_53 WA -
testcase_54 WA -
testcase_55 WA -
testcase_56 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include <atcoder/segtree>
using namespace std;
int op(int x, int y){
  return max(x, y);
}
int e(){
  return 0;
}
int main(){
  int N, Q;
  cin >> N >> Q;
  string S;
  cin >> S;
  vector<int> sum(N + 1);
  sum[0] = 0;
  for (int i = 0; i < N; i++){
    if (S[i] == '0'){
      sum[i + 1] = sum[i] + 1;
    } else {
      sum[i + 1] = sum[i] - 1;
    }
  }
  set<int> st;
  st.insert(0);
  st.insert(N);
  for (int i = 1; i < N; i++){
    if (S[i] != S[i - 1]){
      st.insert(i);
    }
  }
  vector<int> c(N, 1);
  for (int i = 1; i < N; i++){
    if (S[i] == S[i - 1]){
      c[i] = c[i - 1] + 1;
    } else {
      c[i] = 1;
    }
  }
  atcoder::segtree<int, op, e> ST(c);
  for (int i = 0; i < Q; i++){
    int L, R, K;
    cin >> L >> R >> K;
    L--;
    auto itr = st.lower_bound(L);
    if (*itr >= R){
      cout << min(R - L, K - 1) << endl;
    } else {
      bool ok = false;
      if (*itr - L >= K){
        ok = true;
      }
      if (ST.prod(*itr, R) >= K){
        ok = true;
      }
      if (!ok){
        cout << R - L << endl;
      } else {
        int s = sum[R] - sum[L];
        s %= K * 2 - 1;
        s += K * 2 - 1;
        s %= K * 2 - 1;
        cout << min(max(s - 1, K * 2 - 2 - s), R - L) << endl;
      }
    }
  }
}
0