#include<bits/stdc++.h>
#include<unordered_map>
#define rep(i,a,b) for(int i=int(a);i<int(b);i++)
#define rrep(i,a,b) for(int i=int(a);i>int(b);i--)
#define trav(a,v) for(auto& a: v)
#define sz(v) v.size()
#define all(v) v.begin(),v.end()
#define vi vector<int>
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
//const long long inf = 1e15;
using namespace std;
/**
* Author: Simon Lindholm
* Date: 2016-10-08
* License: CC0
* Source: me
* Description: Segment tree with ability to add or set values of large intervals, and compute max of intervals.
* Can be changed to other things.
* Use with a bump allocator for better performance, and SmallPtr or implicit indices to save memory.
* Time: O(\log N).
* Usage: Node* tr = new Node(v, 0, sz(v));
* Status: stress-tested a bit
*/
const int inf = 1e9;
struct Node {
Node* l = 0, * r = 0;
ull lo, hi, mset = inf, madd = 1, val = 0, val0 = 0;
Node(int lo, int hi) :lo(lo), hi(hi) {} // Large interval of -inf
Node(vector<ull>& v, int lo, int hi) : lo(lo), hi(hi) {
if (lo + 1 < hi) {
int mid = lo + (hi - lo) / 2;
l = new Node(v, lo, mid); r = new Node(v, mid, hi);
val = l->val + r->val;
val0 = l->val + r->val;
}
else val = val0 = v[lo];
}
ull query(int L, int R) {
if (R <= lo || hi <= L) return 0;
if (L <= lo && hi <= R) return val;
push();
return l->query(L, R) + r->query(L, R);
}
void set(int L, int R, int x) {
if (R <= lo || hi <= L) return;
if (L <= lo && hi <= R) mset = val = x, madd = 1;
else {
push(), l->set(L, R, x), r->set(L, R, x);
val = l->val + r->val;
}
}
void add(int L, int R, ull x) {
if (R <= lo || hi <= L) return;
if (L <= lo && hi <= R) {
madd = 1;
val = val0;
if (mset != inf) mset += x;
else madd *= x;
val *= x;
}
else {
push(), l->add(L, R, x), r->add(L, R, x);
val = l->val + r->val;
}
}
void push() {
if (!l) {
int mid = lo + (hi - lo) / 2;
l = new Node(lo, mid); r = new Node(mid, hi);
}
if (mset != inf)
l->set(lo, hi, mset), r->set(lo, hi, mset), mset = inf;
else if (madd != 1)
l->add(lo, hi, madd), r->add(lo, hi, madd), madd = 1;
}
};
int main() {
cin.sync_with_stdio(false);
ll n;
cin >> n;
string a, b, c;
cin >> a >> b >> c;
srand(n);
vector<ull> primes = { 37,41,43,47,53,59,61,67,71,73,79,83,89,97,101,103,107,109,113,127,131,137,139,149,151,157,163,167,173,179,181,191,193,197 };
ull C = primes[rand() % primes.size()];
vector<ull> hashed(n);
hashed[0] = 1;
ll MOD = 1000000007;
vector<ull> vec;
rep(i, 1, n) {
hashed[i] = (hashed[i - 1] * C) % MOD;
}
ull val = 0;
rep(i, 0, n)val += hashed[i] * a[i];
vec.push_back(val);
val = 0;
rep(i, 0, n)val += hashed[i] * b[i];
vec.push_back(val);
rep(i, 0, n)val += hashed[i] * c[i];
vec.push_back(val);
queue < string> qu;
qu.push(a);
qu.push(b);
qu.push(c);
vector<string> exists;
exists.push_back(a);
exists.push_back(b);
exists.push_back(c);
while (!qu.empty()) {
string cur = qu.front();
qu.pop();
rep(i, 0, exists.size()) {
string nxt = "";
if (exists[i] == cur)continue;
rep(j, 0, cur.size()) {
if (cur[j] == exists[i][j])nxt += cur[j];
else if (cur[j] == 'J') {
if (exists[i][j] == 'O')nxt += 'I';
else nxt += 'O';
}
else if (cur[j] == 'O') {
if (exists[i][j] == 'J')nxt += 'I';
else nxt += 'J';
}
else if (cur[j] == 'I') {
if (exists[i][j] == 'O')nxt += 'J';
else nxt += 'O';
}
}
val = 0;
rep(i, 0, n)val += hashed[i] * nxt[i];
if (find(all(vec), val) == vec.end()) {
vec.push_back(val);
exists.push_back(nxt);
}
}
}
ll q;
cin >> q;
string t;
cin >> t;
Node* tree = new Node(hashed, 0, n);
rep(i, 0, n)tree->add(i, i + 1, t[i]);
bool done = false;
trav(a, vec)done = done || (tree->query(0, n) == a);
cout << (done ? "Yes" : "No") << endl;
rep(i, 0, q) {
ll A, B;
char d;
cin >> A >> B >> d;
tree->add(A - 1, B, d);
done = false;
trav(a, vec)done = done || (tree->query(0, n) == a);
cout << (done ? "Yes" : "No") << endl;
}
return 0;
}
Compilation message
Main.cpp: In member function 'ull Node::query(int, int)':
Main.cpp:46:9: warning: comparison of integer expressions of different signedness: 'int' and 'ull' {aka 'long long unsigned int'} [-Wsign-compare]
46 | if (R <= lo || hi <= L) return 0;
| ~~^~~~~
Main.cpp:46:21: warning: comparison of integer expressions of different signedness: 'ull' {aka 'long long unsigned int'} and 'int' [-Wsign-compare]
46 | if (R <= lo || hi <= L) return 0;
| ~~~^~~~
Main.cpp:47:9: warning: comparison of integer expressions of different signedness: 'int' and 'ull' {aka 'long long unsigned int'} [-Wsign-compare]
47 | if (L <= lo && hi <= R) return val;
| ~~^~~~~
Main.cpp:47:21: warning: comparison of integer expressions of different signedness: 'ull' {aka 'long long unsigned int'} and 'int' [-Wsign-compare]
47 | if (L <= lo && hi <= R) return val;
| ~~~^~~~
Main.cpp: In member function 'void Node::set(int, int, int)':
Main.cpp:52:9: warning: comparison of integer expressions of different signedness: 'int' and 'ull' {aka 'long long unsigned int'} [-Wsign-compare]
52 | if (R <= lo || hi <= L) return;
| ~~^~~~~
Main.cpp:52:21: warning: comparison of integer expressions of different signedness: 'ull' {aka 'long long unsigned int'} and 'int' [-Wsign-compare]
52 | if (R <= lo || hi <= L) return;
| ~~~^~~~
Main.cpp:53:9: warning: comparison of integer expressions of different signedness: 'int' and 'ull' {aka 'long long unsigned int'} [-Wsign-compare]
53 | if (L <= lo && hi <= R) mset = val = x, madd = 1;
| ~~^~~~~
Main.cpp:53:21: warning: comparison of integer expressions of different signedness: 'ull' {aka 'long long unsigned int'} and 'int' [-Wsign-compare]
53 | if (L <= lo && hi <= R) mset = val = x, madd = 1;
| ~~~^~~~
Main.cpp: In member function 'void Node::add(int, int, ull)':
Main.cpp:61:9: warning: comparison of integer expressions of different signedness: 'int' and 'ull' {aka 'long long unsigned int'} [-Wsign-compare]
61 | if (R <= lo || hi <= L) return;
| ~~^~~~~
Main.cpp:61:21: warning: comparison of integer expressions of different signedness: 'ull' {aka 'long long unsigned int'} and 'int' [-Wsign-compare]
61 | if (R <= lo || hi <= L) return;
| ~~~^~~~
Main.cpp:62:9: warning: comparison of integer expressions of different signedness: 'int' and 'ull' {aka 'long long unsigned int'} [-Wsign-compare]
62 | if (L <= lo && hi <= R) {
| ~~^~~~~
Main.cpp:62:21: warning: comparison of integer expressions of different signedness: 'ull' {aka 'long long unsigned int'} and 'int' [-Wsign-compare]
62 | if (L <= lo && hi <= R) {
| ~~~^~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
392 ms |
864 KB |
Output is correct |
2 |
Correct |
414 ms |
892 KB |
Output is correct |
3 |
Correct |
408 ms |
896 KB |
Output is correct |
4 |
Correct |
399 ms |
788 KB |
Output is correct |
5 |
Correct |
375 ms |
848 KB |
Output is correct |
6 |
Correct |
375 ms |
812 KB |
Output is correct |
7 |
Correct |
385 ms |
928 KB |
Output is correct |
8 |
Correct |
406 ms |
860 KB |
Output is correct |
9 |
Correct |
394 ms |
916 KB |
Output is correct |
10 |
Correct |
447 ms |
836 KB |
Output is correct |
11 |
Correct |
395 ms |
800 KB |
Output is correct |
12 |
Correct |
390 ms |
848 KB |
Output is correct |
13 |
Correct |
402 ms |
848 KB |
Output is correct |
14 |
Correct |
401 ms |
876 KB |
Output is correct |
15 |
Correct |
395 ms |
824 KB |
Output is correct |
16 |
Correct |
399 ms |
876 KB |
Output is correct |
17 |
Correct |
438 ms |
868 KB |
Output is correct |
18 |
Correct |
430 ms |
936 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
392 ms |
864 KB |
Output is correct |
2 |
Correct |
414 ms |
892 KB |
Output is correct |
3 |
Correct |
408 ms |
896 KB |
Output is correct |
4 |
Correct |
399 ms |
788 KB |
Output is correct |
5 |
Correct |
375 ms |
848 KB |
Output is correct |
6 |
Correct |
375 ms |
812 KB |
Output is correct |
7 |
Correct |
385 ms |
928 KB |
Output is correct |
8 |
Correct |
406 ms |
860 KB |
Output is correct |
9 |
Correct |
394 ms |
916 KB |
Output is correct |
10 |
Correct |
447 ms |
836 KB |
Output is correct |
11 |
Correct |
395 ms |
800 KB |
Output is correct |
12 |
Correct |
390 ms |
848 KB |
Output is correct |
13 |
Correct |
402 ms |
848 KB |
Output is correct |
14 |
Correct |
401 ms |
876 KB |
Output is correct |
15 |
Correct |
395 ms |
824 KB |
Output is correct |
16 |
Correct |
399 ms |
876 KB |
Output is correct |
17 |
Correct |
438 ms |
868 KB |
Output is correct |
18 |
Correct |
430 ms |
936 KB |
Output is correct |
19 |
Correct |
763 ms |
35040 KB |
Output is correct |
20 |
Correct |
659 ms |
35100 KB |
Output is correct |
21 |
Correct |
606 ms |
33088 KB |
Output is correct |
22 |
Correct |
607 ms |
29860 KB |
Output is correct |
23 |
Correct |
456 ms |
2608 KB |
Output is correct |
24 |
Correct |
529 ms |
2600 KB |
Output is correct |
25 |
Correct |
668 ms |
35204 KB |
Output is correct |
26 |
Correct |
679 ms |
35148 KB |
Output is correct |
27 |
Correct |
715 ms |
35164 KB |
Output is correct |
28 |
Correct |
699 ms |
35164 KB |
Output is correct |
29 |
Correct |
681 ms |
34112 KB |
Output is correct |
30 |
Correct |
495 ms |
2680 KB |
Output is correct |
31 |
Correct |
692 ms |
35132 KB |
Output is correct |
32 |
Correct |
667 ms |
32092 KB |
Output is correct |
33 |
Correct |
465 ms |
2532 KB |
Output is correct |
34 |
Correct |
728 ms |
35192 KB |
Output is correct |
35 |
Correct |
601 ms |
26436 KB |
Output is correct |
36 |
Correct |
498 ms |
2568 KB |
Output is correct |
37 |
Correct |
475 ms |
2628 KB |
Output is correct |
38 |
Correct |
733 ms |
35164 KB |
Output is correct |
39 |
Correct |
532 ms |
35176 KB |
Output is correct |
40 |
Correct |
612 ms |
23372 KB |
Output is correct |
41 |
Correct |
828 ms |
35316 KB |
Output is correct |
42 |
Correct |
441 ms |
35244 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
392 ms |
864 KB |
Output is correct |
2 |
Correct |
414 ms |
892 KB |
Output is correct |
3 |
Correct |
408 ms |
896 KB |
Output is correct |
4 |
Correct |
399 ms |
788 KB |
Output is correct |
5 |
Correct |
375 ms |
848 KB |
Output is correct |
6 |
Correct |
375 ms |
812 KB |
Output is correct |
7 |
Correct |
385 ms |
928 KB |
Output is correct |
8 |
Correct |
406 ms |
860 KB |
Output is correct |
9 |
Correct |
394 ms |
916 KB |
Output is correct |
10 |
Correct |
447 ms |
836 KB |
Output is correct |
11 |
Correct |
395 ms |
800 KB |
Output is correct |
12 |
Correct |
390 ms |
848 KB |
Output is correct |
13 |
Correct |
402 ms |
848 KB |
Output is correct |
14 |
Correct |
401 ms |
876 KB |
Output is correct |
15 |
Correct |
395 ms |
824 KB |
Output is correct |
16 |
Correct |
399 ms |
876 KB |
Output is correct |
17 |
Correct |
438 ms |
868 KB |
Output is correct |
18 |
Correct |
430 ms |
936 KB |
Output is correct |
19 |
Correct |
396 ms |
876 KB |
Output is correct |
20 |
Correct |
419 ms |
900 KB |
Output is correct |
21 |
Correct |
419 ms |
848 KB |
Output is correct |
22 |
Correct |
403 ms |
836 KB |
Output is correct |
23 |
Correct |
392 ms |
888 KB |
Output is correct |
24 |
Correct |
383 ms |
968 KB |
Output is correct |
25 |
Correct |
430 ms |
912 KB |
Output is correct |
26 |
Correct |
390 ms |
904 KB |
Output is correct |
27 |
Correct |
386 ms |
840 KB |
Output is correct |
28 |
Correct |
369 ms |
868 KB |
Output is correct |
29 |
Correct |
419 ms |
896 KB |
Output is correct |
30 |
Correct |
372 ms |
784 KB |
Output is correct |
31 |
Correct |
402 ms |
800 KB |
Output is correct |
32 |
Correct |
401 ms |
904 KB |
Output is correct |
33 |
Correct |
408 ms |
884 KB |
Output is correct |
34 |
Correct |
372 ms |
832 KB |
Output is correct |
35 |
Correct |
413 ms |
864 KB |
Output is correct |
36 |
Correct |
401 ms |
912 KB |
Output is correct |
37 |
Correct |
424 ms |
912 KB |
Output is correct |
38 |
Correct |
406 ms |
868 KB |
Output is correct |
39 |
Correct |
443 ms |
836 KB |
Output is correct |
40 |
Correct |
418 ms |
1060 KB |
Output is correct |
41 |
Correct |
409 ms |
900 KB |
Output is correct |
42 |
Correct |
430 ms |
872 KB |
Output is correct |
43 |
Correct |
506 ms |
844 KB |
Output is correct |
44 |
Correct |
422 ms |
964 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
392 ms |
864 KB |
Output is correct |
2 |
Correct |
414 ms |
892 KB |
Output is correct |
3 |
Correct |
408 ms |
896 KB |
Output is correct |
4 |
Correct |
399 ms |
788 KB |
Output is correct |
5 |
Correct |
375 ms |
848 KB |
Output is correct |
6 |
Correct |
375 ms |
812 KB |
Output is correct |
7 |
Correct |
385 ms |
928 KB |
Output is correct |
8 |
Correct |
406 ms |
860 KB |
Output is correct |
9 |
Correct |
394 ms |
916 KB |
Output is correct |
10 |
Correct |
447 ms |
836 KB |
Output is correct |
11 |
Correct |
395 ms |
800 KB |
Output is correct |
12 |
Correct |
390 ms |
848 KB |
Output is correct |
13 |
Correct |
402 ms |
848 KB |
Output is correct |
14 |
Correct |
401 ms |
876 KB |
Output is correct |
15 |
Correct |
395 ms |
824 KB |
Output is correct |
16 |
Correct |
399 ms |
876 KB |
Output is correct |
17 |
Correct |
438 ms |
868 KB |
Output is correct |
18 |
Correct |
430 ms |
936 KB |
Output is correct |
19 |
Correct |
763 ms |
35040 KB |
Output is correct |
20 |
Correct |
659 ms |
35100 KB |
Output is correct |
21 |
Correct |
606 ms |
33088 KB |
Output is correct |
22 |
Correct |
607 ms |
29860 KB |
Output is correct |
23 |
Correct |
456 ms |
2608 KB |
Output is correct |
24 |
Correct |
529 ms |
2600 KB |
Output is correct |
25 |
Correct |
668 ms |
35204 KB |
Output is correct |
26 |
Correct |
679 ms |
35148 KB |
Output is correct |
27 |
Correct |
715 ms |
35164 KB |
Output is correct |
28 |
Correct |
699 ms |
35164 KB |
Output is correct |
29 |
Correct |
681 ms |
34112 KB |
Output is correct |
30 |
Correct |
495 ms |
2680 KB |
Output is correct |
31 |
Correct |
692 ms |
35132 KB |
Output is correct |
32 |
Correct |
667 ms |
32092 KB |
Output is correct |
33 |
Correct |
465 ms |
2532 KB |
Output is correct |
34 |
Correct |
728 ms |
35192 KB |
Output is correct |
35 |
Correct |
601 ms |
26436 KB |
Output is correct |
36 |
Correct |
498 ms |
2568 KB |
Output is correct |
37 |
Correct |
475 ms |
2628 KB |
Output is correct |
38 |
Correct |
733 ms |
35164 KB |
Output is correct |
39 |
Correct |
532 ms |
35176 KB |
Output is correct |
40 |
Correct |
612 ms |
23372 KB |
Output is correct |
41 |
Correct |
828 ms |
35316 KB |
Output is correct |
42 |
Correct |
441 ms |
35244 KB |
Output is correct |
43 |
Correct |
396 ms |
876 KB |
Output is correct |
44 |
Correct |
419 ms |
900 KB |
Output is correct |
45 |
Correct |
419 ms |
848 KB |
Output is correct |
46 |
Correct |
403 ms |
836 KB |
Output is correct |
47 |
Correct |
392 ms |
888 KB |
Output is correct |
48 |
Correct |
383 ms |
968 KB |
Output is correct |
49 |
Correct |
430 ms |
912 KB |
Output is correct |
50 |
Correct |
390 ms |
904 KB |
Output is correct |
51 |
Correct |
386 ms |
840 KB |
Output is correct |
52 |
Correct |
369 ms |
868 KB |
Output is correct |
53 |
Correct |
419 ms |
896 KB |
Output is correct |
54 |
Correct |
372 ms |
784 KB |
Output is correct |
55 |
Correct |
402 ms |
800 KB |
Output is correct |
56 |
Correct |
401 ms |
904 KB |
Output is correct |
57 |
Correct |
408 ms |
884 KB |
Output is correct |
58 |
Correct |
372 ms |
832 KB |
Output is correct |
59 |
Correct |
413 ms |
864 KB |
Output is correct |
60 |
Correct |
401 ms |
912 KB |
Output is correct |
61 |
Correct |
424 ms |
912 KB |
Output is correct |
62 |
Correct |
406 ms |
868 KB |
Output is correct |
63 |
Correct |
443 ms |
836 KB |
Output is correct |
64 |
Correct |
418 ms |
1060 KB |
Output is correct |
65 |
Correct |
409 ms |
900 KB |
Output is correct |
66 |
Correct |
430 ms |
872 KB |
Output is correct |
67 |
Correct |
506 ms |
844 KB |
Output is correct |
68 |
Correct |
422 ms |
964 KB |
Output is correct |
69 |
Correct |
835 ms |
30616 KB |
Output is correct |
70 |
Correct |
815 ms |
36496 KB |
Output is correct |
71 |
Correct |
476 ms |
2572 KB |
Output is correct |
72 |
Correct |
475 ms |
2652 KB |
Output is correct |
73 |
Correct |
470 ms |
2688 KB |
Output is correct |
74 |
Correct |
612 ms |
29672 KB |
Output is correct |
75 |
Correct |
458 ms |
2612 KB |
Output is correct |
76 |
Correct |
713 ms |
35428 KB |
Output is correct |
77 |
Correct |
643 ms |
29596 KB |
Output is correct |
78 |
Correct |
457 ms |
2624 KB |
Output is correct |
79 |
Correct |
453 ms |
2624 KB |
Output is correct |
80 |
Correct |
704 ms |
26360 KB |
Output is correct |
81 |
Correct |
471 ms |
2624 KB |
Output is correct |
82 |
Correct |
732 ms |
36448 KB |
Output is correct |
83 |
Correct |
731 ms |
34368 KB |
Output is correct |
84 |
Correct |
470 ms |
2728 KB |
Output is correct |
85 |
Correct |
479 ms |
2800 KB |
Output is correct |
86 |
Correct |
716 ms |
27964 KB |
Output is correct |
87 |
Correct |
742 ms |
36508 KB |
Output is correct |
88 |
Correct |
496 ms |
2796 KB |
Output is correct |
89 |
Correct |
711 ms |
32252 KB |
Output is correct |
90 |
Correct |
752 ms |
36640 KB |
Output is correct |
91 |
Correct |
480 ms |
2672 KB |
Output is correct |
92 |
Correct |
672 ms |
27492 KB |
Output is correct |
93 |
Correct |
502 ms |
2616 KB |
Output is correct |
94 |
Correct |
471 ms |
2616 KB |
Output is correct |
95 |
Correct |
469 ms |
2720 KB |
Output is correct |
96 |
Correct |
766 ms |
35076 KB |
Output is correct |
97 |
Correct |
567 ms |
36500 KB |
Output is correct |
98 |
Correct |
677 ms |
24280 KB |
Output is correct |
99 |
Correct |
919 ms |
36708 KB |
Output is correct |
100 |
Correct |
506 ms |
36696 KB |
Output is correct |