답안 #445054

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
445054 2021-07-16T10:27:59 Z arnold518 Crossing (JOI21_crossing) C++17
100 / 100
356 ms 23136 KB
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int MAXN = 2e5;
const ll MOD = 1e9+9;

int N, Q;
char S[MAXN+10];
vector<int> A[3], B;
vector<ll> V;
ll ppow[MAXN+10];

vector<int> read()
{
	scanf(" %s", S);
	vector<int> ans;
	for(int i=0; i<N; i++)
	{
		if(S[i]=='J') ans.push_back(0);
		else if(S[i]=='O') ans.push_back(1);
		else if(S[i]=='I') ans.push_back(2);
	}
	return ans;
}

ll gethash(vector<int> V)
{
	ll ret=0;
	for(int i=0; i<N; i++)
	{
		ret=(ret+(V[i]+1)*ppow[i])%MOD;
	}
	return ret;
}

struct SEG
{
	ll tree[MAXN*4+10], lazy[MAXN*4+10], sum[MAXN*4+10];

	void init(int node, int tl, int tr, vector<int> &V)
	{
		if(tl==tr)
		{
			tree[node]=(V[tl]+1)*ppow[tl]%MOD;
			sum[node]=ppow[tl]%MOD;
			lazy[node]=0;
			return;
		}
		int mid=tl+tr>>1;
		init(node*2, tl, mid, V);
		init(node*2+1, mid+1, tr, V);
		tree[node]=(tree[node*2]+tree[node*2+1])%MOD;
		sum[node]=(sum[node*2]+sum[node*2+1])%MOD;
		lazy[node]=0;
	}

	void busy(int node, int tl, int tr)
	{
		if(lazy[node]==0) return;
		tree[node]=lazy[node]*sum[node]%MOD;		
		if(tl==tr)
		{
			lazy[node]=0;
			return;
		}
		lazy[node*2]=lazy[node];
		lazy[node*2+1]=lazy[node];
		lazy[node]=0;
	}

	void update(int node, int tl, int tr, int l, int r, int k)
	{
		busy(node, tl, tr);
		if(l<=tl && tr<=r)
		{
			lazy[node]=k;
			busy(node, tl, tr);
			return;
		}
		if(r<tl || tr<l)
		{
			return;
		}
		int mid=tl+tr>>1;
		update(node*2, tl, mid, l, r, k);
		update(node*2+1, mid+1, tr, l, r, k);
		tree[node]=(tree[node*2]+tree[node*2+1])%MOD;
	}

	ll query()
	{
		busy(1, 0, N-1);
		return tree[1];
	}
}seg;

bool solve()
{
	ll t=seg.query();
	for(auto it : V)
	{	
		if(t==it) return true;
	}
	return false;
}

int main()
{
	scanf("%d", &N);

	ppow[0]=1;
	for(int i=1; i<=N; i++)
	{
		ppow[i]=ppow[i-1]*4%MOD;
	}
	for(int i=0; i<3; i++)
	{
		A[i]=read();
	}

	for(int i=0; i<3; i++) for(int j=0; j<3; j++)
	{
		int k=7-i-j;
		k%=3;

		vector<int> now(N);
		for(int p=0; p<N; p++)
		{
			now[p]+=A[0][p]*i;
			now[p]+=A[1][p]*j;
			now[p]+=A[2][p]*k;
			now[p]%=3;
		}
		V.push_back(gethash(now));
	}

	scanf("%d", &Q);
	B=read();

	seg.init(1, 0, N-1, B);
	printf("%s\n", solve() ? "Yes" : "No");
	while(Q--)
	{
		int l, r, k; char c;
		scanf("%d%d %c", &l, &r, &c);
		l--, r--;
		if(c=='J') k=1;
		else if(c=='O') k=2;
		else if(c=='I') k=3;
		seg.update(1, 0, N-1, l, r, k);
		printf("%s\n", solve() ? "Yes" : "No");
	}
}

Compilation message

Main.cpp: In member function 'void SEG::init(int, int, int, std::vector<int>&)':
Main.cpp:53:13: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   53 |   int mid=tl+tr>>1;
      |           ~~^~~
