답안 #479400

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
479400 2021-10-11T15:25:55 Z Arvin Crossing (JOI21_crossing) C++11
100 / 100
460 ms 18628 KB
#include <bits/stdc++.h>

using namespace std;

#define ull unsigned long long
#define ll long long
#define ui unsigned int
#define us unsigned short
#define inf_int 1e9
#define inf_ll 1e18
#define mod 1000000007
#define smod 998244353

const int maxN = 2e5 + 5;
const ll base = 2309;

ll n;
ll prefix[maxN];
string t;

ll convert(char c){
	if(c == 'J') return 0;
	else if(c == 'O') return 1;
	else if(c == 'I') return 2;
	return 3;
}

struct SegTree { // index start from 0 (v)
	ll tree[4*maxN], lazy[4*maxN];
	
	void build(int v, int l, int r){
		if(l > r) return;
		if(l == r){
			tree[v] = (prefix[l] - (l > 0 ? prefix[l-1] : 0) + mod) % mod * convert(t[l]) % mod;
			lazy[v] = -1;
			return;
		}
		
		int m = (l+r) >> 1;
		build(v*2+1, l, m);
		build(v*2+2, m+1, r);
		
		tree[v] = (tree[v*2+1] + tree[v*2+2]) % mod;
		lazy[v] = -1;
	}
	
	void push(int v, int l, int m, int r){
		if(lazy[v] == -1) return;
		
		tree[v*2+1] = (prefix[m] - (l > 0 ? prefix[l-1] : 0) + 2*mod) % mod * lazy[v] % mod;
		lazy[v*2+1] = lazy[v];
		
		tree[v*2+2] = (prefix[r] - prefix[m] + 2*mod) % mod * lazy[v] % mod;
		lazy[v*2+2] = lazy[v];
		
		lazy[v] = -1;
	}
	
	void update(int v, int curL, int curR, int l, int r, ll val){
		if(l > r || curL > curR) return;
		if(curL == l && r == curR){
			tree[v] = (prefix[curR] - (curL > 0 ? prefix[curL-1] : 0) + 2*mod) % mod * val % mod;
			lazy[v] = val;
		} else {
			int curM = (curL+curR) >> 1;
			
			push(v, curL, curM, curR);
			
			update(v*2+1, curL, curM, l, min(r, curM), val);
			update(v*2+2, curM+1, curR, max(l, curM+1), r, val);
			
			tree[v] = (tree[v*2+1] + tree[v*2+2]) % mod;
		}
	}
	
	ll query(int v, int curL, int curR, int l, int r){
		if(l > r || curL > curR) return 0;
		if(l <= curL && curR <= r){
			return tree[v];
		}
		
		int curM = (curL+curR) >> 1;

		push(v, curL, curM, curR);
		
		return (query(v*2+1, curL, curM, l, min(r, curM)) + query(v*2+2, curM+1, curR, max(l, curM+1), r)) % mod;
	}
};

SegTree tree;

int main(){
	ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
//	freopen("JOI2021-Crossing.in","r",stdin);
	
	cin >> n;
	
	ll cur = 1;
	prefix[0] = 1;
	for(int x=1;x<maxN;x++){
		cur *= base;
		cur %= mod;
		prefix[x] = (prefix[x-1] + cur) % mod;
	}
	
	set<string> st;
	vector<string> v;
	
	for(int x=0;x<3;x++){
		string s;
		cin >> s;
		
		if(!st.count(s)){
			st.insert(s);
			v.push_back(s);
		}
	}
	
	for(int x=0;x<v.size();x++){
		for(int y=0;y<x;y++){
			string tmp;
			for(int z=0;z<v[x].length();z++){
				if(v[x][z] == v[y][z]){
					tmp.push_back(v[x][z]);
				} else {
					int bit = (1 << convert(v[x][z]));
					bit |= (1 << convert(v[y][z]));
					
					for(int i=0;i<3;i++){
						if(!(bit&(1<<i))){
							if(i == 0) tmp.push_back('J');
							else if(i == 1) tmp.push_back('O');
							else tmp.push_back('I');
							break;
						}
					}
				}
			}
			
			if(!st.count(tmp)){
				st.insert(tmp);
				v.push_back(tmp);
			}
		}
	}
	
	set<ll> st2;
	for(auto s : st){
		ll val = 0, cur = 1;
		for(int x=0;x<n;x++){
			val += convert(s[x]) * cur % mod;
			val %= mod;
			cur *= base;
			cur %= mod;
		}
		
//		cout << s << "\n";
		st2.insert(val);
	}
	
	int q;
	cin >> q;
	
	cin >> t;
	
	tree.build(0, 0, n-1);
	
	if(st2.count(tree.query(0, 0, n-1, 0, n-1))){
		cout << "Yes\n";
	} else {
		cout << "No\n";
	}
	
	for(int i=1;i<=q;i++){
		int l, r;
		char c;
		cin >> l >> r >> c;
		
		l--; r--;
		tree.update(0, 0, n-1, l, r, convert(c));
		
		if(st2.count(tree.query(0, 0, n-1, 0, n-1))){
			cout << "Yes\n";
		} else {
			cout << "No\n";
		}
	}
	
    return 0;
}

