답안 #1086639

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1086639 2024-09-11T07:43:50 Z peacebringer1667 Crossing (JOI21_crossing) C++17
49 / 100
355 ms 19696 KB
#include<bits/stdc++.h>
#define ll long long
#define ldb long double
#define fi first
#define se second
#define sza(a) (int)a.size()
#define pir pair<int,int>
#define pirll pair<ll,ll>
using namespace std;
const int base = 137;
const int modu = 1e9 + 7;
const int maxn = 2e5 + 5;

//////////
int pw[maxn],pre[maxn];
char gc(int x){
	if (x == 1) return 'J';
	if (x == 2) return 'O';
	return 'I';
}
int gn(char x){
	if (x == 'J') return 1;
	if (x == 'O') return 2;
	return 3;
}
struct Hash{
	vector <int> pre;
	
	void hashing(const string&s){
		if (!s.size()) return;
		pre.clear();
		pre.push_back((ll)pw[1] * (ll)(s[0] - 96) % modu);
		
		for (int i = 1 ; i < s.size() ; i++)
		  pre.push_back(((ll)pre[i - 1] + (ll)(s[i] - 96) * (ll)pw[i + 1] % modu) % modu);
	    
	    for (int &t : pre)
	      if (t < 0) t += modu;
	}
	
	int Val(){
		if (!pre.size()) return -1;
		return pre.back();
	}
};
void prepare_pw(int n){
	for (int i = 0 ; i <= n ; i++){
	  pw[i] = (!i) ? 1 : (ll)pw[i - 1] * (ll)base % modu;
      pre[i] = (!i) ? 1 : (ll)(pre[i - 1] + pw[i]) % modu;
	}
}
set <int> s;
vector <string> S;
bool contain(int x){
	if (!s.size() || *s.rbegin() < x) return 0;
	
	int y = *s.lower_bound(x);
	return (y == x);
}
string Xor(const string &a,const string &b){
	string c = a;
	
	for (int i = 0 ; i < a.size() ; i++){
	    int x = 6 - gn(a[i]) - gn(b[i]);
	    if (x % 3 == 0) x = 3;
	    else x %= 3;
	    
	    c[i] = gc(x);
	  }
	return c;
}
void insertion(const string &t){
	Hash Hash;
	Hash.hashing(t);
	
	if (contain(Hash.Val())) return;
	s.insert(Hash.Val());
	S.push_back(t);
	
	vector <string> lst;
	
	for (const string &st : S){
		string k = Xor(t,st);
		
		Hash.hashing(k);
		if (!contain(Hash.Val()))
		  lst.push_back(k);
	}
	
	if (lst.size())
	  for (const string &k : lst)
	    insertion(k); 
}
void gen_string(int N){
	for (int id = 1 ; id <= 3 ; id++){
		string t;
		cin >> t;
		insertion(t);
	}
}
////////////

struct segment_tree{
	int seg[4*maxn],lazy[4*maxn];
	
	void downlazy(int v,int l,int r){
		if (!lazy[v]) return;
		
		int sum = (pre[r] - pre[l - 1]) % modu;
		seg[v] = (ll)sum * (ll)lazy[v] % modu;
		
		if (l != r){
			lazy[2*v + 1] = lazy[v];
			lazy[2*v + 2] = lazy[v];
		}
		lazy[v] = 0;
	}
	
	void update(int l,int r,int v,int lx,int rx,int val){
		downlazy(v,l,r);
		
		if (l > rx || r < lx) return;
		if (l >= lx && r <= rx){
			lazy[v] = val;
			downlazy(v,l,r);
			return;
		}
		
		int w = (l + r)/2;
		update(l,w,2*v + 1,lx,rx,val);
		update(w + 1,r,2*v + 2,lx,rx,val);
		seg[v] = (ll)(seg[2*v + 1] + seg[2*v + 2]) % modu;
	}
	
	int calc(){
		if (seg[0] < 0) seg[0] += modu;
		return seg[0];
	}
} seg;

