답안 #423596

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
423596 2021-06-11T10:06:05 Z patrikpavic2 Crossing (JOI21_crossing) C++17
100 / 100
670 ms 17812 KB
#include <cstdio>
#include <cstring>
#include <map>

using namespace std;

typedef long long ll;

const int N = 2e5 + 500;
const int MOD = 1e9 + 7;
const int BS = 31337;
const int OFF = (1 << 18);

int pot[N], P_pot[N], sol[N];
int prop[2 * OFF], T[2 * OFF];
int A[N][3];
map < int, int > dobar;

inline int add(int A, int B){
	if(A + B >= MOD)
		return A + B - MOD;
	return A + B;
}

inline int sub(int A, int B){
	if(A - B < 0)
		return A - B + MOD;
	return A - B;
}

inline int mul(int A, int B){
	return (ll)A * B % MOD;
}

void precompute(){
	pot[0] = 1, P_pot[0] = 1;
	for(int i = 1;i < N;i++){
		pot[i] = mul(pot[i - 1], BS);
		P_pot[i] = add(pot[i], P_pot[i - 1]);
	}
}

int kod(char c){
	if(c == 'J') return 0;
	if(c == 'O') return 1;
	return 2;
}

void refresh(int i, int l, int r){
	if(prop[i] == -1) return;
	T[i] = mul(sub(P_pot[r], (l ? P_pot[l - 1] : 0)), (prop[i] + 1));
	if(i < OFF){
		prop[2 * i] = prop[i];
		prop[2 * i + 1] = prop[i];
	}	
	prop[i] = -1;
}

void update(int i, int a, int b, int lo, int hi, int kog){
	refresh(i, a, b);
	if(lo <= a && b <= hi){
		prop[i] = kog; refresh(i, a, b);
		return;
	}
	if(a > hi || b < lo) return;
	update(2 * i, a, (a + b) / 2, lo, hi, kog);
	update(2 * i + 1, (a + b) / 2 + 1, b, lo, hi, kog);
	T[i] = add(T[2 * i], T[2 * i + 1]);
}

int n, q;

int main(){
	memset(prop, -1, sizeof(prop));
	precompute();
	scanf("%d", &n);
	for(int j = 0;j < 3;j++){
		for(int i = 0;i < n;i++){
			char c; scanf(" %c", &c);
			A[i][j] = kod(c);
		}
	}
	for(int ka = 0;ka < 3;ka++){
		for(int kb = 0;kb < 3;kb++){
			for(int kc = 0;kc < 3;kc++){
				if((ka + kb + kc) % 3 != 1) continue;
				int cur = 0;
				for(int i = 0;i < n;i++){
					cur = add(cur, mul(pot[i], ((ka * A[i][0] + kb * A[i][1] + kc * A[i][2]) % 3 + 1)));
				}
				dobar[cur] = 1;
			}	
		}
	}
	scanf("%d", &q);
	for(int i = 0;i < n;i++){
		char tmp; scanf(" %c", &tmp);
		update(1, 0, OFF - 1, i, i, kod(tmp));
	}
	printf(dobar[T[1]] ? "Yes\n" : "No\n");
	for(int i = 0;i < q;i++){
		int l, r; char tmp; scanf("%d%d %c", &l, &r, &tmp);
		int k = kod(tmp);
		update(1, 0, OFF - 1, l - 1, r - 1, k);
		printf(dobar[T[1]] ? "Yes\n" : "No\n");
	}
	return 0;
}

Compilation message

Main.cpp: In function 'int main()':
Main.cpp:76:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   76 |  scanf("%d", &n);
      |  ~~~~~^~~~~~~~~~
Main.cpp:79:17: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   79 |    char c; scanf(" %c", &c);
      |            ~~~~~^~~~~~~~~~~
Main.cpp:95:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   95 |  scanf("%d", &q);
      |  ~~~~~^~~~~~~~~~
Main.cpp:97:18: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   97 |   char tmp; scanf(" %c", &tmp);
      |             ~~~~~^~~~~~~~~~~~~
Main.cpp:102:28: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
  102 |   int l, r; char tmp; scanf("%d%d %c", &l, &r, &tmp);
      |                       ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 205 ms 11480 KB Output is correct