Compilation message

Main.cpp: In function 'int main()':
Main.cpp:121:15: 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]
  121 |  for(int x=0;x<v.size();x++){
      |              ~^~~~~~~~~
Main.cpp:124:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  124 |    for(int z=0;z<v[x].length();z++){
      |                ~^~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 79 ms 2440 KB Output is correct
2 Correct 81 ms 2368 KB Output is correct
3 Correct 79 ms 2396 KB Output is correct
4 Correct 69 ms 2372 KB Output is correct
5 Correct 75 ms 2424 KB Output is correct
6 Correct 67 ms 2404 KB Output is correct
7 Correct 67 ms 2372 KB Output is correct
8 Correct 78 ms 2400 KB Output is correct
9 Correct 82 ms 2376 KB Output is correct
10 Correct 73 ms 2372 KB Output is correct
11 Correct 83 ms 2612 KB Output is correct
12 Correct 80 ms 2368 KB Output is correct
13 Correct 75 ms 2372 KB Output is correct
14 Correct 74 ms 2404 KB Output is correct
15 Correct 72 ms 2372 KB Output is correct
16 Correct 73 ms 2408 KB Output is correct
17 Correct 77 ms 2484 KB Output is correct
18 Correct 77 ms 2424 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 79 ms 2440 KB Output is correct
2 Correct 81 ms 2368 KB Output is correct
3 Correct 79 ms 2396 KB Output is correct
4 Correct 69 ms 2372 KB Output is correct
5 Correct 75 ms 2424 KB Output is correct
6 Correct 67 ms 2404 KB Output is correct
7 Correct 67 ms 2372 KB Output is correct
8 Correct 78 ms 2400 KB Output is correct
9 Correct 82 ms 2376 KB Output is correct
10 Correct 73 ms 2372 KB Output is correct
11 Correct 83 ms 2612 KB Output is correct
12 Correct 80 ms 2368 KB Output is correct
13 Correct 75 ms 2372 KB Output is correct
14 Correct 74 ms 2404 KB Output is correct
15 Correct 72 ms 2372 KB Output is correct
16 Correct 73 ms 2408 KB Output is correct
17 Correct 77 ms 2484 KB Output is correct
18 Correct 77 ms 2424 KB Output is correct
19 Correct 270 ms 12556 KB Output is correct
20 Correct 229 ms 15160 KB Output is correct
21 Correct 167 ms 15016 KB Output is correct
22 Correct 181 ms 14904 KB Output is correct
23 Correct 114 ms 5316 KB Output is correct
24 Correct 114 ms 5340 KB Output is correct
25 Correct 197 ms 15292 KB Output is correct
26 Correct 206 ms 15368 KB Output is correct
27 Correct 206 ms 15188 KB Output is correct
28 Correct 205 ms 15204 KB Output is correct
29 Correct 234 ms 15092 KB Output is correct
30 Correct 123 ms 5328 KB Output is correct
31 Correct 193 ms 15276 KB Output is correct
32 Correct 220 ms 15084 KB Output is correct
33 Correct 122 ms 5332 KB Output is correct
34 Correct 219 ms 15172 KB Output is correct
35 Correct 171 ms 14704 KB Output is correct
36 Correct 119 ms 5380 KB Output is correct
37 Correct 124 ms 5316 KB Output is correct
38 Correct 202 ms 15156 KB Output is correct
39 Correct 140 ms 15292 KB Output is correct
40 Correct 175 ms 10476 KB Output is correct
41 Correct 329 ms 15420 KB Output is correct
42 Correct 50 ms 14720 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 79 ms 2440 KB Output is correct
2 Correct 81 ms 2368 KB Output is correct
3 Correct 79 ms 2396 KB Output is correct
4 Correct 69 ms 2372 KB Output is correct
5 Correct 75 ms 2424 KB Output is correct
6 Correct 67 ms 2404 KB Output is correct
7 Correct 67 ms 2372 KB Output is correct
8 Correct 78 ms 2400 KB Output is correct
9 Correct 82 ms 2376 KB Output is correct
10 Correct 73 ms 2372 KB Output is correct
11 Correct 83 ms 2612 KB Output is correct
12 Correct 80 ms 2368 KB Output is correct
13 Correct 75 ms 2372 KB Output is correct
14 Correct 74 ms 2404 KB Output is correct
15 Correct 72 ms 2372 KB Output is correct
16 Correct 73 ms 2408 KB Output is correct
17 Correct 77 ms 2484 KB Output is correct
18 Correct 77 ms 2424 KB Output is correct
19 Correct 86 ms 2404 KB Output is correct
20 Correct 83 ms 2424 KB Output is correct
21 Correct 83 ms 2372 KB Output is correct
22 Correct 73 ms 2492 KB Output is correct
23 Correct 76 ms 2360 KB Output is correct
24 Correct 77 ms 2400 KB Output is correct
25 Correct 75 ms 2404 KB Output is correct
26 Correct 72 ms 2432 KB Output is correct
27 Correct 72 ms 2380 KB Output is correct
28 Correct 72 ms 2368 KB Output is correct
29 Correct 80 ms 2372 KB Output is correct
30 Correct 67 ms 2412 KB Output is correct
31 Correct 88 ms 2472 KB Output is correct
32 Correct 76 ms 2372 KB Output is correct
33 Correct 79 ms 2488 KB Output is correct
34 Correct 78 ms 2380 KB Output is correct
35 Correct 79 ms 2464 KB Output is correct
36 Correct 82 ms 2472 KB Output is correct
37 Correct 82 ms 2372 KB Output is correct
38 Correct 86 ms 2424 KB Output is correct
39 Correct 84 ms 2476 KB Output is correct
40 Correct 93 ms 2452 KB Output is correct
41 Correct 90 ms 2424 KB Output is correct
42 Correct 92 ms 2380 KB Output is correct
43 Correct 84 ms 2448 KB Output is correct
44 Correct 86 ms 2432 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 79 ms 2440 KB Output is correct
2 Correct 81 ms 2368 KB Output is correct
3 Correct 79 ms 2396 KB Output is correct
4 Correct 69 ms 2372 KB Output is correct
5 Correct 75 ms 2424 KB Output is correct
6 Correct 67 ms 2404 KB Output is correct
7 Correct 67 ms 2372 KB Output is correct
8 Correct 78 ms 2400 KB Output is correct
9 Correct 82 ms 2376 KB Output is correct
10 Correct 73 ms 2372 KB Output is correct
11 Correct 83 ms 2612 KB Output is correct
12 Correct 80 ms 2368 KB Output is correct
13 Correct 75 ms 2372 KB Output is correct
14 Correct 74 ms 2404 KB Output is correct
15 Correct 72 ms 2372 KB Output is correct
16 Correct 73 ms 2408 KB Output is correct
17 Correct 77 ms 2484 KB Output is correct
18 Correct 77 ms 2424 KB Output is correct
19 Correct 270 ms 12556 KB Output is correct
20 Correct 229 ms 15160 KB Output is correct
21 Correct 167 ms 15016 KB Output is correct
22 Correct 181 ms 14904 KB Output is correct
23 Correct 114 ms 5316 KB Output is correct
24 Correct 114 ms 5340 KB Output is correct
25 Correct 197 ms 15292 KB Output is correct
26 Correct 206 ms 15368 KB Output is correct
27 Correct 206 ms 15188 KB Output is correct
28 Correct 205 ms 15204 KB Output is correct
29 Correct 234 ms 15092 KB Output is correct
30 Correct 123 ms 5328 KB Output is correct
31 Correct 193 ms 15276 KB Output is correct
32 Correct 220 ms 15084 KB Output is correct
33 Correct 122 ms 5332 KB Output is correct
34 Correct 219 ms 15172 KB Output is correct
35 Correct 171 ms 14704 KB Output is correct
36 Correct 119 ms 5380 KB Output is correct
37 Correct 124 ms 5316 KB Output is correct
38 Correct 202 ms 15156 KB Output is correct
39 Correct 140 ms 15292 KB Output is correct
40 Correct 175 ms 10476 KB Output is correct
41 Correct 329 ms 15420 KB Output is correct
42 Correct 50 ms 14720 KB Output is correct
43 Correct 86 ms 2404 KB Output is correct
44 Correct 83 ms 2424 KB Output is correct
45 Correct 83 ms 2372 KB Output is correct
46 Correct 73 ms 2492 KB Output is correct
47 Correct 76 ms 2360 KB Output is correct
48 Correct 77 ms 2400 KB Output is correct
49 Correct 75 ms 2404 KB Output is correct
50 Correct 72 ms 2432 KB Output is correct
51 Correct 72 ms 2380 KB Output is correct
52 Correct 72 ms 2368 KB Output is correct
53 Correct 80 ms 2372 KB Output is correct
54 Correct 67 ms 2412 KB Output is correct
55 Correct 88 ms 2472 KB Output is correct
56 Correct 76 ms 2372 KB Output is correct
57 Correct 79 ms 2488 KB Output is correct
58 Correct 78 ms 2380 KB Output is correct
59 Correct 79 ms 2464 KB Output is correct
60 Correct 82 ms 2472 KB Output is correct
61 Correct 82 ms 2372 KB Output is correct
62 Correct 86 ms 2424 KB Output is correct
63 Correct 84 ms 2476 KB Output is correct
64 Correct 93 ms 2452 KB Output is correct
65 Correct 90 ms 2424 KB Output is correct
66 Correct 92 ms 2380 KB Output is correct
67 Correct 84 ms 2448 KB Output is correct
68 Correct 86 ms 2432 KB Output is correct
69 Correct 443 ms 17540 KB Output is correct
70 Correct 460 ms 18408 KB Output is correct
71 Correct 136 ms 5540 KB Output is correct
72 Correct 128 ms 5452 KB Output is correct
73 Correct 138 ms 5368 KB Output is correct
74 Correct 187 ms 15304 KB Output is correct
75 Correct 128 ms 5372 KB Output is correct
76 Correct 216 ms 15888 KB Output is correct
77 Correct 213 ms 15432 KB Output is correct
78 Correct 126 ms 5372 KB Output is correct
79 Correct 128 ms 5460 KB Output is correct
80 Correct 279 ms 16836 KB Output is correct
81 Correct 136 ms 5448 KB Output is correct
82 Correct 362 ms 18508 KB Output is correct
83 Correct 336 ms 18056 KB Output is correct
84 Correct 132 ms 5572 KB Output is correct
85 Correct 139 ms 5460 KB Output is correct
86 Correct 269 ms 17016 KB Output is correct
87 Correct 288 ms 18500 KB Output is correct
88 Correct 145 ms 5544 KB Output is correct
89 Correct 249 ms 17824 KB Output is correct
90 Correct 309 ms 18412 KB Output is correct
91 Correct 134 ms 5544 KB Output is correct
92 Correct 299 ms 16928 KB Output is correct
93 Correct 131 ms 5536 KB Output is correct
94 Correct 126 ms 5472 KB Output is correct
95 Correct 142 ms 5444 KB Output is correct
96 Correct 204 ms 15048 KB Output is correct
97 Correct 207 ms 18572 KB Output is correct
98 Correct 266 ms 12616 KB Output is correct
99 Correct 432 ms 18628 KB Output is correct
100 Correct 201 ms 17864 KB Output is correct