結果

問題 No.3317 ワロングアンサーロングアンサーンスワロンガー
コンテスト
ユーザー Kude
提出日時 2025-10-31 22:39:04
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 239 ms / 2,000 ms
コード長 2,478 bytes
コンパイル時間 3,382 ms
コンパイル使用メモリ 306,012 KB
実行使用メモリ 127,296 KB
最終ジャッジ日時 2025-11-01 10:01:26
合計ジャッジ時間 11,065 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 63
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
namespace {
#pragma GCC diagnostic ignored "-Wunused-function"
#include<atcoder/all>
#pragma GCC diagnostic warning "-Wunused-function"
using namespace std;
using namespace atcoder;
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(i,n) for(int i = (int)(n) - 1; i >= 0; i--)
#define all(x) begin(x), end(x)
#define rall(x) rbegin(x), rend(x)
template<class T> bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } else return false; }
template<class T> bool chmin(T& a, const T& b) { if (b < a) { a = b; return true; } else return false; }
using ll = long long;
using P = pair<int,int>;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<ll>;
using VVL = vector<VL>;
constexpr long long INF = 1002003004005006007;

} int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, q;
  string s;
  cin >> n >> q >> s;
  VL szs{1};
  rep(i, 60) {
    auto l = szs.back();
    szs.emplace_back(min(INF, l + (5LL << i)));
  }
  using Seg = segtree<ll, [](ll x, ll y) { return min(INF, x + y); }, []() { return 0; }>;
  using Segs = array<Seg, 60>;
  auto f = [&](const string& s) {
    int n = s.size();
    Segs seg;
    rep(t, 60) seg[t] = Seg([&]() {
      VL init(n);
      rep(i, n) init[i] = s[i] == 'a' || s[i] == 'w' ? szs[t] : 1;
      return init;
    }());
    return seg;
  };
  auto ss = f(s);
  auto sa = f("answer");
  auto sw = f("warong");
  rep(_, q) {
    ll t, x;
    cin >> t >> x;
    x--;
    chmin(t, 59LL);
    int state = 0;
    char ans = 0;
    rrep(tt, t + 1) {
      if (state == 0) {
        int r = ss[tt].max_right(0, [&](ll v) { return v <= x; });
        x -= ss[tt].prod(0, r);
        if (s[r] == 'a') state = 1;
        else if (s[r] == 'w') state = 2;
        else {
          ans = s[r];
          break;
        }
      } else if (state == 1) {
        int r = sa[tt].max_right(0, [&](ll v) { return v <= x; });
        x -= sa[tt].prod(0, r);
        if ("answer"[r] == 'a') state = 1;
        else if ("answer"[r] == 'w') state = 2;
        else {
          ans = "answer"[r];
          break;
        }
      } else {
        int r = sw[tt].max_right(0, [&](ll v) { return v <= x; });
        x -= sw[tt].prod(0, r);
        if ("warong"[r] == 'a') state = 1;
        else if ("warong"[r] == 'w') state = 2;
        else {
          ans = "warong"[r];
          break;
        }
      }
    }
    if (!ans) ans = "aw"[state - 1];
    cout << ans;
  }
  cout << '\n';
}
0