2 Correct 248 ms 12228 KB Output is correct
3 Correct 195 ms 7188 KB Output is correct
4 Correct 222 ms 12036 KB Output is correct
5 Correct 255 ms 12176 KB Output is correct
6 Correct 224 ms 11540 KB Output is correct
7 Correct 223 ms 11828 KB Output is correct
8 Correct 273 ms 12416 KB Output is correct
9 Correct 234 ms 12064 KB Output is correct
10 Correct 230 ms 13156 KB Output is correct
11 Correct 223 ms 12552 KB Output is correct
12 Correct 240 ms 13144 KB Output is correct
13 Correct 220 ms 12616 KB Output is correct
14 Correct 244 ms 13228 KB Output is correct
15 Correct 237 ms 12580 KB Output is correct
16 Correct 225 ms 13168 KB Output is correct
17 Correct 261 ms 12560 KB Output is correct
18 Correct 191 ms 5996 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 205 ms 11480 KB Output is correct
2 Correct 248 ms 12228 KB Output is correct
3 Correct 195 ms 7188 KB Output is correct
4 Correct 222 ms 12036 KB Output is correct
5 Correct 255 ms 12176 KB Output is correct
6 Correct 224 ms 11540 KB Output is correct
7 Correct 223 ms 11828 KB Output is correct
8 Correct 273 ms 12416 KB Output is correct
9 Correct 234 ms 12064 KB Output is correct
10 Correct 230 ms 13156 KB Output is correct
11 Correct 223 ms 12552 KB Output is correct
12 Correct 240 ms 13144 KB Output is correct
13 Correct 220 ms 12616 KB Output is correct
14 Correct 244 ms 13228 KB Output is correct
15 Correct 237 ms 12580 KB Output is correct
16 Correct 225 ms 13168 KB Output is correct
17 Correct 261 ms 12560 KB Output is correct
18 Correct 191 ms 5996 KB Output is correct
19 Correct 563 ms 15764 KB Output is correct
20 Correct 553 ms 16296 KB Output is correct
21 Correct 531 ms 16796 KB Output is correct
22 Correct 437 ms 14708 KB Output is correct
23 Correct 307 ms 14148 KB Output is correct
24 Correct 269 ms 13076 KB Output is correct
25 Correct 512 ms 17384 KB Output is correct
26 Correct 462 ms 15956 KB Output is correct
27 Correct 560 ms 17760 KB Output is correct
28 Correct 532 ms 15948 KB Output is correct
29 Correct 501 ms 17520 KB Output is correct
30 Correct 344 ms 14148 KB Output is correct
31 Correct 556 ms 17812 KB Output is correct
32 Correct 475 ms 15452 KB Output is correct
33 Correct 288 ms 12992 KB Output is correct
34 Correct 545 ms 16076 KB Output is correct
35 Correct 438 ms 15100 KB Output is correct
36 Correct 280 ms 13128 KB Output is correct
37 Correct 332 ms 13104 KB Output is correct
38 Correct 550 ms 14292 KB Output is correct
39 Correct 360 ms 13200 KB Output is correct
40 Correct 413 ms 15020 KB Output is correct
41 Correct 523 ms 8548 KB Output is correct
42 Correct 246 ms 8684 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 205 ms 11480 KB Output is correct
2 Correct 248 ms 12228 KB Output is correct
3 Correct 195 ms 7188 KB Output is correct
4 Correct 222 ms 12036 KB Output is correct
5 Correct 255 ms 12176 KB Output is correct
6 Correct 224 ms 11540 KB Output is correct
7 Correct 223 ms 11828 KB Output is correct
8 Correct 273 ms 12416 KB Output is correct
9 Correct 234 ms 12064 KB Output is correct
10 Correct 230 ms 13156 KB Output is correct
11 Correct 223 ms 12552 KB Output is correct
12 Correct 240 ms 13144 KB Output is correct
13 Correct 220 ms 12616 KB Output is correct
14 Correct 244 ms 13228 KB Output is correct
15 Correct 237 ms 12580 KB Output is correct
16 Correct 225 ms 13168 KB Output is correct
17 Correct 261 ms 12560 KB Output is correct
18 Correct 191 ms 5996 KB Output is correct
19 Correct 215 ms 11720 KB Output is correct
20 Correct 188 ms 7236 KB Output is correct
21 Correct 257 ms 12748 KB Output is correct
22 Correct 205 ms 11280 KB Output is correct
23 Correct 248 ms 12948 KB Output is correct
24 Correct 212 ms 11928 KB Output is correct
25 Correct 245 ms 12644 KB Output is correct
26 Correct 246 ms 11828 KB Output is correct
27 Correct 299 ms 12788 KB Output is correct
28 Correct 277 ms 12012 KB Output is correct
29 Correct 217 ms 12304 KB Output is correct
30 Correct 210 ms 11460 KB Output is correct
31 Correct 228 ms 12888 KB Output is correct
32 Correct 267 ms 12740 KB Output is correct
33 Correct 244 ms 12420 KB Output is correct
34 Correct 233 ms 11672 KB Output is correct
35 Correct 281 ms 13156 KB Output is correct
36 Correct 225 ms 12616 KB Output is correct
37 Correct 247 ms 13224 KB Output is correct
38 Correct 225 ms 12612 KB Output is correct
39 Correct 265 ms 13236 KB Output is correct
40 Correct 220 ms 12624 KB Output is correct
41 Correct 244 ms 13192 KB Output is correct
42 Correct 281 ms 12576 KB Output is correct
43 Correct 222 ms 12052 KB Output is correct
44 Correct 230 ms 12388 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 205 ms 11480 KB Output is correct
2 Correct 248 ms 12228 KB Output is correct
3 Correct 195 ms 7188 KB Output is correct
4 Correct 222 ms 12036 KB Output is correct
5 Correct 255 ms 12176 KB Output is correct
6 Correct 224 ms 11540 KB Output is correct
7 Correct 223 ms 11828 KB Output is correct
8 Correct 273 ms 12416 KB Output is correct
9 Correct 234 ms 12064 KB Output is correct
10 Correct 230 ms 13156 KB Output is correct
11 Correct 223 ms 12552 KB Output is correct
12 Correct 240 ms 13144 KB Output is correct
13 Correct 220 ms 12616 KB Output is correct
14 Correct 244 ms 13228 KB Output is correct
15 Correct 237 ms 12580 KB Output is correct
16 Correct 225 ms 13168 KB Output is correct
17 Correct 261 ms 12560 KB Output is correct
18 Correct 191 ms 5996 KB Output is correct
19 Correct 563 ms 15764 KB Output is correct
20 Correct 553 ms 16296 KB Output is correct
21 Correct 531 ms 16796 KB Output is correct
22 Correct 437 ms 14708 KB Output is correct
23 Correct 307 ms 14148 KB Output is correct
24 Correct 269 ms 13076 KB Output is correct
25 Correct 512 ms 17384 KB Output is correct
26 Correct 462 ms 15956 KB Output is correct
27 Correct 560 ms 17760 KB Output is correct
28 Correct 532 ms 15948 KB Output is correct
29 Correct 501 ms 17520 KB Output is correct
30 Correct 344 ms 14148 KB Output is correct
31 Correct 556 ms 17812 KB Output is correct
32 Correct 475 ms 15452 KB Output is correct
33 Correct 288 ms 12992 KB Output is correct
34 Correct 545 ms 16076 KB Output is correct
35 Correct 438 ms 15100 KB Output is correct
36 Correct 280 ms 13128 KB Output is correct
37 Correct 332 ms 13104 KB Output is correct
38 Correct 550 ms 14292 KB Output is correct
39 Correct 360 ms 13200 KB Output is correct
40 Correct 413 ms 15020 KB Output is correct
41 Correct 523 ms 8548 KB Output is correct
42 Correct 246 ms 8684 KB Output is correct
43 Correct 215 ms 11720 KB Output is correct
44 Correct 188 ms 7236 KB Output is correct
45 Correct 257 ms 12748 KB Output is correct
46 Correct 205 ms 11280 KB Output is correct
47 Correct 248 ms 12948 KB Output is correct
48 Correct 212 ms 11928 KB Output is correct
49 Correct 245 ms 12644 KB Output is correct
50 Correct 246 ms 11828 KB Output is correct
51 Correct 299 ms 12788 KB Output is correct
52 Correct 277 ms 12012 KB Output is correct
53 Correct 217 ms 12304 KB Output is correct
54 Correct 210 ms 11460 KB Output is correct
55 Correct 228 ms 12888 KB Output is correct
56 Correct 267 ms 12740 KB Output is correct
57 Correct 244 ms 12420 KB Output is correct
58 Correct 233 ms 11672 KB Output is correct
59 Correct 281 ms 13156 KB Output is correct
60 Correct 225 ms 12616 KB Output is correct
61 Correct 247 ms 13224 KB Output is correct
62 Correct 225 ms 12612 KB Output is correct
63 Correct 265 ms 13236 KB Output is correct
64 Correct 220 ms 12624 KB Output is correct
65 Correct 244 ms 13192 KB Output is correct
66 Correct 281 ms 12576 KB Output is correct
67 Correct 222 ms 12052 KB Output is correct
68 Correct 230 ms 12388 KB Output is correct
69 Correct 517 ms 14396 KB Output is correct
70 Correct 670 ms 16240 KB Output is correct
71 Correct 298 ms 13228 KB Output is correct
72 Correct 317 ms 13208 KB Output is correct
73 Correct 291 ms 13180 KB Output is correct
74 Correct 459 ms 15844 KB Output is correct
75 Correct 306 ms 14068 KB Output is correct
76 Correct 520 ms 17452 KB Output is correct
77 Correct 509 ms 14916 KB Output is correct
78 Correct 292 ms 13104 KB Output is correct
79 Correct 319 ms 13176 KB Output is correct
80 Correct 394 ms 15124 KB Output is correct
81 Correct 315 ms 14116 KB Output is correct
82 Correct 488 ms 17500 KB Output is correct
83 Correct 450 ms 15512 KB Output is correct
84 Correct 290 ms 13124 KB Output is correct
85 Correct 274 ms 13236 KB Output is correct
86 Correct 443 ms 14532 KB Output is correct
87 Correct 516 ms 15928 KB Output is correct
88 Correct 317 ms 12676 KB Output is correct
89 Correct 469 ms 15120 KB Output is correct
90 Correct 548 ms 16200 KB Output is correct
91 Correct 281 ms 12700 KB Output is correct
92 Correct 533 ms 15120 KB Output is correct
93 Correct 272 ms 13124 KB Output is correct
94 Correct 308 ms 13112 KB Output is correct
95 Correct 283 ms 13128 KB Output is correct
96 Correct 487 ms 14256 KB Output is correct
97 Correct 362 ms 14244 KB Output is correct
98 Correct 474 ms 14960 KB Output is correct
99 Correct 456 ms 8584 KB Output is correct
100 Correct 245 ms 8644 KB Output is correct