void print_ans(bool x){
	if (x) cout << "Yes";
	else cout << "No";
	cout << "\n";
}

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
	
	//freopen("crossing.inp","r",stdin);
//	freopen("crossing.out","w",stdout);
	int N;
	cin >> N;
	prepare_pw(N);
	gen_string(N);
	
	int Q;
    string QR;
    cin >> Q >> QR;
    for (int i = 1 ; i <= N ; i++)
      seg.update(1,N,0,i,i,(int)QR[i - 1] - 96);
    
	print_ans(contain(seg.calc()));
    while (Q--){
    	int l,r;char c;
    	cin >> l >> r >> c;
    	seg.update(1,N,0,l,r,c - 96);
    	
    	print_ans(contain(seg.calc()));
	}
    
	return 0;
}

Compilation message

Main.cpp: In member function 'void Hash::hashing(const string&)':
Main.cpp:34:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   34 |   for (int i = 1 ; i < s.size() ; i++)
      |                    ~~^~~~~~~~~~
Main.cpp: In function 'std::string Xor(const string&, const string&)':
Main.cpp:63:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   63 |  for (int i = 0 ; i < a.size() ; i++){
      |                   ~~^~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 50 ms 2384 KB Output is correct
2 Correct 56 ms 2496 KB Output is correct
3 Correct 55 ms 2256 KB Output is correct
4 Correct 46 ms 2392 KB Output is correct
5 Correct 47 ms 2384 KB Output is correct
6 Correct 47 ms 2384 KB Output is correct
7 Correct 47 ms 2388 KB Output is correct
8 Correct 49 ms 2380 KB Output is correct
9 Correct 50 ms 2416 KB Output is correct
10 Correct 55 ms 2388 KB Output is correct
11 Correct 50 ms 2356 KB Output is correct
12 Correct 48 ms 2552 KB Output is correct
13 Correct 55 ms 2388 KB Output is correct
14 Correct 49 ms 2388 KB Output is correct
15 Correct 51 ms 2388 KB Output is correct
16 Correct 50 ms 2432 KB Output is correct
17 Correct 51 ms 2524 KB Output is correct
18 Correct 51 ms 2416 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 50 ms 2384 KB Output is correct
2 Correct 56 ms 2496 KB Output is correct
3 Correct 55 ms 2256 KB Output is correct
4 Correct 46 ms 2392 KB Output is correct
5 Correct 47 ms 2384 KB Output is correct
6 Correct 47 ms 2384 KB Output is correct
7 Correct 47 ms 2388 KB Output is correct
8 Correct 49 ms 2380 KB Output is correct
9 Correct 50 ms 2416 KB Output is correct
10 Correct 55 ms 2388 KB Output is correct
11 Correct 50 ms 2356 KB Output is correct
12 Correct 48 ms 2552 KB Output is correct
13 Correct 55 ms 2388 KB Output is correct
14 Correct 49 ms 2388 KB Output is correct
15 Correct 51 ms 2388 KB Output is correct
16 Correct 50 ms 2432 KB Output is correct
17 Correct 51 ms 2524 KB Output is correct
18 Correct 51 ms 2416 KB Output is correct
19 Correct 198 ms 10784 KB Output is correct
20 Correct 206 ms 10496 KB Output is correct
21 Correct 144 ms 10576 KB Output is correct
22 Correct 143 ms 10228 KB Output is correct
23 Correct 78 ms 3664 KB Output is correct
24 Correct 82 ms 3664 KB Output is correct
25 Correct 161 ms 10824 KB Output is correct
26 Correct 156 ms 10796 KB Output is correct
27 Correct 176 ms 10824 KB Output is correct
28 Correct 171 ms 10828 KB Output is correct
29 Correct 211 ms 10868 KB Output is correct
30 Correct 89 ms 3664 KB Output is correct
31 Correct 172 ms 10820 KB Output is correct
32 Correct 168 ms 10540 KB Output is correct
33 Correct 82 ms 3664 KB Output is correct
34 Correct 174 ms 10820 KB Output is correct
35 Correct 140 ms 9976 KB Output is correct
36 Correct 83 ms 3664 KB Output is correct
37 Correct 93 ms 3668 KB Output is correct
38 Correct 190 ms 10312 KB Output is correct
39 Correct 137 ms 10500 KB Output is correct
40 Correct 130 ms 7852 KB Output is correct
41 Correct 225 ms 11044 KB Output is correct
42 Correct 91 ms 9804 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 50 ms 2384 KB Output is correct
2 Correct 56 ms 2496 KB Output is correct
3 Correct 55 ms 2256 KB Output is correct
4 Correct 46 ms 2392 KB Output is correct
5 Correct 47 ms 2384 KB Output is correct
6 Correct 47 ms 2384 KB Output is correct
7 Correct 47 ms 2388 KB Output is correct
8 Correct 49 ms 2380 KB Output is correct
9 Correct 50 ms 2416 KB Output is correct
10 Correct 55 ms 2388 KB Output is correct
11 Correct 50 ms 2356 KB Output is correct
12 Correct 48 ms 2552 KB Output is correct
13 Correct 55 ms 2388 KB Output is correct
14 Correct 49 ms 2388 KB Output is correct
15 Correct 51 ms 2388 KB Output is correct
16 Correct 50 ms 2432 KB Output is correct
17 Correct 51 ms 2524 KB Output is correct
18 Correct 51 ms 2416 KB Output is correct
19 Correct 55 ms 2460 KB Output is correct
20 Correct 57 ms 2388 KB Output is correct
21 Correct 49 ms 2384 KB Output is correct
22 Correct 46 ms 2388 KB Output is correct
23 Correct 51 ms 2572 KB Output is correct
24 Correct 51 ms 2388 KB Output is correct
25 Correct 51 ms 2560 KB Output is correct
26 Correct 46 ms 2388 KB Output is correct
27 Correct 49 ms 2472 KB Output is correct
28 Correct 46 ms 2384 KB Output is correct
29 Correct 50 ms 2384 KB Output is correct
30 Correct 47 ms 2388 KB Output is correct
31 Correct 52 ms 2384 KB Output is correct
32 Correct 51 ms 2388 KB Output is correct
33 Correct 60 ms 2596 KB Output is correct
34 Correct 47 ms 2384 KB Output is correct
35 Correct 52 ms 2388 KB Output is correct
36 Correct 52 ms 2644 KB Output is correct
37 Correct 56 ms 2644 KB Output is correct
38 Correct 52 ms 2384 KB Output is correct
39 Correct 53 ms 2544 KB Output is correct
40 Correct 52 ms 2388 KB Output is correct
41 Correct 52 ms 2388 KB Output is correct
42 Correct 54 ms 2644 KB Output is correct
43 Correct 51 ms 2388 KB Output is correct
44 Correct 53 ms 2388 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 50 ms 2384 KB Output is correct
2 Correct 56 ms 2496 KB Output is correct
3 Correct 55 ms 2256 KB Output is correct
4 Correct 46 ms 2392 KB Output is correct
5 Correct 47 ms 2384 KB Output is correct
6 Correct 47 ms 2384 KB Output is correct
7 Correct 47 ms 2388 KB Output is correct
8 Correct 49 ms 2380 KB Output is correct
9 Correct 50 ms 2416 KB Output is correct
10 Correct 55 ms 2388 KB Output is correct
11 Correct 50 ms 2356 KB Output is correct
12 Correct 48 ms 2552 KB Output is correct
13 Correct 55 ms 2388 KB Output is correct
14 Correct 49 ms 2388 KB Output is correct
15 Correct 51 ms 2388 KB Output is correct
16 Correct 50 ms 2432 KB Output is correct
17 Correct 51 ms 2524 KB Output is correct
18 Correct 51 ms 2416 KB Output is correct
19 Correct 198 ms 10784 KB Output is correct
20 Correct 206 ms 10496 KB Output is correct
21 Correct 144 ms 10576 KB Output is correct
22 Correct 143 ms 10228 KB Output is correct
23 Correct 78 ms 3664 KB Output is correct
24 Correct 82 ms 3664 KB Output is correct
25 Correct 161 ms 10824 KB Output is correct
26 Correct 156 ms 10796 KB Output is correct
27 Correct 176 ms 10824 KB Output is correct
28 Correct 171 ms 10828 KB Output is correct
29 Correct 211 ms 10868 KB Output is correct
30 Correct 89 ms 3664 KB Output is correct
31 Correct 172 ms 10820 KB Output is correct
32 Correct 168 ms 10540 KB Output is correct
33 Correct 82 ms 3664 KB Output is correct
34 Correct 174 ms 10820 KB Output is correct
35 Correct 140 ms 9976 KB Output is correct
36 Correct 83 ms 3664 KB Output is correct
37 Correct 93 ms 3668 KB Output is correct
38 Correct 190 ms 10312 KB Output is correct
39 Correct 137 ms 10500 KB Output is correct
40 Correct 130 ms 7852 KB Output is correct
41 Correct 225 ms 11044 KB Output is correct
42 Correct 91 ms 9804 KB Output is correct
43 Correct 55 ms 2460 KB Output is correct
44 Correct 57 ms 2388 KB Output is correct
45 Correct 49 ms 2384 KB Output is correct
46 Correct 46 ms 2388 KB Output is correct
47 Correct 51 ms 2572 KB Output is correct
48 Correct 51 ms 2388 KB Output is correct
49 Correct 51 ms 2560 KB Output is correct
50 Correct 46 ms 2388 KB Output is correct
51 Correct 49 ms 2472 KB Output is correct
52 Correct 46 ms 2384 KB Output is correct
53 Correct 50 ms 2384 KB Output is correct
54 Correct 47 ms 2388 KB Output is correct
55 Correct 52 ms 2384 KB Output is correct
56 Correct 51 ms 2388 KB Output is correct
57 Correct 60 ms 2596 KB Output is correct
58 Correct 47 ms 2384 KB Output is correct
59 Correct 52 ms 2388 KB Output is correct
60 Correct 52 ms 2644 KB Output is correct
61 Correct 56 ms 2644 KB Output is correct
62 Correct 52 ms 2384 KB Output is correct
63 Correct 53 ms 2544 KB Output is correct
64 Correct 52 ms 2388 KB Output is correct
65 Correct 52 ms 2388 KB Output is correct
66 Correct 54 ms 2644 KB Output is correct
67 Correct 51 ms 2388 KB Output is correct
68 Correct 53 ms 2388 KB Output is correct
69 Correct 302 ms 16332 KB Output is correct
70 Correct 355 ms 19124 KB Output is correct
71 Correct 88 ms 3872 KB Output is correct
72 Correct 82 ms 3872 KB Output is correct
73 Correct 81 ms 3872 KB Output is correct
74 Correct 150 ms 10532 KB Output is correct
75 Correct 80 ms 3876 KB Output is correct
76 Correct 177 ms 11352 KB Output is correct
77 Correct 157 ms 10552 KB Output is correct
78 Correct 82 ms 3868 KB Output is correct
79 Correct 82 ms 3988 KB Output is correct
80 Correct 248 ms 15424 KB Output is correct
81 Correct 90 ms 4020 KB Output is correct
82 Correct 332 ms 19696 KB Output is correct
83 Correct 288 ms 17580 KB Output is correct
84 Correct 88 ms 4068 KB Output is correct
85 Correct 90 ms 4040 KB Output is correct
86 Correct 222 ms 15788 KB Output is correct
87 Correct 250 ms 19668 KB Output is correct
88 Correct 92 ms 4012 KB Output is correct
89 Correct 228 ms 17224 KB Output is correct
90 Correct 253 ms 19632 KB Output is correct
91 Correct 94 ms 4020 KB Output is correct
92 Incorrect 246 ms 15760 KB Output isn't correct
93 Halted 0 ms 0 KB -