結果

問題 No.2933 Range ROT Query
ユーザー Kude
提出日時 2024-10-12 16:32:44
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 1,247 ms / 3,000 ms
コード長 2,561 bytes
コンパイル時間 3,555 ms
コンパイル使用メモリ 283,240 KB
実行使用メモリ 24,828 KB
最終ジャッジ日時 2024-10-12 16:33:20
合計ジャッジ時間 33,433 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 50
権限があれば一括ダウンロードができます

ソースコード

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>;

// add diff
struct S {
  bool v[26];
};

S op(S x, S y) {
  S res;
  rep(i, 26) res.v[i] = x.v[i] & y.v[i];
  return res;
}
S e() {
  S res;
  rep(i, 26) res.v[i] = true;
  return res;
}

int composition(int f, int g) { return f + g; }
int id() { return 0; }
S mapping(int f, S x) {
  f %= 26;
  if (f < 0) f += 26;
  if (f == 0) return x;
  rotate(x.v, x.v + f, x.v + 26);
  return x;
}


} int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  string s, t;
  cin >> s >> t;
  int q;
  cin >> q;
  int mx = max(s.size(), t.size());
  vector<S> init(mx);
  rep(i, mx) {
    S v;
    if (i >= ssize(s) || i >= ssize(t)) {
      rep(i, 26) v.v[i] = false;
    } else {
      rep(i, 26) v.v[i] = false;
      int diff = (t[i] - s[i] + 52) % 26;
      v.v[diff] = true;
    }
    init[i] = v;
  }
  lazy_segtree<S, op, e, int, mapping, composition, id> seg(init);
  fenwick_tree<int> add_s(ssize(s) + 1), add_t(ssize(t) + 1);
  while (q--) {
    int type;
    cin >> type;
    if (type == 1) {
      int l, r, x;
      cin >> l >> r >> x;
      l--;
      seg.apply(l, r, x);
      add_s.add(l, x);
      add_s.add(r, -x);
    } else if (type == 2) {
      int l, r, x;
      cin >> l >> r >> x;
      l--;
      seg.apply(l, r, -x);
      add_t.add(l, x);
      add_t.add(r, -x);
    } else {
      int p;
      cin >> p;
      p--;
      int r = seg.max_right(p, [](const S& s) {
        return s.v[0];
      });
      if (r == ssize(s)) {
        if (r == ssize(t)) {
          cout << "Equals\n";
        } else {
          cout << "Lesser\n";
        }
      } else if (r == ssize(t)) {
        cout << "Greater\n";
      } else {
        int sx = (s[r] - 'a' + add_s.sum(0, r + 1)) % 26;
        int tx = (t[r] - 'a' + add_t.sum(0, r + 1)) % 26;
        cout << (sx < tx ? "Lesser\n" : "Greater\n");
      }
    }
  }
}
0