답안 #445041

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
445041 2021-07-16T09:56:53 Z arnold518 Crossing (JOI21_crossing) C++17
49 / 100
389 ms 23044 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+7;

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 103 ms 2244 KB Output is correct
2 Correct 111 ms 2460 KB Output is correct
3 Correct 106 ms 2316 KB Output is correct
4 Correct 95 ms 2372 KB Output is correct
5 Correct 94 ms 2352 KB Output is correct
6 Correct 94 ms 2244 KB Output is correct
7 Correct 101 ms 2372 KB Output is correct
8 Correct 102 ms 2380 KB Output is correct
9 Correct 99 ms 2444 KB Output is correct
10 Correct 100 ms 2372 KB Output is correct
11 Correct 101 ms 2440 KB Output is correct
12 Correct 101 ms 2424 KB Output is correct
13 Correct 101 ms 2500 KB Output is correct
14 Correct 98 ms 2340 KB Output is correct
15 Correct 101 ms 2408 KB Output is correct
16 Correct 117 ms 2372 KB Output is correct
17 Correct 103 ms 2372 KB Output is correct
18 Correct 99 ms 2332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 103 ms 2244 KB Output is correct
2 Correct 111 ms 2460 KB Output is correct
3 Correct 106 ms 2316 KB Output is correct
4 Correct 95 ms 2372 KB Output is correct
5 Correct 94 ms 2352 KB Output is correct
6 Correct 94 ms 2244 KB Output is correct
7 Correct 101 ms 2372 KB Output is correct
8 Correct 102 ms 2380 KB Output is correct
9 Correct 99 ms 2444 KB Output is correct
10 Correct 100 ms 2372 KB Output is correct
11 Correct 101 ms 2440 KB Output is correct
12 Correct 101 ms 2424 KB Output is correct
13 Correct 101 ms 2500 KB Output is correct
14 Correct 98 ms 2340 KB Output is correct
15 Correct 101 ms 2408 KB Output is correct
16 Correct 117 ms 2372 KB Output is correct
17 Correct 103 ms 2372 KB Output is correct
18 Correct 99 ms 2332 KB Output is correct
19 Correct 369 ms 22776 KB Output is correct
20 Correct 306 ms 22752 KB Output is correct
21 Correct 271 ms 22264 KB Output is correct
22 Correct 248 ms 21752 KB Output is correct
23 Correct 148 ms 4312 KB Output is correct
24 Correct 149 ms 4352 KB Output is correct
25 Correct 282 ms 22908 KB Output is correct
26 Correct 276 ms 22844 KB Output is correct
27 Correct 277 ms 23044 KB Output is correct
28 Correct 290 ms 22712 KB Output is correct
29 Correct 295 ms 22572 KB Output is correct
30 Correct 158 ms 4420 KB Output is correct
31 Correct 288 ms 22748 KB Output is correct
32 Correct 284 ms 22196 KB Output is correct
33 Correct 149 ms 4316 KB Output is correct
34 Correct 313 ms 22796 KB Output is correct
35 Correct 233 ms 21104 KB Output is correct
36 Correct 147 ms 4292 KB Output is correct
37 Correct 153 ms 4308 KB Output is correct
38 Correct 277 ms 22704 KB Output is correct
39 Correct 191 ms 22816 KB Output is correct
40 Correct 243 ms 14144 KB Output is correct
41 Correct 389 ms 22996 KB Output is correct
42 Correct 104 ms 22228 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 103 ms 2244 KB Output is correct
2 Correct 111 ms 2460 KB Output is correct
3 Correct 106 ms 2316 KB Output is correct
4 Correct 95 ms 2372 KB Output is correct
5 Correct 94 ms 2352 KB Output is correct
6 Correct 94 ms 2244 KB Output is correct
7 Correct 101 ms 2372 KB Output is correct
8 Correct 102 ms 2380 KB Output is correct
9 Correct 99 ms 2444 KB Output is correct
10 Correct 100 ms 2372 KB Output is correct
11 Correct 101 ms 2440 KB Output is correct
12 Correct 101 ms 2424 KB Output is correct
13 Correct 101 ms 2500 KB Output is correct
14 Correct 98 ms 2340 KB Output is correct
15 Correct 101 ms 2408 KB Output is correct
16 Correct 117 ms 2372 KB Output is correct
17 Correct 103 ms 2372 KB Output is correct
18 Correct 99 ms 2332 KB Output is correct
19 Correct 108 ms 2360 KB Output is correct
20 Correct 109 ms 2244 KB Output is correct
21 Correct 102 ms 2496 KB Output is correct
22 Correct 92 ms 2244 KB Output is correct
23 Correct 99 ms 2408 KB Output is correct
24 Correct 107 ms 2248 KB Output is correct
25 Correct 100 ms 2372 KB Output is correct
26 Correct 94 ms 2300 KB Output is correct
27 Correct 104 ms 2448 KB Output is correct
28 Correct 92 ms 2216 KB Output is correct
29 Correct 99 ms 2360 KB Output is correct
30 Correct 91 ms 2236 KB Output is correct
31 Correct 105 ms 2372 KB Output is correct
32 Correct 100 ms 2352 KB Output is correct
33 Correct 99 ms 2440 KB Output is correct
34 Correct 91 ms 2184 KB Output is correct
35 Correct 97 ms 2444 KB Output is correct
36 Correct 103 ms 2376 KB Output is correct
37 Correct 102 ms 2384 KB Output is correct
38 Correct 99 ms 2340 KB Output is correct
39 Correct 98 ms 2420 KB Output is correct
40 Correct 101 ms 2336 KB Output is correct
41 Correct 99 ms 2372 KB Output is correct
42 Correct 100 ms 2400 KB Output is correct
43 Correct 95 ms 2368 KB Output is correct
44 Correct 103 ms 2420 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 103 ms 2244 KB Output is correct
2 Correct 111 ms 2460 KB Output is correct
3 Correct 106 ms 2316 KB Output is correct
4 Correct 95 ms 2372 KB Output is correct
5 Correct 94 ms 2352 KB Output is correct
6 Correct 94 ms 2244 KB Output is correct
7 Correct 101 ms 2372 KB Output is correct
8 Correct 102 ms 2380 KB Output is correct
9 Correct 99 ms 2444 KB Output is correct
10 Correct 100 ms 2372 KB Output is correct
11 Correct 101 ms 2440 KB Output is correct
12 Correct 101 ms 2424 KB Output is correct
13 Correct 101 ms 2500 KB Output is correct
14 Correct 98 ms 2340 KB Output is correct
15 Correct 101 ms 2408 KB Output is correct
16 Correct 117 ms 2372 KB Output is correct
17 Correct 103 ms 2372 KB Output is correct
18 Correct 99 ms 2332 KB Output is correct
19 Correct 369 ms 22776 KB Output is correct
20 Correct 306 ms 22752 KB Output is correct
21 Correct 271 ms 22264 KB Output is correct
22 Correct 248 ms 21752 KB Output is correct
23 Correct 148 ms 4312 KB Output is correct
24 Correct 149 ms 4352 KB Output is correct
25 Correct 282 ms 22908 KB Output is correct
26 Correct 276 ms 22844 KB Output is correct
27 Correct 277 ms 23044 KB Output is correct
28 Correct 290 ms 22712 KB Output is correct
29 Correct 295 ms 22572 KB Output is correct
30 Correct 158 ms 4420 KB Output is correct
31 Correct 288 ms 22748 KB Output is correct
32 Correct 284 ms 22196 KB Output is correct
33 Correct 149 ms 4316 KB Output is correct
34 Correct 313 ms 22796 KB Output is correct
35 Correct 233 ms 21104 KB Output is correct
36 Correct 147 ms 4292 KB Output is correct
37 Correct 153 ms 4308 KB Output is correct
38 Correct 277 ms 22704 KB Output is correct
39 Correct 191 ms 22816 KB Output is correct
40 Correct 243 ms 14144 KB Output is correct
41 Correct 389 ms 22996 KB Output is correct
42 Correct 104 ms 22228 KB Output is correct
43 Correct 108 ms 2360 KB Output is correct
44 Correct 109 ms 2244 KB Output is correct
45 Correct 102 ms 2496 KB Output is correct
46 Correct 92 ms 2244 KB Output is correct
47 Correct 99 ms 2408 KB Output is correct
48 Correct 107 ms 2248 KB Output is correct
49 Correct 100 ms 2372 KB Output is correct
50 Correct 94 ms 2300 KB Output is correct
51 Correct 104 ms 2448 KB Output is correct
52 Correct 92 ms 2216 KB Output is correct
53 Correct 99 ms 2360 KB Output is correct
54 Correct 91 ms 2236 KB Output is correct
55 Correct 105 ms 2372 KB Output is correct
56 Correct 100 ms 2352 KB Output is correct
57 Correct 99 ms 2440 KB Output is correct
58 Correct 91 ms 2184 KB Output is correct
59 Correct 97 ms 2444 KB Output is correct
60 Correct 103 ms 2376 KB Output is correct
61 Correct 102 ms 2384 KB Output is correct
62 Correct 99 ms 2340 KB Output is correct
63 Correct 98 ms 2420 KB Output is correct
64 Correct 101 ms 2336 KB Output is correct
65 Correct 99 ms 2372 KB Output is correct
66 Correct 100 ms 2400 KB Output is correct
67 Correct 95 ms 2368 KB Output is correct
68 Correct 103 ms 2420 KB Output is correct
69 Correct 306 ms 21564 KB Output is correct
70 Correct 295 ms 22688 KB Output is correct
71 Correct 150 ms 4596 KB Output is correct
72 Correct 148 ms 4368 KB Output is correct
73 Correct 147 ms 4340 KB Output is correct
74 Correct 228 ms 21568 KB Output is correct
75 Correct 145 ms 4388 KB Output is correct
76 Correct 254 ms 22768 KB Output is correct
77 Correct 248 ms 21692 KB Output is correct
78 Correct 145 ms 4328 KB Output is correct
79 Correct 147 ms 4292 KB Output is correct
80 Correct 228 ms 19892 KB Output is correct
81 Correct 149 ms 4300 KB Output is correct
82 Correct 261 ms 22892 KB Output is correct
83 Correct 256 ms 22340 KB Output is correct
84 Correct 145 ms 4304 KB Output is correct
85 Correct 150 ms 4332 KB Output is correct
86 Correct 250 ms 21252 KB Output is correct
87 Correct 282 ms 22772 KB Output is correct
88 Correct 158 ms 4308 KB Output is correct
89 Correct 260 ms 21944 KB Output is correct
90 Correct 271 ms 22732 KB Output is correct
91 Correct 155 ms 4420 KB Output is correct
92 Correct 225 ms 21108 KB Output is correct
93 Correct 148 ms 4328 KB Output is correct
94 Correct 149 ms 4292 KB Output is correct
95 Correct 151 ms 4368 KB Output is correct
96 Correct 265 ms 22524 KB Output is correct
97 Correct 195 ms 22972 KB Output is correct
98 Incorrect 226 ms 14228 KB Output isn't correct
99 Halted 0 ms 0 KB -