답안 #502543

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
502543 2022-01-06T08:23:25 Z beksultan04 Crossing (JOI21_crossing) C++14
100 / 100
3210 ms 107752 KB
#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
//#define int long long
#define pii pair<int,int>
#define ret return
#define fr first
#define sc second
#define OK puts("OK");
#define NO puts("NO");
#define YES puts("YES");
#define all(s) s.begin(),s.end()
#define allr(s) s.rbegin(),s.rend()
#define nosol puts("-1");
#define pb push_back
#define endi puts("");
#define ordered_set tree <int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
const int N = 2e5+12,INF = 1e9+7;
int q[10][N],w[N],n,pref[N][10][4];
string s[5];
struct derevo{
	int lp,can;
	derevo (int x=0): can(x),lp(-1) {};
} der[4*N][10];

void fun(int a,int b,int c){
	for (int i=1;i<=n;++i)
		q[c][i] = ((3-(q[a][i]+q[b][i])+3)%3);
}

void build(int v,int l,int r,int j){
	if (l == r){
		der[v][j].can = (q[j][l] == w[l]);
		ret ;
	}
	int m = l+r>>1;
	build(v<<1,l,m,j);
	build(v<<1|1,m+1,r,j);
	der[v][j].can = (der[v<<1][j].can && der[v<<1|1][j].can);
}

void push(int v,int j,int l,int r){
	if (der[v][j].lp == -1)ret ;
	if (r == l){
		der[v][j].can = (der[v][j].lp == q[j][l]);
		der[v][j].lp = -1;
		ret ;
	}
	int m = l+r>>1;
	der[v<<1][j].can = ((pref[m][j][der[v][j].lp]-pref[l-1][j][der[v][j].lp]) == (m-l+1));
	der[v<<1|1][j].can = ((pref[r][j][der[v][j].lp]-pref[m][j][der[v][j].lp]) == (r-m));
	der[v<<1][j].lp = der[v][j].lp;
	der[v<<1|1][j].lp = der[v][j].lp;
	der[v][j].can = (der[v<<1][j].can && der[v<<1|1][j].can);
	der[v][j].lp = -1;
}

void update(int v,int l,int r,int ql,int qr,int x,int j){
	push(v,j,l,r);
	if (l > qr || r < ql){
		ret ;
	}
	if (ql <= l && r <= qr){
		der[v][j].lp = x;
		der[v][j].can = ((pref[r][j][x] - pref[l-1][j][x]) == (r-l+1));
		push(v,j,l,r);
		ret ;
	}
	int m = l+r>>1;
	update(v<<1,l,m,ql,qr,x,j);
	update(v<<1|1,m+1,r,ql,qr,x,j);
	der[v][j].can = (der[v<<1][j].can && der[v<<1|1][j].can);
}

void is(){
	for (int j=0;j<9;++j){
		
		if (der[1][j].can){
			cout <<"Yes\n";ret ;
		}
	}
	cout <<"No\n";
}

int main(){
	int i,m,j;
	cin>>n;
	cin>>s[0]>>s[1]>>s[2];
	
	for (i=0;i<n;++i){
		if (s[0][i] == 'J')
			q[0][i+1] = 1;
		if (s[1][i] == 'J')
			q[1][i+1] = 1;
		if (s[2][i] == 'J')
			q[2][i+1] = 1;
		if (s[0][i] == 'O')
			q[0][i+1] = 2;
		if (s[1][i] == 'O')
			q[1][i+1] = 2;
		if (s[2][i] == 'O')
			q[2][i+1] = 2;
	}
	fun(0,1,3);
	fun(0,2,4);
	fun(1,2,5);
	fun(3,2,6);
	fun(4,1,7);
	fun(5,0,8);
	cin>>m;
	cin>>s[3];
	
	for (j=0;j<9;++j){
		for (i=1;i<=n;++i){
			pref[i][j][0] = pref[i-1][j][0];
			pref[i][j][1] = pref[i-1][j][1];
			pref[i][j][2] = pref[i-1][j][2]; 
			pref[i][j][q[j][i]]++;
		}
	}
	
	for (i=0;i<n;++i){
		if (s[3][i] == 'J')
			w[i+1] = 1;
		if (s[3][i] == 'O')
			w[i+1] = 2;
	}
	
	for (j=0;j<9;++j)
		build(1,1,n,j);
	is();
	while (m--){
		int l,r,z=0;
		char ch;
		cin>>l>>r>>ch;
		if (ch == 'J')z = 1;
		if (ch == 'O')z = 2;
		for (j=0;j<9;++j){
			update(1,1,n,l,r,z,j);
		}
		is();
	}
	
}








