Submission #833202

#TimeUsernameProblemLanguageResultExecution timeMemory
833202maomao90Crossing (JOI21_crossing)C++17
100 / 100
249 ms18136 KiB

// Hallelujah, praise the one who set me free
// Hallelujah, death has lost its grip on me
// You have broken every chain, There's salvation in your name
// Jesus Christ, my living hope
#include <bits/stdc++.h> 
using namespace std;

#define REP(i, s, e) for (int i = (s); i < (e); i++)
#define RREP(i, s, e) for (int i = (s); i >= (e); i--)
template <class T>
inline bool mnto(T& a, T b) {return a > b ? a = b, 1 : 0;}
template <class T>
inline bool mxto(T& a, T b) {return a < b ? a = b, 1: 0;}

typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
#define FI first
#define SE second
typedef pair<int, int> ii;
typedef pair<ll, ll> pll;
typedef tuple<int, int, int> iii;
#define ALL(_a) _a.begin(), _a.end()
#define SZ(_a) (int) _a.size()
#define pb push_back
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<ii> vii;
typedef vector<iii> viii;

#ifndef DEBUG
#define cerr if (0) cerr
#endif

const int INF = 1000000005;
const ll LINF = 1000000000000000005ll;
const int MAXN = 200005;
const ll MOD = 998244353998244393;

#define submod(x) if (x >= MOD) x -= MOD
#define addmod(x) if (x < 0) x += MOD

int key[100];

int n;
ll pw[MAXN], pfxpw[MAXN];
set<string> st, nst;
set<ll> gd;
int q;
string t;

ll v[MAXN * 4];
int lz[MAXN * 4];
#define MLR int mid = lo + hi >> 1, lc = u << 1, rc = u << 1 ^ 1
void apply(int x, int u, int lo, int hi) {
    lz[u] = x;
    ll tmp = pfxpw[hi] - (lo == 0 ? 0 : pfxpw[lo - 1]);
    addmod(tmp);
    v[u] = tmp * x % MOD;
}
void propo(int u, int lo, int hi) {
    if (lz[u] == -1) {
        return;
    }
    MLR;
    apply(lz[u], lc, lo, mid);
    apply(lz[u], rc, mid + 1, hi);
    lz[u] = -1;
}
void init(int u = 1, int lo = 0, int hi = n - 1) {
    lz[u] = -1;
    if (lo == hi) {
        v[u] = key[t[lo]] * pw[lo] % MOD;
    } else {
        MLR;
        init(lc, lo, mid);
        init(rc, mid + 1, hi);
        v[u] = v[lc] + v[rc];
        submod(v[u]);
    }
}
void upd(int s, int e, int x, int u = 1, int lo = 0, int hi = n - 1) {
    if (lo >= s && hi <= e) {
        apply(x, u, lo, hi);
        return;
    }
    MLR;
    propo(u, lo, hi);
    if (s <= mid) {
        upd(s, e, x, lc, lo, mid);
    }
    if (e > mid) {
        upd(s, e, x, rc, mid + 1, hi);
    }
    v[u] = v[lc] + v[rc];
    submod(v[u]);
}

int main() {
    key['J'] = 0; key['O'] = 1; key['I'] = 2;
#ifndef DEBUG
    ios::sync_with_stdio(0), cin.tie(0);
#endif
    cin >> n;
    pw[0] = pfxpw[0] = 1;
    REP (i, 1, n + 1) {
        pw[i] = pw[i - 1] * 3 % MOD;
        pfxpw[i] = pw[i] + pfxpw[i - 1];
        submod(pfxpw[i]);
    }
    REP (i, 0, 3) {
        string s; cin >> s;
        st.insert(s);
    }
    while (1) {
        for (string a : st) {
            for (string b : st) {
                string c = a;
                REP (i, 0, n) {
                    if (a[i] == b[i]) {
                        c[i] = a[i];
                    } else {
                        c[i] = 'J' + 'O' + 'I' - a[i] - b[i];
                    }
                }
                nst.insert(c);
            }
        }
        if (SZ(nst) == SZ(st)) {
            break;
        }
        swap(st, nst);
    }
    for (string s : st) {
        ll hsh = 0;
        REP (i, 0, n) {
            hsh = (hsh + key[s[i]] * pw[i]) % MOD;
        }
        gd.insert(hsh);
    }
    cin >> q;
    cin >> t;
    init();
    if (gd.find(v[1]) != gd.end()) {
        cout << "Yes\n";
    } else {
        cout << "No\n";
    }
    while (q--) {
        int l, r; char c; cin >> l >> r >> c;
        l--; r--;
        upd(l, r, key[c]);
        if (gd.find(v[1]) != gd.end()) {
            cout << "Yes\n";
        } else {
            cout << "No\n";
        }
    }
    return 0;
}

Compilation message (stderr)

Main.cpp: In function 'void propo(int, int, int)':
Main.cpp:55:26: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   55 | #define MLR int mid = lo + hi >> 1, lc = u << 1, rc = u << 1 ^ 1
      |                       ~~~^~~~
Main.cpp:66:5: note: in expansion of macro 'MLR'
   66 |     MLR;
      |     ^~~
Main.cpp: In function 'void init(int, int, int)':
Main.cpp:74:25: warning: array subscript has type 'char' [-Wchar-subscripts]
   74 |         v[u] = key[t[lo]] * pw[lo] % MOD;
      |                         ^
Main.cpp:55:26: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   55 | #define MLR int mid = lo + hi >> 1, lc = u << 1, rc = u << 1 ^ 1
      |                       ~~~^~~~
Main.cpp:76:9: note: in expansion of macro 'MLR'
   76 |         MLR;
      |         ^~~
Main.cpp: In function 'void upd(int, int, int, int, int, int)':
Main.cpp:55:26: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   55 | #define MLR int mid = lo + hi >> 1, lc = u << 1, rc = u << 1 ^ 1
      |                       ~~~^~~~
Main.cpp:88:5: note: in expansion of macro 'MLR'
   88 |     MLR;
      |     ^~~
Main.cpp: In function 'int main()':
Main.cpp:138:34: warning: array subscript has type 'char' [-Wchar-subscripts]
  138 |             hsh = (hsh + key[s[i]] * pw[i]) % MOD;
      |                                  ^
Main.cpp:153:23: warning: array subscript has type 'char' [-Wchar-subscripts]
  153 |         upd(l, r, key[c]);
      |                       ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...