답안 #988972

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
988972 2024-05-27T07:23:52 Z PenguinsAreCute Crossing (JOI21_crossing) C++17
100 / 100
427 ms 11616 KB
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int BASE = 1210;
const int MOD = 998244353;
const int MAXN = 262144;
const int h = 32 - __builtin_clz(MAXN);
int pows[MAXN], ones[MAXN];
int wtf[80];
namespace seg {
	int v[MAXN<<1], lazy[MAXN<<1|1];
	void calc(int x, int k) {
		if(lazy[x]<3) v[x]=(1LL*lazy[x]*ones[k])%MOD;
		else v[x]=(1LL*v[x<<1|1]*pows[k>>1]+v[x<<1])%MOD;
	}
	void app(int x, int u, int k) {
		if(x<MAXN) lazy[x] = u;
		v[x] = (1LL*u*ones[k])%MOD;
	}
	void build(int l, int r) {
		int k = 2;
		for(l+=MAXN,r+=MAXN-1;l>1;k<<=1) {
			l>>=1,r>>=1;
			for(int i=r;i>=l;i--) calc(i,k);
		}
	}
	void push(int l, int r) {
		int k=1<<(h-1), s= h;
		for(l+=MAXN,r+=MAXN-1;s;s--,k>>=1) for(int i=(l>>s);i<=(r>>s);i++) if(lazy[i]<3) {
			app(i<<1,lazy[i],k);
			app(i<<1|1,lazy[i],k);
			lazy[i]=3;
		}
	}
	void init(string s) {
		fill(lazy,lazy+MAXN,3);
		for(int i=0;i<MAXN;i++) v[i+MAXN]=(i<s.size()?wtf[s[i]]:0);
		build(0,MAXN);
	}
	void up(int l, int r, int u) {
		push(l,l+1); push(r-1,r);
		int l0=l, r0=r, k=1;
		for(l+=MAXN,r+=MAXN;l<r;l>>=1,r>>=1,k<<=1) {
			if(l&1) app(l++,u,k);
			if(r&1) app(--r,u,k);
		}
		build(l0,l0+1); build(r0-1,r0);
	}
}
main() {
	pows[0]=1; for(int i=1;i<200005;i++) pows[i]=(1LL*pows[i-1]*BASE)%MOD;
	ones[0]=0; for(int i=1;i<200005;i++) ones[i]=(1LL*ones[i-1]*BASE+1)%MOD;
	wtf[73]=0;wtf[74]=1;wtf[79]=2;
	int n; cin >> n;
	string s1, s2, s3; cin >> s1 >> s2 >> s3;
	vector<int> hsh;
	for(int i=0;i<3;i++) for(int j=0;j<3;j++) {
		int curHsh = 0;
		for(int k=n;k--;) {
			int cur = i*wtf[s1[k]]+j*wtf[s2[k]]+(7-i-j)*wtf[s3[k]];
			cur %= 3;
			curHsh = (1LL * BASE * curHsh + cur) % MOD;
		}
		hsh.push_back(curHsh);
	}
	sort(hsh.begin(),hsh.end());
	int q; string t; cin >> q >> t;
	seg::init(t);
	auto it = lower_bound(hsh.begin(),hsh.end(),seg::v[1]);
	cout<<(it!=hsh.end()&&(*it)==seg::v[1]?"Yes\n":"No\n");
	for(int l,r;q--;) {
		char c; cin >> l >> r >> c;
		seg::up(--l,r,wtf[c]);
		it = lower_bound(hsh.begin(),hsh.end(),seg::v[1]);
		cout<<(it!=hsh.end()&&(*it)==seg::v[1]?"Yes\n":"No\n");
	}
}

Compilation message

Main.cpp: In function 'void seg::init(std::string)':
Main.cpp:37:39: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   37 |   for(int i=0;i<MAXN;i++) v[i+MAXN]=(i<s.size()?wtf[s[i]]:0);
      |                                      ~^~~~~~~~~
Main.cpp:37:57: warning: array subscript has type 'char' [-Wchar-subscripts]
   37 |   for(int i=0;i<MAXN;i++) v[i+MAXN]=(i<s.size()?wtf[s[i]]:0);
      |                                                         ^
