답안 #521118

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
521118 2022-01-31T19:05:48 Z new_acc Crossing (JOI21_crossing) C++14
100 / 100
872 ms 17744 KB
#include<bits/stdc++.h>
#define fi first
#define se second
#define rep(a, b) for(int a = 0; a < (b); a++)
using namespace std;
typedef long long ll;
typedef vector<ll> vi;
typedef vector<ll> vl;
const int N=2e5+10;
const ll mod=1000*1000*1000+7;
const ll p=70032301;
const int SS=1<<19;
unordered_map<ll,bool> m;
vector<string> v;
ll seg[SS*2+10],lazy[SS*2+10];
ll sum[N],pot[N];
ll ustaw(int l,int r,ll x){
	return (sum[r-l]*x)%mod;
}
void push(int v,int l,int r){
	if(lazy[v]==0) return;
	seg[v*2]=ustaw(l,(l+r)/2,lazy[v]),seg[v*2+1]=ustaw((l+r)/2+1,r,lazy[v]);
	lazy[v*2]=lazy[v],lazy[v*2+1]=lazy[v];
	lazy[v]=0;
}
void Insert(int pocz,int kon,int x,int p=0,int k=SS-1,int v=1){
	if(p>kon or k<pocz) return;
	if(p>=pocz and k<=kon) lazy[v]=x,seg[v]=ustaw(p,k,x);
	else{
		push(v,p,k);
		Insert(pocz,kon,x,p,(p+k)/2,v*2),Insert(pocz,kon,x,(p+k)/2+1,k,v*2+1);
		(seg[v]=seg[v*2]+seg[v*2+1]*pot[(k-p+1)/2])%=mod;
	}
}
bool hhash(string x){
	ll h=0;
	for(int i=x.size()-1;i>=0;i--) (h*=p)%=mod,(h+=int(x[i])-64)%=mod;
	if(m[h]) return 0;
	m[h]=1;
	v.push_back(x);
	return 1;
}
string cross(string a,string b){
	string res="";
	rep(i,a.size()){
		if(a[i]==b[i]) res+=a[i];
		else{
			if((a[i]=='J' and b[i]=='O') or (a[i]=='O' and b[i]=='J')) res+='I';
			if((a[i]=='I' and b[i]=='O') or (a[i]=='O' and b[i]=='I')) res+='J';
			if((a[i]=='J' and b[i]=='I') or (a[i]=='I' and b[i]=='J')) res+='O';
		}
	}
	return res;
}
void solve(){
	int n;
	cin>>n;
	string s1,s2,s3;
	cin>>s1>>s2>>s3;
	v.push_back(s1),v.push_back(s2),v.push_back(s3);
	ll pp=1;
	rep(i,n+10) pot[i]=pp,(sum[i]=(i==0?0:sum[i-1])+pp)%=mod,(pp*=p)%=mod;
	bool b=1;
	while(b){
		b=0;
		rep(i,v.size()){
			for(int j=i+1;j<v.size();j++){
				string xd=cross(v[i],v[j]);
				if(hhash(xd)) {b=1;break;}
			}
			if(b) break;
		}
	}
	int q;
	cin>>q;
	rep(i,n){
		char a;
		cin>>a;
		Insert(i,i,int(a)-64);
	}
	cout<<(m.count(seg[1])>0?"Yes":"No")<<"\n";
	for(int i=1;i<=q;i++){
		int a,b;
		char c;
		cin>>a>>b;
		a--,b--;
		cin>>c;
		Insert(a,b,int(c)-64);	
		cout<<(m.count(seg[1])>0?"Yes":"No")<<"\n";
	}
}
int main(){
	ios_base::sync_with_stdio(0),cin.tie(0);
	solve();
}

Compilation message

Main.cpp: In function 'std::string cross(std::string, std::string)':
Main.cpp:4:36: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    4 | #define rep(a, b) for(int a = 0; a < (b); a++)
      |                                    ^
