結果

問題 No.2933 Range ROT Query
ユーザー t98slider
提出日時 2024-10-12 16:47:38
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
TLE  
実行時間 -
コード長 5,212 bytes
コンパイル時間 4,486 ms
コンパイル使用メモリ 259,316 KB
最終ジャッジ日時 2025-02-24 18:41:49
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 10 TLE * 1 -- * 39
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;

template<const long long MOD = 2305843009213693951, 
        const long long MASK31 = (1ll << 31) - 1, const long long MASK30 = (1ll << 30) - 1>
struct modint61 {
    using mint = modint61;
    long long v;
    modint61() : v(0) {}
    template<class T> modint61(T x) { 
        while(x < 0) x += MOD;
        while(x >= MOD) x -= MOD;
        v = x;
    }
    long long safe_mod(long long x){
        x = (x >> 61) + (x & MOD);
        if (x >= MOD) x -= MOD;
        return x;
    }
    static constexpr long long mod() { return MOD; }
    mint& operator++() {v++; if(v == MOD)v = 0; return *this;}
    mint& operator--() {if(v == 0)v = MOD; v--; return *this;}
    mint operator++(int) { mint result = *this; ++*this; return result; }
    mint operator--(int) { mint result = *this; --*this; return result; }
    mint& operator+=(const mint& rhs) { v += rhs.v; if(v >= MOD) v -= MOD; return *this; }
    mint& operator-=(const mint& rhs) { if(v < rhs.v) v += MOD; v -= rhs.v; return *this; }
    mint& operator*=(const mint& rhs) {
        long long u = v >> 31, d = v & MASK31;
        long long ru = rhs.v >> 31, rd = rhs.v & MASK31;
        long long mid = d * ru + u * rd;
        v = safe_mod(u * ru * 2 + (mid >> 30) + ((mid & MASK30) << 31) + d * rd);
        return *this;
    }
    mint& operator/=(const mint& rhs) { return *this = *this * rhs.inv(); }
    mint operator+() const { return *this; }
    mint operator-() const { return mint() - *this; }
    mint pow(long long n) const {
        assert(0 <= n);
        mint r = 1, x = *this;
        while (n) {
            if (n & 1) r *= x;
            x *= x;
            n >>= 1;
        }
        return r;
    }
    mint inv() const { assert(v); return pow(MOD - 2); }
    friend mint operator+(const mint& lhs, const mint& rhs) { return mint(lhs) += rhs; }
    friend mint operator-(const mint& lhs, const mint& rhs) { return mint(lhs) -= rhs; }
    friend mint operator*(const mint& lhs, const mint& rhs) { return mint(lhs) *= rhs; }
    friend mint operator/(const mint& lhs, const mint& rhs) { return mint(lhs) /= rhs; }
    friend bool operator<(const mint& lhs, const mint& rhs) { return lhs.v < rhs.v; }
    friend bool operator==(const mint& lhs, const mint& rhs) { return (lhs.v == rhs.v); }
    friend bool operator!=(const mint& lhs, const mint& rhs) { return (lhs.v != rhs.v); }
    friend std::istream& operator >> (std::istream& is, mint& rhs) noexcept {
        long long tmp;
        rhs = mint{(is >> tmp, tmp)};
        return is;
    }
    friend std::ostream& operator << (std::ostream &os, const mint& rhs) noexcept { return os << rhs.v; }
};
using mint61 = modint61<2305843009213693951>;

using S = array<mint61, 27>;
S op(S lhs, S rhs){
    S tmp{};
    for(int i = 0; i < 26; i++){
        tmp[i] = lhs[i] * rhs[26] + rhs[i];
    }
    tmp[26] = lhs[26] * rhs[26];
    return tmp;
}
S e(){
    S tmp{};
    tmp[26] = 1;
    return tmp;
}
using F = int;
// x に f を作用させた時の変化
S mapping(F f, S x){
    while(f >= 26) f -= 26;
    if(f == 0) return x;
    rotate(x.begin(), x.begin() + f, x.begin() + 26);
    return x;
}
// bf を作用させた後に af を作用させる
F composition(F af, F bf){
    af += bf;
    if(af >= 26) af -= 26;
    return af;
}
// 恒等写像
F id(){return 0;}


int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    string s, t;
    cin >> s >> t;
    int n = s.size(), m = t.size();
    vector<S> tmps(n), tmpt(m);
    mint61 base = 1145141919810;
    for(int i = 0; i < n; i++){
        int v = s[i] - 'a';
        for(int j = 0; j < 26; j++){
            tmps[i][j] = (v + j) % 26 + 'a';
        }
        tmps[i][26] = base;
    }
    for(int i = 0; i < m; i++){
        int v = t[i] - 'a';
        for(int j = 0; j < 26; j++){
            tmpt[i][j] = (v + j) % 26 + 'a';
        }
        tmpt[i][26] = base;
    }
    atcoder::lazy_segtree<S, op, e, F, mapping, composition, id> seg1(tmps), seg2(tmpt);
    int Q;
    cin >> Q;
    while(Q--){
        int cmd;
        cin >> cmd;
        if(cmd <= 2){
            int l, r, x;
            cin >> l >> r >> x;
            l--;
            if(cmd == 1){
                seg1.apply(l, r, x);
            }else{
                seg2.apply(l, r, x);
            }
        }else{
            int p;
            cin >> p;
            p--;
            int ok = p, ng = min(n, m) + 1;
            while(ok + 1 < ng){
                int mid = (ok + ng) / 2;
                (seg1.prod(p, mid)[0] == seg2.prod(p, mid)[0] ? ok : ng) = mid;
            } 
            if(ok == n && ok == m){
                cout << "Equals" << '\n';
            }else if(ok == n){
                cout << "Lesser" << '\n';
            }else if(ok == m){
                cout << "Greater\n";
            }else{
                char c1 = seg1.get(ok)[0].v;
                char c2 = seg2.get(ok)[0].v;
                if(c1 == c2){
                    cout << "Equals\n";
                }else if(c1 < c2){
                    cout << "Lesser\n";
                }else{
                    cout << "Greater\n";
                }
            }
        }
    }
}
0