제출 #950528

#제출 시각아이디문제언어결과실행 시간메모리
950528glebustimCrossing (JOI21_crossing)C++17
26 / 100
248 ms20956 KiB
#include <bits/extc++.h> using namespace std; using namespace __gnu_pbds; #define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0) #define all(a) a.begin(), a.end() using ll = long long; using ld = long double; using pii = pair<int, int>; using vi = vector<int>; using oset = tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>; struct node { ll h = 0; int push = -1; }; const ll MOD = 1e18 + 3, P = 7; const int R = (1 << 18); const vector<array<int, 3>> o = {{0, 0, 1}, {0, 1, 0}, {1, 0, 0}, {0, 2, 2}, {2, 0, 2}, {2, 2, 0}, {1, 1, 2}, {1, 2, 1}, {2, 1, 1}}; vector<ll> pw(R + 1), pr(R + 1); vector<node> t(R * 2); int n; vi A, B, C; unordered_set<ll> ps; void all_combs() { for (auto x: o) { ll h = 0; for (int i = 0; i < n; ++i) { int y = (A[i] * x[0] + B[i] * x[1] + C[i] * x[2]) % 3; h = ((__int128)h * P + y + 1) % MOD; } ps.insert((__int128)h * pw[R - n] % MOD); } } void push(int v, int len) { if (t[v].push != -1) { t[v << 1].h = (__int128)pr[len - 1] * (t[v].push + 1) % MOD; t[v << 1].push = t[v].push; t[(v << 1) ^ 1].h = (__int128)pr[len - 1] * (t[v].push + 1) % MOD; t[(v << 1) ^ 1].push = t[v].push; t[v].push = -1; } } void update(int ql, int qr, int x, int v = 1, int l = 0, int r = R) { if (ql >= r || l >= qr) return; if (ql <= l && r <= qr) { t[v].h = (__int128)pr[r - l - 1] * (x + 1) % MOD; t[v].push = x; return; } int m = (l + r) / 2; push(v, m - l); update(ql, qr, x, (v << 1), l, m); update(ql, qr, x, ((v << 1) ^ 1), m, r); t[v].h = ((__int128)t[v << 1].h * pw[m - l] + t[(v << 1) ^ 1].h) % MOD; } int get_num(char c) { if (c == 'J') return 0; else if (c == 'O') return 1; else return 2; } void check_string() { if (ps.find(t[1].h) != ps.end()) cout << "Yes\n"; else cout << "No\n"; } int main() { fast; pw[0] = 1; pr[0] = 1; for (int i = 1; i <= R; ++i) { pw[i] = (__int128)pw[i - 1] * P % MOD; pr[i] = (pr[i - 1] + pw[i]) % MOD; } cin >> n; A.resize(n); B.resize(n); C.resize(n); string s; cin >> s; for (int i = 0; i < n; ++i) A[i] = get_num(s[i]); cin >> s; for (int i = 0; i < n; ++i) B[i] = get_num(s[i]); cin >> s; for (int i = 0; i < n; ++i) C[i] = get_num(s[i]); all_combs(); int q; cin >> q >> s; for (int i = 0; i < n; ++i) t[R + i].h = get_num(s[i]) + 1; vi len(R); len[0] = R; for (int i = 1; i < R; ++i) len[i] = len[i >> 1] / 2; for (int i = R - 1; i > 0; --i) t[i].h = ((__int128)t[i << 1].h * pw[len[i]] + t[(i << 1) ^ 1].h) % MOD; check_string(); while (q--) { int l, r; char c; cin >> l >> r >> c; --l; update(l, r, get_num(c)); check_string(); } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...