#include<bits/stdc++.h>
using namespace std;
#define mp make_pair
#define INF 10000000
#define MOD 1000000007
#define MID ((l+r)/2)
#define HASHMOD 2305843009213693951
#define ll long long
#define ull unsigned long long
#define F first
#define S second
typedef pair<ll, ll> ii;
typedef pair<ii, int> iii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef map<int, int> mii;
#define EPS 1e-6
#define FOR(i,n) for(int i=0;i<((int)(n));i++)
#define FORi(i,a,b) for(int i=((int)(a));i<((int)(b));i++)
#define FOA(v, a) for(auto v : a)
int t, n;
vi a, b;
#define Q 4
#define enumer(x) (x=='I' ? 1 : (x=='J' ? 2 : 3))
string cross(string a, string b){
FOR(i,a.size()){
if(a[i]==b[i]) continue;
if(a[i]+b[i]=='O'+'I') a[i] = 'J';
else if(a[i]+b[i]=='J'+'I') a[i] = 'O';
else if(a[i]+b[i]=='O'+'J') a[i] = 'I';
}
return a;
}
ll mpow(ll a, ll b, ll m){
if(b==0) return 1;
if(b==1) return a;
ll z = mpow(a, b/2, m);
z*=z;
z%=m;
if(b%2) z*=a;
return z%m;
}
ll inv(ll x, ll m){
return mpow(x, m-2, m);
}
#define NMOD 1
ll invx[NMOD];
ll mods[NMOD] = {MOD+200};
template<typename T>
struct seg_tree{
struct node{
vector<T> val;
T laz;
int left=-1;
int right=-1;
node() {val.assign(NMOD, 0); laz=0, left=-1, right=-1;}
node(T v){ val.assign(NMOD, v);}
};
vector<node> seg;
static inline int N;
const int RAND_VALUE=0;
seg_tree(int n){N=n, seg.assign(1, node());}
inline node merge(node par, node a, node b, int l, int r){
node ret;
ret.left = par.left, ret.right = par.right;
FOR(m,NMOD) ret.val[m] = ((a.val[m] * mpow(Q, r-MID, mods[m]))%mods[m] + b.val[m])%mods[m];
return ret;
}
inline void update_node(int ind, int val, int l, int r){
FOR(m,NMOD){
seg[ind].val[m] = (val * (mpow(Q, (r-l+1), mods[m])-1) * invx[m])%mods[m];
}
seg[ind].laz = val;
}
inline void down(node &par, int l, int r){
if(par.laz){
FOR(m,NMOD){
seg[par.left].val[m] = (((par.laz * (mpow(Q, (MID-l+1), mods[m])-1))%mods[m]) * invx[m])%mods[m];
seg[par.right].val[m] = (((par.laz * (mpow(Q, (r-MID), mods[m])-1))%mods[m]) * invx[m])%mods[m];
}
seg[par.left].laz = par.laz;
seg[par.right].laz = par.laz;
}
par.laz = 0;
}
inline void create_children(int ind){
node par = seg[ind];
if(par.left==-1) par.left=seg.size(), seg.push_back(node());
if(par.right==-1) par.right=seg.size(), seg.push_back(node());
seg[ind] = par;
}
void build(vector<T>& arr, int l=0, int r=N-1, int ind=0){
if(l==r) seg[ind] = node(arr[l]);
else{
create_children(ind);
build(arr,l,MID,seg[ind].left);
build(arr,MID+1,r,seg[ind].right);
seg[ind] = merge(seg[ind], seg[seg[ind].left], seg[seg[ind].right], l,r);
}
}
void update(int rl, int rr, int val, int l=0, int r=N-1, int ind=0){
if(rl<=l && r<=rr) update_node(ind, val,l,r);
else if(rr<l || r<rl) return;
else{
create_children(ind);
down(seg[ind],l,r);
update(rl,rr,val,l,MID,seg[ind].left);
update(rl,rr,val,MID+1,r,seg[ind].right);
seg[ind] = merge(seg[ind], seg[seg[ind].left], seg[seg[ind].right], l,r);
}
}
node _query(int rl, int rr, int l=0, int r=N-1, int ind=0){
if(rl<=l && r<=rr) return seg[ind];
else if(rl>r || l>rr) return node(RAND_VALUE);
else{
create_children(ind);
down(seg[ind],l,r);
return merge(seg[ind], _query(rl, rr, l, MID, seg[ind].left), _query(rl,rr,MID+1,r,seg[ind].right), l, r);
}
}
vector<T> query(int l, int r){
return _query(l,r).val;
}
};
vector<ll> hsh(string s){
vector<ll> a;
FOR(m, NMOD){
ll x = 0;
FOA(v, s){
x*=Q;
x+=enumer(v);
x%=mods[m];
}
a.push_back(x);
}
return a;
}
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
FOR(i, NMOD) invx[i] = inv(Q-1, mods[i]);
int n;
cin>>n;
string s[3];
cin>>s[0]>>s[1]>>s[2];
set<string> all;
set<vector<ll> > hshs;
int p=0;
hshs.insert(hsh(s[0]));
hshs.insert(hsh(s[1]));
hshs.insert(hsh(s[2]));
all.insert(s[0]);
all.insert(s[1]);
all.insert(s[2]);
while(p!=(int)all.size()){
p = all.size();
FOA(a, all){
FOA(b, all){
if(a==b) continue;
hshs.insert(hsh(cross(a,b)));
all.insert(cross(a,b));
}
}
}
//FOA(v, all) cout<<v<<" "<<hsh(v)<<endl;
seg_tree<ll> seg(n);
int q;
cin>>q;
string t;
cin>>t;
vector<ll> b(n);
FOR(i,n) b[i] = enumer(t[i]);
seg.build(b);
do{
//cout<<seg.query(0, n-1)<<endl;
if(hshs.count(seg.query(0, n-1))) cout<<"Yes\n";
else cout<<"No\n";
if(q==0) break;
int l, r;
char c;
cin>>l>>r>>c;
seg.update(l-1, r-1, enumer(c));
}while(q--);
}
Compilation message
Main.cpp:69:9: warning: inline variables are only available with '-std=c++17' or '-std=gnu++17'
69 | static inline int N;
| ^~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
396 ms |
788 KB |
Output is correct |
2 |
Correct |
459 ms |
940 KB |
Output is correct |
3 |
Correct |
551 ms |
1024 KB |
Output is correct |
4 |
Correct |
402 ms |
944 KB |
Output is correct |
5 |
Correct |
365 ms |
828 KB |
Output is correct |
6 |
Correct |
365 ms |
836 KB |
Output is correct |
7 |
Correct |
365 ms |
876 KB |
Output is correct |
8 |
Correct |
396 ms |
876 KB |
Output is correct |
9 |
Correct |
403 ms |
872 KB |
Output is correct |
10 |
Correct |
388 ms |
828 KB |
Output is correct |
11 |
Correct |
397 ms |
980 KB |
Output is correct |
12 |
Correct |
428 ms |
808 KB |
Output is correct |
13 |
Correct |
396 ms |
924 KB |
Output is correct |
14 |
Correct |
402 ms |
860 KB |
Output is correct |
15 |
Correct |
425 ms |
860 KB |
Output is correct |
16 |
Correct |
433 ms |
856 KB |
Output is correct |
17 |
Correct |
416 ms |
832 KB |
Output is correct |
18 |
Correct |
493 ms |
920 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
396 ms |
788 KB |
Output is correct |
2 |
Correct |
459 ms |
940 KB |
Output is correct |
3 |
Correct |
551 ms |
1024 KB |
Output is correct |
4 |
Correct |
402 ms |
944 KB |
Output is correct |
5 |
Correct |
365 ms |
828 KB |
Output is correct |
6 |
Correct |
365 ms |
836 KB |
Output is correct |
7 |
Correct |
365 ms |
876 KB |
Output is correct |
8 |
Correct |
396 ms |
876 KB |
Output is correct |
9 |
Correct |
403 ms |
872 KB |
Output is correct |
10 |
Correct |
388 ms |
828 KB |
Output is correct |
11 |
Correct |
397 ms |
980 KB |
Output is correct |
12 |
Correct |
428 ms |
808 KB |
Output is correct |
13 |
Correct |
396 ms |
924 KB |
Output is correct |
14 |
Correct |
402 ms |
860 KB |
Output is correct |
15 |
Correct |
425 ms |
860 KB |
Output is correct |
16 |
Correct |
433 ms |
856 KB |
Output is correct |
17 |
Correct |
416 ms |
832 KB |
Output is correct |
18 |
Correct |
493 ms |
920 KB |
Output is correct |
19 |
Correct |
3294 ms |
31648 KB |
Output is correct |
20 |
Correct |
3645 ms |
31628 KB |
Output is correct |
21 |
Correct |
1837 ms |
31336 KB |
Output is correct |
22 |
Correct |
1842 ms |
31124 KB |
Output is correct |
23 |
Correct |
987 ms |
2480 KB |
Output is correct |
24 |
Correct |
1008 ms |
2424 KB |
Output is correct |
25 |
Correct |
2068 ms |
31556 KB |
Output is correct |
26 |
Correct |
2000 ms |
31572 KB |
Output is correct |
27 |
Correct |
2376 ms |
31648 KB |
Output is correct |
28 |
Correct |
2307 ms |
31676 KB |
Output is correct |
29 |
Correct |
2159 ms |
31444 KB |
Output is correct |
30 |
Correct |
1068 ms |
2556 KB |
Output is correct |
31 |
Correct |
2151 ms |
31640 KB |
Output is correct |
32 |
Correct |
2044 ms |
31260 KB |
Output is correct |
33 |
Correct |
956 ms |
2516 KB |
Output is correct |
34 |
Correct |
2164 ms |
31612 KB |
Output is correct |
35 |
Correct |
1586 ms |
30832 KB |
Output is correct |
36 |
Correct |
936 ms |
2444 KB |
Output is correct |
37 |
Correct |
940 ms |
2452 KB |
Output is correct |
38 |
Correct |
2797 ms |
31764 KB |
Output is correct |
39 |
Correct |
1320 ms |
31760 KB |
Output is correct |
40 |
Correct |
1565 ms |
21208 KB |
Output is correct |
41 |
Correct |
3582 ms |
32032 KB |
Output is correct |
42 |
Correct |
207 ms |
31848 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
396 ms |
788 KB |
Output is correct |
2 |
Correct |
459 ms |
940 KB |
Output is correct |
3 |
Correct |
551 ms |
1024 KB |
Output is correct |
4 |
Correct |
402 ms |
944 KB |
Output is correct |
5 |
Correct |
365 ms |
828 KB |
Output is correct |
6 |
Correct |
365 ms |
836 KB |
Output is correct |
7 |
Correct |
365 ms |
876 KB |
Output is correct |
8 |
Correct |
396 ms |
876 KB |
Output is correct |
9 |
Correct |
403 ms |
872 KB |
Output is correct |
10 |
Correct |
388 ms |
828 KB |
Output is correct |
11 |
Correct |
397 ms |
980 KB |
Output is correct |
12 |
Correct |
428 ms |
808 KB |
Output is correct |
13 |
Correct |
396 ms |
924 KB |
Output is correct |
14 |
Correct |
402 ms |
860 KB |
Output is correct |
15 |
Correct |
425 ms |
860 KB |
Output is correct |
16 |
Correct |
433 ms |
856 KB |
Output is correct |
17 |
Correct |
416 ms |
832 KB |
Output is correct |
18 |
Correct |
493 ms |
920 KB |
Output is correct |
19 |
Correct |
443 ms |
860 KB |
Output is correct |
20 |
Correct |
543 ms |
848 KB |
Output is correct |
21 |
Correct |
387 ms |
964 KB |
Output is correct |
22 |
Correct |
327 ms |
836 KB |
Output is correct |
23 |
Correct |
388 ms |
924 KB |
Output is correct |
24 |
Correct |
375 ms |
936 KB |
Output is correct |
25 |
Correct |
408 ms |
984 KB |
Output is correct |
26 |
Correct |
341 ms |
1084 KB |
Output is correct |
27 |
Correct |
389 ms |
868 KB |
Output is correct |
28 |
Correct |
357 ms |
796 KB |
Output is correct |
29 |
Correct |
393 ms |
964 KB |
Output is correct |
30 |
Correct |
328 ms |
872 KB |
Output is correct |
31 |
Correct |
389 ms |
872 KB |
Output is correct |
32 |
Correct |
389 ms |
836 KB |
Output is correct |
33 |
Correct |
400 ms |
852 KB |
Output is correct |
34 |
Correct |
334 ms |
840 KB |
Output is correct |
35 |
Correct |
396 ms |
876 KB |
Output is correct |
36 |
Correct |
401 ms |
964 KB |
Output is correct |
37 |
Correct |
396 ms |
840 KB |
Output is correct |
38 |
Correct |
395 ms |
804 KB |
Output is correct |
39 |
Correct |
387 ms |
836 KB |
Output is correct |
40 |
Correct |
399 ms |
872 KB |
Output is correct |
41 |
Correct |
392 ms |
1008 KB |
Output is correct |
42 |
Correct |
396 ms |
836 KB |
Output is correct |
43 |
Correct |
366 ms |
968 KB |
Output is correct |
44 |
Correct |
402 ms |
876 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
396 ms |
788 KB |
Output is correct |
2 |
Correct |
459 ms |
940 KB |
Output is correct |
3 |
Correct |
551 ms |
1024 KB |
Output is correct |
4 |
Correct |
402 ms |
944 KB |
Output is correct |
5 |
Correct |
365 ms |
828 KB |
Output is correct |
6 |
Correct |
365 ms |
836 KB |
Output is correct |
7 |
Correct |
365 ms |
876 KB |
Output is correct |
8 |
Correct |
396 ms |
876 KB |
Output is correct |
9 |
Correct |
403 ms |
872 KB |
Output is correct |
10 |
Correct |
388 ms |
828 KB |
Output is correct |
11 |
Correct |
397 ms |
980 KB |
Output is correct |
12 |
Correct |
428 ms |
808 KB |
Output is correct |
13 |
Correct |
396 ms |
924 KB |
Output is correct |
14 |
Correct |
402 ms |
860 KB |
Output is correct |
15 |
Correct |
425 ms |
860 KB |
Output is correct |
16 |
Correct |
433 ms |
856 KB |
Output is correct |
17 |
Correct |
416 ms |
832 KB |
Output is correct |
18 |
Correct |
493 ms |
920 KB |
Output is correct |
19 |
Correct |
3294 ms |
31648 KB |
Output is correct |
20 |
Correct |
3645 ms |
31628 KB |
Output is correct |
21 |
Correct |
1837 ms |
31336 KB |
Output is correct |
22 |
Correct |
1842 ms |
31124 KB |
Output is correct |
23 |
Correct |
987 ms |
2480 KB |
Output is correct |
24 |
Correct |
1008 ms |
2424 KB |
Output is correct |
25 |
Correct |
2068 ms |
31556 KB |
Output is correct |
26 |
Correct |
2000 ms |
31572 KB |
Output is correct |
27 |
Correct |
2376 ms |
31648 KB |
Output is correct |
28 |
Correct |
2307 ms |
31676 KB |
Output is correct |
29 |
Correct |
2159 ms |
31444 KB |
Output is correct |
30 |
Correct |
1068 ms |
2556 KB |
Output is correct |
31 |
Correct |
2151 ms |
31640 KB |
Output is correct |
32 |
Correct |
2044 ms |
31260 KB |
Output is correct |
33 |
Correct |
956 ms |
2516 KB |
Output is correct |
34 |
Correct |
2164 ms |
31612 KB |
Output is correct |
35 |
Correct |
1586 ms |
30832 KB |
Output is correct |
36 |
Correct |
936 ms |
2444 KB |
Output is correct |
37 |
Correct |
940 ms |
2452 KB |
Output is correct |
38 |
Correct |
2797 ms |
31764 KB |
Output is correct |
39 |
Correct |
1320 ms |
31760 KB |
Output is correct |
40 |
Correct |
1565 ms |
21208 KB |
Output is correct |
41 |
Correct |
3582 ms |
32032 KB |
Output is correct |
42 |
Correct |
207 ms |
31848 KB |
Output is correct |
43 |
Correct |
443 ms |
860 KB |
Output is correct |
44 |
Correct |
543 ms |
848 KB |
Output is correct |
45 |
Correct |
387 ms |
964 KB |
Output is correct |
46 |
Correct |
327 ms |
836 KB |
Output is correct |
47 |
Correct |
388 ms |
924 KB |
Output is correct |
48 |
Correct |
375 ms |
936 KB |
Output is correct |
49 |
Correct |
408 ms |
984 KB |
Output is correct |
50 |
Correct |
341 ms |
1084 KB |
Output is correct |
51 |
Correct |
389 ms |
868 KB |
Output is correct |
52 |
Correct |
357 ms |
796 KB |
Output is correct |
53 |
Correct |
393 ms |
964 KB |
Output is correct |
54 |
Correct |
328 ms |
872 KB |
Output is correct |
55 |
Correct |
389 ms |
872 KB |
Output is correct |
56 |
Correct |
389 ms |
836 KB |
Output is correct |
57 |
Correct |
400 ms |
852 KB |
Output is correct |
58 |
Correct |
334 ms |
840 KB |
Output is correct |
59 |
Correct |
396 ms |
876 KB |
Output is correct |
60 |
Correct |
401 ms |
964 KB |
Output is correct |
61 |
Correct |
396 ms |
840 KB |
Output is correct |
62 |
Correct |
395 ms |
804 KB |
Output is correct |
63 |
Correct |
387 ms |
836 KB |
Output is correct |
64 |
Correct |
399 ms |
872 KB |
Output is correct |
65 |
Correct |
392 ms |
1008 KB |
Output is correct |
66 |
Correct |
396 ms |
836 KB |
Output is correct |
67 |
Correct |
366 ms |
968 KB |
Output is correct |
68 |
Correct |
402 ms |
876 KB |
Output is correct |
69 |
Correct |
3184 ms |
32432 KB |
Output is correct |
70 |
Correct |
3698 ms |
33364 KB |
Output is correct |
71 |
Correct |
981 ms |
2600 KB |
Output is correct |
72 |
Correct |
930 ms |
2524 KB |
Output is correct |
73 |
Correct |
955 ms |
2520 KB |
Output is correct |
74 |
Correct |
1811 ms |
31580 KB |
Output is correct |
75 |
Correct |
940 ms |
2388 KB |
Output is correct |
76 |
Correct |
1841 ms |
32116 KB |
Output is correct |
77 |
Correct |
1727 ms |
31552 KB |
Output is correct |
78 |
Correct |
957 ms |
2448 KB |
Output is correct |
79 |
Correct |
942 ms |
2572 KB |
Output is correct |
80 |
Correct |
2033 ms |
32304 KB |
Output is correct |
81 |
Correct |
978 ms |
2516 KB |
Output is correct |
82 |
Correct |
2502 ms |
33348 KB |
Output is correct |
83 |
Correct |
2395 ms |
33028 KB |
Output is correct |
84 |
Correct |
984 ms |
2668 KB |
Output is correct |
85 |
Correct |
975 ms |
2596 KB |
Output is correct |
86 |
Correct |
2253 ms |
32268 KB |
Output is correct |
87 |
Correct |
2467 ms |
33384 KB |
Output is correct |
88 |
Correct |
1038 ms |
2672 KB |
Output is correct |
89 |
Correct |
2171 ms |
32648 KB |
Output is correct |
90 |
Correct |
2389 ms |
33260 KB |
Output is correct |
91 |
Correct |
1082 ms |
2508 KB |
Output is correct |
92 |
Correct |
2078 ms |
32084 KB |
Output is correct |
93 |
Correct |
963 ms |
2536 KB |
Output is correct |
94 |
Correct |
982 ms |
2592 KB |
Output is correct |
95 |
Correct |
990 ms |
2688 KB |
Output is correct |
96 |
Correct |
2822 ms |
31808 KB |
Output is correct |
97 |
Correct |
1496 ms |
33304 KB |
Output is correct |
98 |
Correct |
1979 ms |
22344 KB |
Output is correct |
99 |
Correct |
4075 ms |
33456 KB |
Output is correct |
100 |
Correct |
720 ms |
33384 KB |
Output is correct |