Main.cpp:45:2: note: in expansion of macro 'rep'
   45 |  rep(i,a.size()){
      |  ^~~
Main.cpp: In function 'void solve()':
Main.cpp:4:36: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::__cxx11::basic_string<char> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    4 | #define rep(a, b) for(int a = 0; a < (b); a++)
      |                                    ^
Main.cpp:66:3: note: in expansion of macro 'rep'
   66 |   rep(i,v.size()){
      |   ^~~
Main.cpp:67:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::__cxx11::basic_string<char> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   67 |    for(int j=i+1;j<v.size();j++){
      |                  ~^~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 94 ms 2360 KB Output is correct
2 Correct 110 ms 2444 KB Output is correct
3 Correct 107 ms 2312 KB Output is correct
4 Correct 96 ms 2524 KB Output is correct
5 Correct 91 ms 2428 KB Output is correct
6 Correct 88 ms 2380 KB Output is correct
7 Correct 101 ms 2592 KB Output is correct
8 Correct 116 ms 2552 KB Output is correct
9 Correct 97 ms 2460 KB Output is correct
10 Correct 93 ms 2472 KB Output is correct
11 Correct 98 ms 2556 KB Output is correct
12 Correct 96 ms 2464 KB Output is correct
13 Correct 105 ms 2516 KB Output is correct
14 Correct 96 ms 2516 KB Output is correct
15 Correct 98 ms 2500 KB Output is correct
16 Correct 94 ms 2492 KB Output is correct
17 Correct 95 ms 2492 KB Output is correct
18 Correct 104 ms 2532 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 94 ms 2360 KB Output is correct
2 Correct 110 ms 2444 KB Output is correct
3 Correct 107 ms 2312 KB Output is correct
4 Correct 96 ms 2524 KB Output is correct
5 Correct 91 ms 2428 KB Output is correct
6 Correct 88 ms 2380 KB Output is correct
7 Correct 101 ms 2592 KB Output is correct
8 Correct 116 ms 2552 KB Output is correct
9 Correct 97 ms 2460 KB Output is correct
10 Correct 93 ms 2472 KB Output is correct
11 Correct 98 ms 2556 KB Output is correct
12 Correct 96 ms 2464 KB Output is correct
13 Correct 105 ms 2516 KB Output is correct
14 Correct 96 ms 2516 KB Output is correct
15 Correct 98 ms 2500 KB Output is correct
16 Correct 94 ms 2492 KB Output is correct
17 Correct 95 ms 2492 KB Output is correct
18 Correct 104 ms 2532 KB Output is correct
19 Correct 286 ms 15752 KB Output is correct
20 Correct 276 ms 14488 KB Output is correct
21 Correct 208 ms 14860 KB Output is correct
22 Correct 239 ms 13744 KB Output is correct
23 Correct 118 ms 3900 KB Output is correct
24 Correct 120 ms 3872 KB Output is correct
25 Correct 245 ms 15804 KB Output is correct
26 Correct 232 ms 15784 KB Output is correct
27 Correct 250 ms 15720 KB Output is correct
28 Correct 244 ms 15836 KB Output is correct
29 Correct 226 ms 15428 KB Output is correct
30 Correct 140 ms 4024 KB Output is correct
31 Correct 260 ms 15776 KB Output is correct
32 Correct 231 ms 14716 KB Output is correct
33 Correct 117 ms 3916 KB Output is correct
34 Correct 261 ms 15704 KB Output is correct
35 Correct 191 ms 12548 KB Output is correct
36 Correct 122 ms 3984 KB Output is correct
37 Correct 117 ms 3868 KB Output is correct
38 Correct 253 ms 14372 KB Output is correct
39 Correct 197 ms 14180 KB Output is correct
40 Correct 182 ms 11596 KB Output is correct
41 Correct 304 ms 16328 KB Output is correct
42 Correct 160 ms 13572 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 94 ms 2360 KB Output is correct
2 Correct 110 ms 2444 KB Output is correct
3 Correct 107 ms 2312 KB Output is correct
4 Correct 96 ms 2524 KB Output is correct
5 Correct 91 ms 2428 KB Output is correct
6 Correct 88 ms 2380 KB Output is correct
7 Correct 101 ms 2592 KB Output is correct
8 Correct 116 ms 2552 KB Output is correct
9 Correct 97 ms 2460 KB Output is correct
10 Correct 93 ms 2472 KB Output is correct
11 Correct 98 ms 2556 KB Output is correct
12 Correct 96 ms 2464 KB Output is correct
13 Correct 105 ms 2516 KB Output is correct
14 Correct 96 ms 2516 KB Output is correct
15 Correct 98 ms 2500 KB Output is correct
16 Correct 94 ms 2492 KB Output is correct
17 Correct 95 ms 2492 KB Output is correct
18 Correct 104 ms 2532 KB Output is correct
19 Correct 107 ms 2388 KB Output is correct
20 Correct 118 ms 2436 KB Output is correct
21 Correct 101 ms 2468 KB Output is correct
22 Correct 91 ms 2276 KB Output is correct
23 Correct 96 ms 2536 KB Output is correct
24 Correct 99 ms 2512 KB Output is correct
25 Correct 95 ms 2556 KB Output is correct
26 Correct 91 ms 2360 KB Output is correct
27 Correct 96 ms 2532 KB Output is correct
28 Correct 86 ms 2244 KB Output is correct
29 Correct 96 ms 2512 KB Output is correct
30 Correct 88 ms 2372 KB Output is correct
31 Correct 102 ms 2488 KB Output is correct
32 Correct 98 ms 2420 KB Output is correct
33 Correct 110 ms 2560 KB Output is correct
34 Correct 129 ms 2384 KB Output is correct
35 Correct 98 ms 2500 KB Output is correct
36 Correct 101 ms 2500 KB Output is correct
37 Correct 105 ms 2504 KB Output is correct
38 Correct 132 ms 2556 KB Output is correct
39 Correct 98 ms 2552 KB Output is correct
40 Correct 101 ms 2500 KB Output is correct
41 Correct 108 ms 2516 KB Output is correct
42 Correct 133 ms 2476 KB Output is correct
43 Correct 95 ms 2504 KB Output is correct
44 Correct 111 ms 2560 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 94 ms 2360 KB Output is correct
2 Correct 110 ms 2444 KB Output is correct
3 Correct 107 ms 2312 KB Output is correct
4 Correct 96 ms 2524 KB Output is correct
5 Correct 91 ms 2428 KB Output is correct
6 Correct 88 ms 2380 KB Output is correct
7 Correct 101 ms 2592 KB Output is correct
8 Correct 116 ms 2552 KB Output is correct
9 Correct 97 ms 2460 KB Output is correct
10 Correct 93 ms 2472 KB Output is correct
11 Correct 98 ms 2556 KB Output is correct
12 Correct 96 ms 2464 KB Output is correct
13 Correct 105 ms 2516 KB Output is correct
14 Correct 96 ms 2516 KB Output is correct
15 Correct 98 ms 2500 KB Output is correct
16 Correct 94 ms 2492 KB Output is correct
17 Correct 95 ms 2492 KB Output is correct
18 Correct 104 ms 2532 KB Output is correct
19 Correct 286 ms 15752 KB Output is correct
20 Correct 276 ms 14488 KB Output is correct
21 Correct 208 ms 14860 KB Output is correct
22 Correct 239 ms 13744 KB Output is correct
23 Correct 118 ms 3900 KB Output is correct
24 Correct 120 ms 3872 KB Output is correct
25 Correct 245 ms 15804 KB Output is correct
26 Correct 232 ms 15784 KB Output is correct
27 Correct 250 ms 15720 KB Output is correct
28 Correct 244 ms 15836 KB Output is correct
29 Correct 226 ms 15428 KB Output is correct
30 Correct 140 ms 4024 KB Output is correct
31 Correct 260 ms 15776 KB Output is correct
32 Correct 231 ms 14716 KB Output is correct
33 Correct 117 ms 3916 KB Output is correct
34 Correct 261 ms 15704 KB Output is correct
35 Correct 191 ms 12548 KB Output is correct
36 Correct 122 ms 3984 KB Output is correct
37 Correct 117 ms 3868 KB Output is correct
38 Correct 253 ms 14372 KB Output is correct
39 Correct 197 ms 14180 KB Output is correct
40 Correct 182 ms 11596 KB Output is correct
41 Correct 304 ms 16328 KB Output is correct
42 Correct 160 ms 13572 KB Output is correct
43 Correct 107 ms 2388 KB Output is correct
44 Correct 118 ms 2436 KB Output is correct
45 Correct 101 ms 2468 KB Output is correct
46 Correct 91 ms 2276 KB Output is correct
47 Correct 96 ms 2536 KB Output is correct
48 Correct 99 ms 2512 KB Output is correct
49 Correct 95 ms 2556 KB Output is correct
50 Correct 91 ms 2360 KB Output is correct
51 Correct 96 ms 2532 KB Output is correct
52 Correct 86 ms 2244 KB Output is correct
53 Correct 96 ms 2512 KB Output is correct
54 Correct 88 ms 2372 KB Output is correct
55 Correct 102 ms 2488 KB Output is correct
56 Correct 98 ms 2420 KB Output is correct
57 Correct 110 ms 2560 KB Output is correct
58 Correct 129 ms 2384 KB Output is correct
59 Correct 98 ms 2500 KB Output is correct
60 Correct 101 ms 2500 KB Output is correct
61 Correct 105 ms 2504 KB Output is correct
62 Correct 132 ms 2556 KB Output is correct
63 Correct 98 ms 2552 KB Output is correct
64 Correct 101 ms 2500 KB Output is correct
65 Correct 108 ms 2516 KB Output is correct
66 Correct 133 ms 2476 KB Output is correct
67 Correct 95 ms 2504 KB Output is correct
68 Correct 111 ms 2560 KB Output is correct
69 Correct 755 ms 14844 KB Output is correct
70 Correct 872 ms 16084 KB Output is correct
71 Correct 126 ms 3904 KB Output is correct
72 Correct 124 ms 3988 KB Output is correct
73 Correct 138 ms 4048 KB Output is correct
74 Correct 273 ms 13956 KB Output is correct
75 Correct 132 ms 3964 KB Output is correct
76 Correct 353 ms 16184 KB Output is correct
77 Correct 285 ms 14056 KB Output is correct
78 Correct 139 ms 3916 KB Output is correct
79 Correct 135 ms 4012 KB Output is correct
80 Correct 632 ms 13192 KB Output is correct
81 Correct 158 ms 3996 KB Output is correct
82 Correct 832 ms 17268 KB Output is correct
83 Correct 818 ms 16504 KB Output is correct
84 Correct 149 ms 3976 KB Output is correct
85 Correct 146 ms 4028 KB Output is correct
86 Correct 496 ms 14044 KB Output is correct
87 Correct 617 ms 17408 KB Output is correct
88 Correct 148 ms 3988 KB Output is correct
89 Correct 549 ms 15640 KB Output is correct
90 Correct 618 ms 17368 KB Output is correct
91 Correct 150 ms 3952 KB Output is correct
92 Correct 642 ms 13824 KB Output is correct
93 Correct 162 ms 4036 KB Output is correct
94 Correct 150 ms 3984 KB Output is correct
95 Correct 161 ms 4028 KB Output is correct
96 Correct 270 ms 14348 KB Output is correct
97 Correct 559 ms 15764 KB Output is correct
98 Correct 622 ms 12820 KB Output is correct
99 Correct 851 ms 17744 KB Output is correct
100 Correct 700 ms 15160 KB Output is correct