Compilation message

Main.cpp: In constructor 'derevo::derevo(int)':
Main.cpp:24:9: warning: 'derevo::can' will be initialized after [-Wreorder]
   24 |  int lp,can;
      |         ^~~
Main.cpp:24:6: warning:   'int derevo::lp' [-Wreorder]
   24 |  int lp,can;
      |      ^~
Main.cpp:25:2: warning:   when initialized here [-Wreorder]
   25 |  derevo (int x=0): can(x),lp(-1) {};
      |  ^~~~~~
Main.cpp: In function 'void build(int, int, int, int)':
Main.cpp:38:11: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   38 |  int m = l+r>>1;
      |          ~^~
Main.cpp: In function 'void push(int, int, int, int)':
Main.cpp:51:11: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   51 |  int m = l+r>>1;
      |          ~^~
Main.cpp: In function 'void update(int, int, int, int, int, int, int)':
Main.cpp:71:11: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   71 |  int m = l+r>>1;
      |          ~^~
# 결과 실행 시간 메모리 Grader output
1 Correct 652 ms 63684 KB Output is correct
2 Correct 739 ms 63828 KB Output is correct
3 Correct 787 ms 63756 KB Output is correct
4 Correct 580 ms 63600 KB Output is correct
5 Correct 591 ms 63800 KB Output is correct
6 Correct 597 ms 63688 KB Output is correct
7 Correct 629 ms 63796 KB Output is correct
8 Correct 689 ms 63692 KB Output is correct
9 Correct 625 ms 63796 KB Output is correct
10 Correct 610 ms 63832 KB Output is correct
11 Correct 631 ms 63888 KB Output is correct
12 Correct 620 ms 63636 KB Output is correct
13 Correct 652 ms 63664 KB Output is correct
14 Correct 605 ms 63684 KB Output is correct
15 Correct 619 ms 63720 KB Output is correct
16 Correct 598 ms 63684 KB Output is correct
17 Correct 619 ms 63628 KB Output is correct
18 Correct 732 ms 63844 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 652 ms 63684 KB Output is correct
2 Correct 739 ms 63828 KB Output is correct
3 Correct 787 ms 63756 KB Output is correct
4 Correct 580 ms 63600 KB Output is correct
5 Correct 591 ms 63800 KB Output is correct
6 Correct 597 ms 63688 KB Output is correct
7 Correct 629 ms 63796 KB Output is correct
8 Correct 689 ms 63692 KB Output is correct
9 Correct 625 ms 63796 KB Output is correct
10 Correct 610 ms 63832 KB Output is correct
11 Correct 631 ms 63888 KB Output is correct
12 Correct 620 ms 63636 KB Output is correct
13 Correct 652 ms 63664 KB Output is correct
14 Correct 605 ms 63684 KB Output is correct
15 Correct 619 ms 63720 KB Output is correct
16 Correct 598 ms 63684 KB Output is correct
17 Correct 619 ms 63628 KB Output is correct
18 Correct 732 ms 63844 KB Output is correct
19 Correct 2759 ms 103604 KB Output is correct
20 Correct 2649 ms 103624 KB Output is correct
21 Correct 1391 ms 104804 KB Output is correct
22 Correct 1483 ms 100636 KB Output is correct
23 Correct 918 ms 68124 KB Output is correct
24 Correct 907 ms 68040 KB Output is correct
25 Correct 1428 ms 107396 KB Output is correct
26 Correct 1603 ms 107232 KB Output is correct
27 Correct 1982 ms 107148 KB Output is correct
28 Correct 2045 ms 107248 KB Output is correct
29 Correct 1843 ms 106096 KB Output is correct
30 Correct 1050 ms 68160 KB Output is correct
31 Correct 1914 ms 107264 KB Output is correct
32 Correct 1799 ms 103684 KB Output is correct
33 Correct 936 ms 67888 KB Output is correct
34 Correct 1870 ms 107268 KB Output is correct
35 Correct 1289 ms 96652 KB Output is correct
36 Correct 936 ms 68064 KB Output is correct
37 Correct 924 ms 67852 KB Output is correct
38 Correct 2339 ms 104744 KB Output is correct
39 Correct 1098 ms 107208 KB Output is correct
40 Correct 1369 ms 93304 KB Output is correct
41 Correct 3210 ms 107436 KB Output is correct
42 Correct 481 ms 106596 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 652 ms 63684 KB Output is correct
2 Correct 739 ms 63828 KB Output is correct
3 Correct 787 ms 63756 KB Output is correct
4 Correct 580 ms 63600 KB Output is correct
5 Correct 591 ms 63800 KB Output is correct
6 Correct 597 ms 63688 KB Output is correct
7 Correct 629 ms 63796 KB Output is correct
8 Correct 689 ms 63692 KB Output is correct
9 Correct 625 ms 63796 KB Output is correct
10 Correct 610 ms 63832 KB Output is correct
11 Correct 631 ms 63888 KB Output is correct
12 Correct 620 ms 63636 KB Output is correct
13 Correct 652 ms 63664 KB Output is correct
14 Correct 605 ms 63684 KB Output is correct
15 Correct 619 ms 63720 KB Output is correct
16 Correct 598 ms 63684 KB Output is correct
17 Correct 619 ms 63628 KB Output is correct
18 Correct 732 ms 63844 KB Output is correct
19 Correct 680 ms 63700 KB Output is correct
20 Correct 811 ms 63824 KB Output is correct
21 Correct 636 ms 63832 KB Output is correct
22 Correct 548 ms 63812 KB Output is correct
23 Correct 614 ms 63752 KB Output is correct
24 Correct 601 ms 63864 KB Output is correct
25 Correct 619 ms 63976 KB Output is correct
26 Correct 576 ms 63812 KB Output is correct
27 Correct 609 ms 63852 KB Output is correct
28 Correct 574 ms 63752 KB Output is correct
29 Correct 629 ms 63808 KB Output is correct
30 Correct 554 ms 63724 KB Output is correct
31 Correct 608 ms 63732 KB Output is correct
32 Correct 616 ms 63812 KB Output is correct
33 Correct 628 ms 63768 KB Output is correct
34 Correct 563 ms 63804 KB Output is correct
35 Correct 614 ms 63812 KB Output is correct
36 Correct 636 ms 63784 KB Output is correct
37 Correct 631 ms 63848 KB Output is correct
38 Correct 624 ms 63896 KB Output is correct
39 Correct 613 ms 63812 KB Output is correct
40 Correct 618 ms 63752 KB Output is correct
41 Correct 612 ms 63832 KB Output is correct
42 Correct 620 ms 63960 KB Output is correct
43 Correct 591 ms 63728 KB Output is correct
44 Correct 611 ms 63800 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 652 ms 63684 KB Output is correct
2 Correct 739 ms 63828 KB Output is correct
3 Correct 787 ms 63756 KB Output is correct
4 Correct 580 ms 63600 KB Output is correct
5 Correct 591 ms 63800 KB Output is correct
6 Correct 597 ms 63688 KB Output is correct
7 Correct 629 ms 63796 KB Output is correct
8 Correct 689 ms 63692 KB Output is correct
9 Correct 625 ms 63796 KB Output is correct
10 Correct 610 ms 63832 KB Output is correct
11 Correct 631 ms 63888 KB Output is correct
12 Correct 620 ms 63636 KB Output is correct
13 Correct 652 ms 63664 KB Output is correct
14 Correct 605 ms 63684 KB Output is correct
15 Correct 619 ms 63720 KB Output is correct
16 Correct 598 ms 63684 KB Output is correct
17 Correct 619 ms 63628 KB Output is correct
18 Correct 732 ms 63844 KB Output is correct
19 Correct 2759 ms 103604 KB Output is correct
20 Correct 2649 ms 103624 KB Output is correct
21 Correct 1391 ms 104804 KB Output is correct
22 Correct 1483 ms 100636 KB Output is correct
23 Correct 918 ms 68124 KB Output is correct
24 Correct 907 ms 68040 KB Output is correct
25 Correct 1428 ms 107396 KB Output is correct
26 Correct 1603 ms 107232 KB Output is correct
27 Correct 1982 ms 107148 KB Output is correct
28 Correct 2045 ms 107248 KB Output is correct
29 Correct 1843 ms 106096 KB Output is correct
30 Correct 1050 ms 68160 KB Output is correct
31 Correct 1914 ms 107264 KB Output is correct
32 Correct 1799 ms 103684 KB Output is correct
33 Correct 936 ms 67888 KB Output is correct
34 Correct 1870 ms 107268 KB Output is correct
35 Correct 1289 ms 96652 KB Output is correct
36 Correct 936 ms 68064 KB Output is correct
37 Correct 924 ms 67852 KB Output is correct
38 Correct 2339 ms 104744 KB Output is correct
39 Correct 1098 ms 107208 KB Output is correct
40 Correct 1369 ms 93304 KB Output is correct
41 Correct 3210 ms 107436 KB Output is correct
42 Correct 481 ms 106596 KB Output is correct
43 Correct 680 ms 63700 KB Output is correct
44 Correct 811 ms 63824 KB Output is correct
45 Correct 636 ms 63832 KB Output is correct
46 Correct 548 ms 63812 KB Output is correct
47 Correct 614 ms 63752 KB Output is correct
48 Correct 601 ms 63864 KB Output is correct
49 Correct 619 ms 63976 KB Output is correct
50 Correct 576 ms 63812 KB Output is correct
51 Correct 609 ms 63852 KB Output is correct
52 Correct 574 ms 63752 KB Output is correct
53 Correct 629 ms 63808 KB Output is correct
54 Correct 554 ms 63724 KB Output is correct
55 Correct 608 ms 63732 KB Output is correct
56 Correct 616 ms 63812 KB Output is correct
57 Correct 628 ms 63768 KB Output is correct
58 Correct 563 ms 63804 KB Output is correct
59 Correct 614 ms 63812 KB Output is correct
60 Correct 636 ms 63784 KB Output is correct
61 Correct 631 ms 63848 KB Output is correct
62 Correct 624 ms 63896 KB Output is correct
63 Correct 613 ms 63812 KB Output is correct
64 Correct 618 ms 63752 KB Output is correct
65 Correct 612 ms 63832 KB Output is correct
66 Correct 620 ms 63960 KB Output is correct
67 Correct 591 ms 63728 KB Output is correct
68 Correct 611 ms 63800 KB Output is correct
69 Correct 2499 ms 100416 KB Output is correct
70 Correct 2743 ms 107160 KB Output is correct
71 Correct 939 ms 68044 KB Output is correct
72 Correct 919 ms 68012 KB Output is correct
73 Correct 931 ms 68032 KB Output is correct
74 Correct 1354 ms 100240 KB Output is correct
75 Correct 945 ms 67924 KB Output is correct
76 Correct 1457 ms 107240 KB Output is correct
77 Correct 1542 ms 100452 KB Output is correct
78 Correct 930 ms 68188 KB Output is correct
79 Correct 923 ms 68208 KB Output is correct
80 Correct 1370 ms 95180 KB Output is correct
81 Correct 915 ms 68024 KB Output is correct
82 Correct 1463 ms 107232 KB Output is correct
83 Correct 1534 ms 104932 KB Output is correct
84 Correct 930 ms 67916 KB Output is correct
85 Correct 929 ms 67968 KB Output is correct
86 Correct 2040 ms 97268 KB Output is correct
87 Correct 2005 ms 107236 KB Output is correct
88 Correct 1072 ms 68016 KB Output is correct
89 Correct 1721 ms 102272 KB Output is correct
90 Correct 1826 ms 107436 KB Output is correct
91 Correct 1052 ms 68052 KB Output is correct
92 Correct 1281 ms 96904 KB Output is correct
93 Correct 932 ms 67944 KB Output is correct
94 Correct 919 ms 67844 KB Output is correct
95 Correct 928 ms 68064 KB Output is correct
96 Correct 2350 ms 107156 KB Output is correct
97 Correct 1075 ms 107296 KB Output is correct
98 Correct 1448 ms 93188 KB Output is correct
99 Correct 3180 ms 107752 KB Output is correct
100 Correct 510 ms 106616 KB Output is correct