Submission #902557

# Submission time Handle Problem Language Result Execution time Memory
902557 2024-01-10T17:19:00 Z qin Crossing (JOI21_crossing) C++17
3 / 100
233 ms 31492 KB
#include <bits/stdc++.h>
#define fi first
#define se second
#define ssize(x) int(x.size())
#define pn printf("\n")
#define all(x) x.begin(),x.end()
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
int inf = 2e09; ll infll = 2e18;
vector<string> get_strings(string &xx, string &y, string &z){
		string s[3] = {xx, y, z};
		int n = int(s[0].length());
		map<string, int> mp;
		queue<string> q;
		for(int l = 0; l < 3; ++l) mp[s[l]] = 1, q.emplace(s[l]);
		char t[3] = {'J', 'O', 'I'};
		//~ int cnt = 0;
		vector<string> ret;
		while(!q.empty()){
				string x = q.front(); q.pop();
				string tt = ""; tt.resize(n);
				for(int l = 0; l < 3; ++l){
						for(int i = 0; i < n; ++i) if(x[i] == s[l][i]) tt[i] = x[i];
												   else{
														int a, b;
														for(int j = 0; j < 3; ++j) if(t[j] == x[i]) a = j;
														for(int j = 0; j < 3; ++j) if(t[j] == s[l][i]) b = j;
														if(a && b) tt[i] = t[0];
														else if(max(a, b) > 1) tt[i] = t[1];
														else tt[i] = t[2];
												   }
						if(mp[tt] != 1) mp[tt] = 1, q.emplace(tt); //, cout << ":\n" << x << "\n" << s[l] << "\n" << tt << "\n\n";
				}
				//~ cout << x << "\n";
				ret.emplace_back(x);
		}
		return ret;
}
ll mod = 998244353ll;
int base = 1;
struct seg{
		vector<ll> t, p, tmp, powp;
		void build(int i, int s, int e){
				for(int j = s; j <= e; ++j) tmp[i] += powp[j];
				int mid = (s+e)>>1;
				if(s != e) build(i<<1, s, mid), build(i<<1|1, mid+1, e);
		}
		void init(int n){
				while(base < n) base <<= 1;
				t.resize(base<<1, 0), tmp.resize(base<<1, 0), powp.resize(base+1), p.resize(base<<1, 0);
				powp[0] = 1;
				for(int i = 1; i <= base; ++i) powp[i] = powp[i-1]*998244353ll;
				build(1, 1, base);
		}
		void add(int i, ll pr){ t[i] = tmp[i]*pr, p[i] = pr; }
		void push(int i){ if(p[i]) add(i<<1, p[i]), add(i<<1|1, p[i]), p[i] = 0; }
		void update(int i, int s, int e, int x, int y, ll pr){
				if(x <= s && e <= y) return void(add(i, pr));
				int mid = (s+e)>>1; push(i);
				if(x <= mid) update(i<<1, s, mid, x, y, pr);
				if(mid < y) update(i<<1|1, mid+1, e, x, y, pr);
				t[i] = t[i<<1]+t[i<<1|1];
		}
};
void answer(){
		int n, q; scanf("%d", &n);
		string s[3] = {"", "", ""}, t="";
		char c;
		for(int l = 0; l < 3; ++l){
				c = getchar_unlocked();
				for(int i = 0; i < n; ++i) c = getchar_unlocked(), s[l] += c;
		}
		scanf("%d\n", &q);
		for(int i = 0; i < n; ++i) c = getchar_unlocked(), t += c;
		vector<string> st = get_strings(s[0], s[1], s[2]);
		
		vector<ll> powp(n+1); powp[0] = 1;
		for(int i = 1; i <= n; ++i) powp[i] = powp[i-1]*998244353ll;
		
		unordered_map<ll, bool> mp;
		for(string &u : st){
				ll hash = 0;
				for(int i = 0; i < n; ++i) hash += ll(u[i])*powp[i+1];
				mp[hash] = 1;
				//~ printf("%lld\n", hash);
		}
		
		seg seg; seg.init(n+1);
		for(int i = 0; i < n; ++i) seg.t[i+base] = ll(t[i])*powp[i+1];
		for(int i = base-1; i; --i) seg.t[i] = seg.t[i<<1]+seg.t[i<<1|1];
		printf(mp[seg.t[1]] ? "Yes\n" : "No\n");
		//~ printf("%lld\n", seg.t[1]);
		
		for(++q; --q; ){
				int a, b; 
				scanf("%d%d %c", &a, &b, &c);
				seg.update(1, 1, base, a, b, ll(c));
				printf(mp[seg.t[1]] ? "Yes\n" : "No\n");
				//~ printf("%lld\n", seg.t[1]);
		}
}
int main(){
		int T = 1;
		//~ ios_base::sync_with_stdio(0); cin.tie(0);
		for(++T; --T; ) answer();
		return 0;
}