Main.cpp: In member function 'void SEG::update(int, int, int, int, int, int)':
Main.cpp:88:13: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   88 |   int mid=tl+tr>>1;
      |           ~~^~~
Main.cpp: In function 'std::vector<int> read()':
Main.cpp:19:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   19 |  scanf(" %s", S);
      |  ~~~~~^~~~~~~~~~
Main.cpp: In function 'int main()':
Main.cpp:113:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
  113 |  scanf("%d", &N);
      |  ~~~~~^~~~~~~~~~
Main.cpp:141:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
  141 |  scanf("%d", &Q);
      |  ~~~~~^~~~~~~~~~
Main.cpp:149:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
  149 |   scanf("%d%d %c", &l, &r, &c);
      |   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:80:15: warning: 'k' may be used uninitialized in this function [-Wmaybe-uninitialized]
   80 |    lazy[node]=k;
      |               ^
Main.cpp:148:13: note: 'k' was declared here
  148 |   int l, r, k; char c;
      |             ^
# 결과 실행 시간 메모리 Grader output
1 Correct 96 ms 1092 KB Output is correct
2 Correct 108 ms 1116 KB Output is correct
3 Correct 102 ms 1048 KB Output is correct
4 Correct 96 ms 1088 KB Output is correct
5 Correct 93 ms 1084 KB Output is correct
6 Correct 92 ms 1124 KB Output is correct
7 Correct 99 ms 1240 KB Output is correct
8 Correct 97 ms 1064 KB Output is correct
9 Correct 100 ms 1164 KB Output is correct
10 Correct 98 ms 1112 KB Output is correct
11 Correct 99 ms 1288 KB Output is correct
12 Correct 100 ms 1168 KB Output is correct
13 Correct 101 ms 1124 KB Output is correct
14 Correct 100 ms 1108 KB Output is correct
15 Correct 105 ms 1240 KB Output is correct
16 Correct 99 ms 1148 KB Output is correct
17 Correct 99 ms 1140 KB Output is correct
18 Correct 98 ms 1092 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 96 ms 1092 KB Output is correct
2 Correct 108 ms 1116 KB Output is correct
3 Correct 102 ms 1048 KB Output is correct
4 Correct 96 ms 1088 KB Output is correct
5 Correct 93 ms 1084 KB Output is correct
6 Correct 92 ms 1124 KB Output is correct
7 Correct 99 ms 1240 KB Output is correct
8 Correct 97 ms 1064 KB Output is correct
9 Correct 100 ms 1164 KB Output is correct
10 Correct 98 ms 1112 KB Output is correct
11 Correct 99 ms 1288 KB Output is correct
12 Correct 100 ms 1168 KB Output is correct
13 Correct 101 ms 1124 KB Output is correct
14 Correct 100 ms 1108 KB Output is correct
15 Correct 105 ms 1240 KB Output is correct
16 Correct 99 ms 1148 KB Output is correct
17 Correct 99 ms 1140 KB Output is correct
18 Correct 98 ms 1092 KB Output is correct
19 Correct 345 ms 19348 KB Output is correct
20 Correct 292 ms 19292 KB Output is correct
21 Correct 250 ms 19064 KB Output is correct
22 Correct 234 ms 18508 KB Output is correct
23 Correct 146 ms 2180 KB Output is correct
24 Correct 150 ms 2372 KB Output is correct
25 Correct 256 ms 19420 KB Output is correct
26 Correct 254 ms 19384 KB Output is correct
27 Correct 266 ms 19436 KB Output is correct
28 Correct 274 ms 19372 KB Output is correct
29 Correct 263 ms 19312 KB Output is correct
30 Correct 157 ms 2244 KB Output is correct
31 Correct 263 ms 19328 KB Output is correct
32 Correct 267 ms 18900 KB Output is correct
33 Correct 146 ms 2360 KB Output is correct
34 Correct 272 ms 19316 KB Output is correct
35 Correct 219 ms 18236 KB Output is correct
36 Correct 144 ms 2244 KB Output is correct
37 Correct 144 ms 2284 KB Output is correct
38 Correct 263 ms 19480 KB Output is correct
39 Correct 191 ms 19380 KB Output is correct
40 Correct 211 ms 10936 KB Output is correct
41 Correct 354 ms 19632 KB Output is correct
42 Correct 104 ms 19504 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 96 ms 1092 KB Output is correct
2 Correct 108 ms 1116 KB Output is correct
3 Correct 102 ms 1048 KB Output is correct
4 Correct 96 ms 1088 KB Output is correct
5 Correct 93 ms 1084 KB Output is correct
6 Correct 92 ms 1124 KB Output is correct
7 Correct 99 ms 1240 KB Output is correct
8 Correct 97 ms 1064 KB Output is correct
9 Correct 100 ms 1164 KB Output is correct
10 Correct 98 ms 1112 KB Output is correct
11 Correct 99 ms 1288 KB Output is correct
12 Correct 100 ms 1168 KB Output is correct
13 Correct 101 ms 1124 KB Output is correct
14 Correct 100 ms 1108 KB Output is correct
15 Correct 105 ms 1240 KB Output is correct
16 Correct 99 ms 1148 KB Output is correct
17 Correct 99 ms 1140 KB Output is correct
18 Correct 98 ms 1092 KB Output is correct
19 Correct 102 ms 1168 KB Output is correct
20 Correct 106 ms 1084 KB Output is correct
21 Correct 100 ms 1172 KB Output is correct
22 Correct 88 ms 1060 KB Output is correct
23 Correct 105 ms 1092 KB Output is correct
24 Correct 97 ms 1216 KB Output is correct
25 Correct 99 ms 1152 KB Output is correct
26 Correct 93 ms 1092 KB Output is correct
27 Correct 97 ms 1108 KB Output is correct
28 Correct 99 ms 1052 KB Output is correct
29 Correct 99 ms 1092 KB Output is correct
30 Correct 88 ms 1100 KB Output is correct
31 Correct 98 ms 1072 KB Output is correct
32 Correct 101 ms 1160 KB Output is correct
33 Correct 100 ms 1092 KB Output is correct
34 Correct 93 ms 1076 KB Output is correct
35 Correct 100 ms 1088 KB Output is correct
36 Correct 102 ms 1048 KB Output is correct
37 Correct 98 ms 1112 KB Output is correct
38 Correct 99 ms 1100 KB Output is correct
39 Correct 98 ms 1112 KB Output is correct
40 Correct 101 ms 1096 KB Output is correct
41 Correct 98 ms 1088 KB Output is correct
42 Correct 101 ms 1060 KB Output is correct
43 Correct 97 ms 1068 KB Output is correct
44 Correct 98 ms 1096 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 96 ms 1092 KB Output is correct
2 Correct 108 ms 1116 KB Output is correct
3 Correct 102 ms 1048 KB Output is correct
4 Correct 96 ms 1088 KB Output is correct
5 Correct 93 ms 1084 KB Output is correct
6 Correct 92 ms 1124 KB Output is correct
7 Correct 99 ms 1240 KB Output is correct
8 Correct 97 ms 1064 KB Output is correct
9 Correct 100 ms 1164 KB Output is correct
10 Correct 98 ms 1112 KB Output is correct
11 Correct 99 ms 1288 KB Output is correct
12 Correct 100 ms 1168 KB Output is correct
13 Correct 101 ms 1124 KB Output is correct
14 Correct 100 ms 1108 KB Output is correct
15 Correct 105 ms 1240 KB Output is correct
16 Correct 99 ms 1148 KB Output is correct
17 Correct 99 ms 1140 KB Output is correct
18 Correct 98 ms 1092 KB Output is correct
19 Correct 345 ms 19348 KB Output is correct
20 Correct 292 ms 19292 KB Output is correct
21 Correct 250 ms 19064 KB Output is correct
22 Correct 234 ms 18508 KB Output is correct
23 Correct 146 ms 2180 KB Output is correct
24 Correct 150 ms 2372 KB Output is correct
25 Correct 256 ms 19420 KB Output is correct
26 Correct 254 ms 19384 KB Output is correct
27 Correct 266 ms 19436 KB Output is correct
28 Correct 274 ms 19372 KB Output is correct
29 Correct 263 ms 19312 KB Output is correct
30 Correct 157 ms 2244 KB Output is correct
31 Correct 263 ms 19328 KB Output is correct
32 Correct 267 ms 18900 KB Output is correct
33 Correct 146 ms 2360 KB Output is correct
34 Correct 272 ms 19316 KB Output is correct
35 Correct 219 ms 18236 KB Output is correct
36 Correct 144 ms 2244 KB Output is correct
37 Correct 144 ms 2284 KB Output is correct
38 Correct 263 ms 19480 KB Output is correct
39 Correct 191 ms 19380 KB Output is correct
40 Correct 211 ms 10936 KB Output is correct
41 Correct 354 ms 19632 KB Output is correct
42 Correct 104 ms 19504 KB Output is correct
43 Correct 102 ms 1168 KB Output is correct
44 Correct 106 ms 1084 KB Output is correct
45 Correct 100 ms 1172 KB Output is correct
46 Correct 88 ms 1060 KB Output is correct
47 Correct 105 ms 1092 KB Output is correct
48 Correct 97 ms 1216 KB Output is correct
49 Correct 99 ms 1152 KB Output is correct
50 Correct 93 ms 1092 KB Output is correct
51 Correct 97 ms 1108 KB Output is correct
52 Correct 99 ms 1052 KB Output is correct
53 Correct 99 ms 1092 KB Output is correct
54 Correct 88 ms 1100 KB Output is correct
55 Correct 98 ms 1072 KB Output is correct
56 Correct 101 ms 1160 KB Output is correct
57 Correct 100 ms 1092 KB Output is correct
58 Correct 93 ms 1076 KB Output is correct
59 Correct 100 ms 1088 KB Output is correct
60 Correct 102 ms 1048 KB Output is correct
61 Correct 98 ms 1112 KB Output is correct
62 Correct 99 ms 1100 KB Output is correct
63 Correct 98 ms 1112 KB Output is correct
64 Correct 101 ms 1096 KB Output is correct
65 Correct 98 ms 1088 KB Output is correct
66 Correct 101 ms 1060 KB Output is correct
67 Correct 97 ms 1068 KB Output is correct
68 Correct 98 ms 1096 KB Output is correct
69 Correct 294 ms 18556 KB Output is correct
70 Correct 293 ms 19392 KB Output is correct
71 Correct 147 ms 2404 KB Output is correct
72 Correct 151 ms 2244 KB Output is correct
73 Correct 145 ms 2264 KB Output is correct
74 Correct 236 ms 18640 KB Output is correct
75 Correct 146 ms 2212 KB Output is correct
76 Correct 249 ms 19284 KB Output is correct
77 Correct 255 ms 18476 KB Output is correct
78 Correct 144 ms 2244 KB Output is correct
79 Correct 145 ms 2196 KB Output is correct
80 Correct 220 ms 17040 KB Output is correct
81 Correct 144 ms 2232 KB Output is correct
82 Correct 249 ms 19388 KB Output is correct
83 Correct 247 ms 19092 KB Output is correct
84 Correct 147 ms 2200 KB Output is correct
85 Correct 143 ms 2288 KB Output is correct
86 Correct 255 ms 18156 KB Output is correct
87 Correct 273 ms 19356 KB Output is correct
88 Correct 160 ms 2264 KB Output is correct
89 Correct 251 ms 18672 KB Output is correct
90 Correct 278 ms 19380 KB Output is correct
91 Correct 160 ms 2288 KB Output is correct
92 Correct 227 ms 18128 KB Output is correct
93 Correct 145 ms 2196 KB Output is correct
94 Correct 148 ms 2244 KB Output is correct
95 Correct 150 ms 2248 KB Output is correct
96 Correct 256 ms 19412 KB Output is correct
97 Correct 197 ms 19344 KB Output is correct
98 Correct 226 ms 11156 KB Output is correct
99 Correct 356 ms 23136 KB Output is correct
100 Correct 110 ms 22188 KB Output is correct