Main.cpp: At global scope:
Main.cpp:50:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   50 | main() {
      | ^~~~
Main.cpp: In function 'int main()':
Main.cpp:60:25: warning: array subscript has type 'char' [-Wchar-subscripts]
   60 |    int cur = i*wtf[s1[k]]+j*wtf[s2[k]]+(7-i-j)*wtf[s3[k]];
      |                         ^
Main.cpp:60:38: warning: array subscript has type 'char' [-Wchar-subscripts]
   60 |    int cur = i*wtf[s1[k]]+j*wtf[s2[k]]+(7-i-j)*wtf[s3[k]];
      |                                      ^
Main.cpp:60:57: warning: array subscript has type 'char' [-Wchar-subscripts]
   60 |    int cur = i*wtf[s1[k]]+j*wtf[s2[k]]+(7-i-j)*wtf[s3[k]];
      |                                                         ^
Main.cpp:73:21: warning: array subscript has type 'char' [-Wchar-subscripts]
   73 |   seg::up(--l,r,wtf[c]);
      |                     ^
# 결과 실행 시간 메모리 Grader output
1 Correct 312 ms 7912 KB Output is correct
2 Correct 343 ms 8092 KB Output is correct
3 Correct 335 ms 8020 KB Output is correct
4 Correct 329 ms 8020 KB Output is correct
5 Correct 321 ms 8020 KB Output is correct
6 Correct 320 ms 7912 KB Output is correct
7 Correct 329 ms 7980 KB Output is correct
8 Correct 402 ms 8168 KB Output is correct
9 Correct 336 ms 8020 KB Output is correct
10 Correct 353 ms 8016 KB Output is correct
11 Correct 335 ms 8020 KB Output is correct
12 Correct 343 ms 8272 KB Output is correct
13 Correct 334 ms 8056 KB Output is correct
14 Correct 329 ms 8020 KB Output is correct
15 Correct 334 ms 8168 KB Output is correct
16 Correct 329 ms 8020 KB Output is correct
17 Correct 336 ms 7972 KB Output is correct
18 Correct 335 ms 8016 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 312 ms 7912 KB Output is correct
2 Correct 343 ms 8092 KB Output is correct
3 Correct 335 ms 8020 KB Output is correct
4 Correct 329 ms 8020 KB Output is correct
5 Correct 321 ms 8020 KB Output is correct
6 Correct 320 ms 7912 KB Output is correct
7 Correct 329 ms 7980 KB Output is correct
8 Correct 402 ms 8168 KB Output is correct
9 Correct 336 ms 8020 KB Output is correct
10 Correct 353 ms 8016 KB Output is correct
11 Correct 335 ms 8020 KB Output is correct
12 Correct 343 ms 8272 KB Output is correct
13 Correct 334 ms 8056 KB Output is correct
14 Correct 329 ms 8020 KB Output is correct
15 Correct 334 ms 8168 KB Output is correct
16 Correct 329 ms 8020 KB Output is correct
17 Correct 336 ms 7972 KB Output is correct
18 Correct 335 ms 8016 KB Output is correct
19 Correct 423 ms 11220 KB Output is correct
20 Correct 410 ms 11160 KB Output is correct
21 Correct 374 ms 10932 KB Output is correct
22 Correct 346 ms 10756 KB Output is correct
23 Correct 344 ms 8884 KB Output is correct
24 Correct 344 ms 9040 KB Output is correct
25 Correct 389 ms 11220 KB Output is correct
26 Correct 384 ms 11120 KB Output is correct
27 Correct 396 ms 11216 KB Output is correct
28 Correct 400 ms 11220 KB Output is correct
29 Correct 390 ms 10964 KB Output is correct
30 Correct 358 ms 8984 KB Output is correct
31 Correct 398 ms 11216 KB Output is correct
32 Correct 389 ms 10976 KB Output is correct
33 Correct 353 ms 9116 KB Output is correct
34 Correct 397 ms 11112 KB Output is correct
35 Correct 347 ms 10500 KB Output is correct
36 Correct 346 ms 9296 KB Output is correct
37 Correct 350 ms 8868 KB Output is correct
38 Correct 398 ms 11020 KB Output is correct
39 Correct 384 ms 11212 KB Output is correct
40 Correct 373 ms 10644 KB Output is correct
41 Correct 418 ms 11472 KB Output is correct
42 Correct 381 ms 10960 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 312 ms 7912 KB Output is correct
2 Correct 343 ms 8092 KB Output is correct
3 Correct 335 ms 8020 KB Output is correct
4 Correct 329 ms 8020 KB Output is correct
5 Correct 321 ms 8020 KB Output is correct
6 Correct 320 ms 7912 KB Output is correct
7 Correct 329 ms 7980 KB Output is correct
8 Correct 402 ms 8168 KB Output is correct
9 Correct 336 ms 8020 KB Output is correct
10 Correct 353 ms 8016 KB Output is correct
11 Correct 335 ms 8020 KB Output is correct
12 Correct 343 ms 8272 KB Output is correct
13 Correct 334 ms 8056 KB Output is correct
14 Correct 329 ms 8020 KB Output is correct
15 Correct 334 ms 8168 KB Output is correct
16 Correct 329 ms 8020 KB Output is correct
17 Correct 336 ms 7972 KB Output is correct
18 Correct 335 ms 8016 KB Output is correct
19 Correct 328 ms 8016 KB Output is correct
20 Correct 324 ms 8016 KB Output is correct
21 Correct 348 ms 8020 KB Output is correct
22 Correct 306 ms 7912 KB Output is correct
23 Correct 346 ms 8276 KB Output is correct
24 Correct 316 ms 7916 KB Output is correct
25 Correct 327 ms 8016 KB Output is correct
26 Correct 320 ms 8016 KB Output is correct
27 Correct 336 ms 8020 KB Output is correct
28 Correct 310 ms 8024 KB Output is correct
29 Correct 330 ms 8020 KB Output is correct
30 Correct 314 ms 8020 KB Output is correct
31 Correct 336 ms 8016 KB Output is correct
32 Correct 341 ms 8312 KB Output is correct
33 Correct 326 ms 8276 KB Output is correct
34 Correct 342 ms 8140 KB Output is correct
35 Correct 313 ms 8016 KB Output is correct
36 Correct 338 ms 8016 KB Output is correct
37 Correct 334 ms 8224 KB Output is correct
38 Correct 343 ms 8272 KB Output is correct
39 Correct 332 ms 8016 KB Output is correct
40 Correct 341 ms 8016 KB Output is correct
41 Correct 325 ms 8016 KB Output is correct
42 Correct 348 ms 8180 KB Output is correct
43 Correct 332 ms 8152 KB Output is correct
44 Correct 337 ms 8152 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 312 ms 7912 KB Output is correct
2 Correct 343 ms 8092 KB Output is correct
3 Correct 335 ms 8020 KB Output is correct
4 Correct 329 ms 8020 KB Output is correct
5 Correct 321 ms 8020 KB Output is correct
6 Correct 320 ms 7912 KB Output is correct
7 Correct 329 ms 7980 KB Output is correct
8 Correct 402 ms 8168 KB Output is correct
9 Correct 336 ms 8020 KB Output is correct
10 Correct 353 ms 8016 KB Output is correct
11 Correct 335 ms 8020 KB Output is correct
12 Correct 343 ms 8272 KB Output is correct
13 Correct 334 ms 8056 KB Output is correct
14 Correct 329 ms 8020 KB Output is correct
15 Correct 334 ms 8168 KB Output is correct
16 Correct 329 ms 8020 KB Output is correct
17 Correct 336 ms 7972 KB Output is correct
18 Correct 335 ms 8016 KB Output is correct
19 Correct 423 ms 11220 KB Output is correct
20 Correct 410 ms 11160 KB Output is correct
21 Correct 374 ms 10932 KB Output is correct
22 Correct 346 ms 10756 KB Output is correct
23 Correct 344 ms 8884 KB Output is correct
24 Correct 344 ms 9040 KB Output is correct
25 Correct 389 ms 11220 KB Output is correct
26 Correct 384 ms 11120 KB Output is correct
27 Correct 396 ms 11216 KB Output is correct
28 Correct 400 ms 11220 KB Output is correct
29 Correct 390 ms 10964 KB Output is correct
30 Correct 358 ms 8984 KB Output is correct
31 Correct 398 ms 11216 KB Output is correct
32 Correct 389 ms 10976 KB Output is correct
33 Correct 353 ms 9116 KB Output is correct
34 Correct 397 ms 11112 KB Output is correct
35 Correct 347 ms 10500 KB Output is correct
36 Correct 346 ms 9296 KB Output is correct
37 Correct 350 ms 8868 KB Output is correct
38 Correct 398 ms 11020 KB Output is correct
39 Correct 384 ms 11212 KB Output is correct
40 Correct 373 ms 10644 KB Output is correct
41 Correct 418 ms 11472 KB Output is correct
42 Correct 381 ms 10960 KB Output is correct
43 Correct 328 ms 8016 KB Output is correct
44 Correct 324 ms 8016 KB Output is correct
45 Correct 348 ms 8020 KB Output is correct
46 Correct 306 ms 7912 KB Output is correct
47 Correct 346 ms 8276 KB Output is correct
48 Correct 316 ms 7916 KB Output is correct
49 Correct 327 ms 8016 KB Output is correct
50 Correct 320 ms 8016 KB Output is correct
51 Correct 336 ms 8020 KB Output is correct
52 Correct 310 ms 8024 KB Output is correct
53 Correct 330 ms 8020 KB Output is correct
54 Correct 314 ms 8020 KB Output is correct
55 Correct 336 ms 8016 KB Output is correct
56 Correct 341 ms 8312 KB Output is correct
57 Correct 326 ms 8276 KB Output is correct
58 Correct 342 ms 8140 KB Output is correct
59 Correct 313 ms 8016 KB Output is correct
60 Correct 338 ms 8016 KB Output is correct
61 Correct 334 ms 8224 KB Output is correct
62 Correct 343 ms 8272 KB Output is correct
63 Correct 332 ms 8016 KB Output is correct
64 Correct 341 ms 8016 KB Output is correct
65 Correct 325 ms 8016 KB Output is correct
66 Correct 348 ms 8180 KB Output is correct
67 Correct 332 ms 8152 KB Output is correct
68 Correct 337 ms 8152 KB Output is correct
69 Correct 377 ms 10496 KB Output is correct
70 Correct 420 ms 11204 KB Output is correct
71 Correct 343 ms 9040 KB Output is correct
72 Correct 349 ms 9020 KB Output is correct
73 Correct 345 ms 8876 KB Output is correct
74 Correct 369 ms 10608 KB Output is correct
75 Correct 341 ms 9040 KB Output is correct
76 Correct 395 ms 11220 KB Output is correct
77 Correct 376 ms 10736 KB Output is correct
78 Correct 351 ms 9040 KB Output is correct
79 Correct 352 ms 9044 KB Output is correct
80 Correct 357 ms 10504 KB Output is correct
81 Correct 351 ms 8876 KB Output is correct
82 Correct 386 ms 11216 KB Output is correct
83 Correct 388 ms 11032 KB Output is correct
84 Correct 348 ms 8872 KB Output is correct
85 Correct 353 ms 9040 KB Output is correct
86 Correct 373 ms 10496 KB Output is correct
87 Correct 404 ms 11120 KB Output is correct
88 Correct 347 ms 9040 KB Output is correct
89 Correct 371 ms 10796 KB Output is correct
90 Correct 388 ms 11192 KB Output is correct
91 Correct 351 ms 9128 KB Output is correct
92 Correct 346 ms 10548 KB Output is correct
93 Correct 348 ms 9040 KB Output is correct
94 Correct 344 ms 9040 KB Output is correct
95 Correct 353 ms 8872 KB Output is correct
96 Correct 404 ms 10964 KB Output is correct
97 Correct 386 ms 11616 KB Output is correct
98 Correct 365 ms 10648 KB Output is correct
99 Correct 427 ms 11472 KB Output is correct
100 Correct 370 ms 10604 KB Output is correct