Compilation message

Main.cpp: In function 'void answer()':
Main.cpp:67:18: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   67 |   int n, q; scanf("%d", &n);
      |             ~~~~~^~~~~~~~~~
Main.cpp:74:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   74 |   scanf("%d\n", &q);
      |   ~~~~~^~~~~~~~~~~~
Main.cpp:97:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   97 |     scanf("%d%d %c", &a, &b, &c);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 104 ms 8536 KB Output is correct
2 Correct 89 ms 8808 KB Output is correct
3 Correct 77 ms 4892 KB Output is correct
4 Correct 79 ms 8900 KB Output is correct
5 Correct 86 ms 8904 KB Output is correct
6 Correct 78 ms 8488 KB Output is correct
7 Correct 97 ms 8508 KB Output is correct
8 Correct 95 ms 8980 KB Output is correct
9 Correct 93 ms 8764 KB Output is correct
10 Correct 126 ms 11976 KB Output is correct
11 Correct 86 ms 9156 KB Output is correct
12 Correct 89 ms 11976 KB Output is correct
13 Correct 80 ms 9152 KB Output is correct
14 Correct 89 ms 11908 KB Output is correct
15 Correct 83 ms 9332 KB Output is correct
16 Correct 113 ms 11796 KB Output is correct
17 Correct 87 ms 9240 KB Output is correct
18 Correct 75 ms 3804 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 104 ms 8536 KB Output is correct
2 Correct 89 ms 8808 KB Output is correct
3 Correct 77 ms 4892 KB Output is correct
4 Correct 79 ms 8900 KB Output is correct
5 Correct 86 ms 8904 KB Output is correct
6 Correct 78 ms 8488 KB Output is correct
7 Correct 97 ms 8508 KB Output is correct
8 Correct 95 ms 8980 KB Output is correct
9 Correct 93 ms 8764 KB Output is correct
10 Correct 126 ms 11976 KB Output is correct
11 Correct 86 ms 9156 KB Output is correct
12 Correct 89 ms 11976 KB Output is correct
13 Correct 80 ms 9152 KB Output is correct
14 Correct 89 ms 11908 KB Output is correct
15 Correct 83 ms 9332 KB Output is correct
16 Correct 113 ms 11796 KB Output is correct
17 Correct 87 ms 9240 KB Output is correct
18 Correct 75 ms 3804 KB Output is correct
19 Correct 226 ms 27552 KB Output is correct
20 Correct 186 ms 28548 KB Output is correct
21 Correct 203 ms 31100 KB Output is correct
22 Correct 178 ms 27124 KB Output is correct
23 Correct 139 ms 13800 KB Output is correct
24 Correct 136 ms 13904 KB Output is correct
25 Correct 233 ms 31036 KB Output is correct
26 Correct 192 ms 28556 KB Output is correct
27 Correct 192 ms 31492 KB Output is correct
28 Correct 189 ms 28300 KB Output is correct
29 Correct 219 ms 31144 KB Output is correct
30 Correct 124 ms 13780 KB Output is correct
31 Correct 229 ms 31112 KB Output is correct
32 Correct 197 ms 27732 KB Output is correct
33 Correct 131 ms 13772 KB Output is correct
34 Correct 190 ms 28292 KB Output is correct
35 Correct 200 ms 27204 KB Output is correct
36 Correct 120 ms 13944 KB Output is correct
37 Correct 139 ms 13920 KB Output is correct
38 Correct 208 ms 26892 KB Output is correct
39 Correct 109 ms 26500 KB Output is correct
40 Incorrect 195 ms 27284 KB Output isn't correct
41 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 104 ms 8536 KB Output is correct
2 Correct 89 ms 8808 KB Output is correct
3 Correct 77 ms 4892 KB Output is correct
4 Correct 79 ms 8900 KB Output is correct
5 Correct 86 ms 8904 KB Output is correct
6 Correct 78 ms 8488 KB Output is correct
7 Correct 97 ms 8508 KB Output is correct
8 Correct 95 ms 8980 KB Output is correct
9 Correct 93 ms 8764 KB Output is correct
10 Correct 126 ms 11976 KB Output is correct
11 Correct 86 ms 9156 KB Output is correct
12 Correct 89 ms 11976 KB Output is correct
13 Correct 80 ms 9152 KB Output is correct
14 Correct 89 ms 11908 KB Output is correct
15 Correct 83 ms 9332 KB Output is correct
16 Correct 113 ms 11796 KB Output is correct
17 Correct 87 ms 9240 KB Output is correct
18 Correct 75 ms 3804 KB Output is correct
19 Correct 111 ms 8504 KB Output is correct
20 Correct 81 ms 4836 KB Output is correct
21 Correct 102 ms 12028 KB Output is correct
22 Correct 83 ms 8128 KB Output is correct
23 Correct 107 ms 11856 KB Output is correct
24 Correct 96 ms 8772 KB Output is correct
25 Correct 87 ms 11972 KB Output is correct
26 Correct 78 ms 8388 KB Output is correct
27 Correct 85 ms 11972 KB Output is correct
28 Correct 74 ms 8548 KB Output is correct
29 Correct 98 ms 8984 KB Output is correct
30 Correct 74 ms 8388 KB Output is correct
31 Correct 93 ms 11856 KB Output is correct
32 Correct 112 ms 11956 KB Output is correct
33 Correct 122 ms 9124 KB Output is correct
34 Correct 86 ms 8600 KB Output is correct
35 Correct 104 ms 11984 KB Output is correct
36 Correct 92 ms 9100 KB Output is correct
37 Correct 103 ms 12028 KB Output is correct
38 Correct 84 ms 9116 KB Output is correct
39 Correct 87 ms 11968 KB Output is correct
40 Correct 89 ms 9304 KB Output is correct
41 Correct 105 ms 11856 KB Output is correct
42 Correct 93 ms 9156 KB Output is correct
43 Correct 77 ms 8900 KB Output is correct
44 Incorrect 77 ms 9112 KB Output isn't correct
45 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 104 ms 8536 KB Output is correct
2 Correct 89 ms 8808 KB Output is correct
3 Correct 77 ms 4892 KB Output is correct
4 Correct 79 ms 8900 KB Output is correct
5 Correct 86 ms 8904 KB Output is correct
6 Correct 78 ms 8488 KB Output is correct
7 Correct 97 ms 8508 KB Output is correct
8 Correct 95 ms 8980 KB Output is correct
9 Correct 93 ms 8764 KB Output is correct
10 Correct 126 ms 11976 KB Output is correct
11 Correct 86 ms 9156 KB Output is correct
12 Correct 89 ms 11976 KB Output is correct
13 Correct 80 ms 9152 KB Output is correct
14 Correct 89 ms 11908 KB Output is correct
15 Correct 83 ms 9332 KB Output is correct
16 Correct 113 ms 11796 KB Output is correct
17 Correct 87 ms 9240 KB Output is correct
18 Correct 75 ms 3804 KB Output is correct
19 Correct 226 ms 27552 KB Output is correct
20 Correct 186 ms 28548 KB Output is correct
21 Correct 203 ms 31100 KB Output is correct
22 Correct 178 ms 27124 KB Output is correct
23 Correct 139 ms 13800 KB Output is correct
24 Correct 136 ms 13904 KB Output is correct
25 Correct 233 ms 31036 KB Output is correct
26 Correct 192 ms 28556 KB Output is correct
27 Correct 192 ms 31492 KB Output is correct
28 Correct 189 ms 28300 KB Output is correct
29 Correct 219 ms 31144 KB Output is correct
30 Correct 124 ms 13780 KB Output is correct
31 Correct 229 ms 31112 KB Output is correct
32 Correct 197 ms 27732 KB Output is correct
33 Correct 131 ms 13772 KB Output is correct
34 Correct 190 ms 28292 KB Output is correct
35 Correct 200 ms 27204 KB Output is correct
36 Correct 120 ms 13944 KB Output is correct
37 Correct 139 ms 13920 KB Output is correct
38 Correct 208 ms 26892 KB Output is correct
39 Correct 109 ms 26500 KB Output is correct
40 Incorrect 195 ms 27284 KB Output isn't correct
41 Halted 0 ms 0 KB -