Submission #594604

# Submission time Handle Problem Language Result Execution time Memory
594604 2022-07-12T17:44:50 Z SOCIOPATE Crossing (JOI21_crossing) C++17
100 / 100
4323 ms 51192 KB
#include <bits/stdc++.h>
#include <iostream>
#include <cstdlib>
#include <iomanip>
#include <vector>
#include <cmath>
#include <assert.h>
#include <ctime>
#include <math.h>
#include <queue>
#include <string>
#include <numeric>
#include <fstream>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <map>
#include <stack>
#include <random>
#include <list>
#include <bitset>
#include <algorithm>

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

#define pll pair<ll, ll>
#define pii pair<int, int>
#define pdd pair<ld, ld>
#define ff first
#define ss second
#define all(v) v.begin(),v.end()

typedef tree<
    pii,
    null_type,
    less<pii>,
    rb_tree_tag,
    tree_order_statistics_node_update> ordset;


#pragma GCC optimize("-O3")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("-Os")

ll INF = 2e18;

//mt19937 gen(time(0));

ll gcd(ll n, ll m){
    while(n != 0 && m != 0){
        if(n > m) n %= m;
        else m %= n;
    }
    return n + m;
}

ll lcm(ll n, ll m){
    ll nod = gcd(n, m);
    return n / nod * m;
}

ll mod = 1e9 + 7;

ll binpow(ll n, ll m){
    if(m == 0) return 1;
    if(m % 2ll == 1) {
        return (binpow(n, m - 1ll) * 1ll * n) % mod;
    }
    ll b = binpow(n, m / 2);
    return (b * 1ll * b) % mod;

}

int n;

vector<vector<int>> ch;
vector<int> t;
vector<char> t_add;

string cur;

struct str{
    int l, r;
    string s;
};

inline bool check(int l, int r, char x){
    return ch[r][x - 'A'] - (l ? ch[l - 1][x - 'A'] : 0) == r - l + 1;
}

void push(int v, int l, int r){
    if(t_add[v] == '.') return;
    int m = (l + r) / 2;
    t[2*v] = check(l, m - 1, t_add[v]);
    t[2*v + 1] = check(m, r - 1, t_add[v]);
    t_add[2*v] = t_add[2*v+1] = t_add[v];
    t_add[v] = '.';
}

void build(int v, int l, int r){
    if(l == r - 1){
        t[v] = check(l, l, cur[l]);
        return;
    }
    int m = (l + r) / 2;
    build(2*v,l,m);
    build(2*v+1,m,r);
    t[v] = t[2*v] & t[2*v + 1];
}

void upd(int v, int l, int r, int askl, int askr, char c){
    if(l >= askl && r <= askr){
        t_add[v] = c;
        t[v] = check(l, r - 1, c);
        return;
    }
    if(l >= askr || r <= askl) return;
    push(v,l,r);
    int m = (l + r) / 2;
    upd(2*v,l,m,askl,askr,c);
    upd(2*v+1,m,r,askl,askr,c);
    t[v] = t[2*v] & t[2*v+1];
}

void solve(){
    cin >> n;
    ch.resize(n, vector<int>(27, 0));
    vector<string> a(3);
    unordered_map<string, int> st;
    for(int i = 0; i < 3; i++){
        cin >> a[i];
        st[a[i]] = 1;
    }
    while(true){
        int u = (int)st.size();
        int n1 = (int)a.size();
        for(int i = 0; i < n1; i++){
            for(int j = 0; j < n1; j++){
                string s = "";
                for(int k = 0; k < n; k++){
                    if(a[i][k] == a[j][k]) s += a[i][k];
                    else if (a[i][k] != 'J' && a[j][k] != 'J') s += "J";
                    else if (a[i][k] != 'O' && a[j][k] != 'O') s += "O";
                    else if (a[i][k] != 'I' && a[j][k] != 'I') s += "I";
                }
                if(st.find(s) != st.end()) continue;
                else{
                    a.push_back(s);
                    st[s] = 1;
                }
            }
        }
        if(u == (int)st.size()) break;
    }
    int q;
    cin >> q;
    string s;
    cin >> s;
    vector<str> qq(q);
    for(int i = 0; i < q; i++) cin >> qq[i].l >> qq[i].r >> qq[i].s;
    vector<int> res(q + 1, 0);
    t.resize(4*n);
    t_add.resize(4*n);
    for(auto& u : st){
        ch.assign(n, vector<int>(27, 0));
        for(int i = 0; i < n; i++){
            if(!i){
                ch[i][u.ff[i] - 'A'] = 1;
                continue;
            }
            ch[i] = ch[i - 1];
            ch[i][u.ff[i] - 'A']++;
        }
        t_add.assign(4*n, '.');
        cur = s;
        build(1, 0, n);
        //cout << u.ff << " " << cur << " " << t[1] << '\n';
        res[0] |= t[1];
        for(int i = 0; i < q; i++){
            upd(1, 0, n, qq[i].l - 1, qq[i].r, qq[i].s[0]);
            res[i + 1] |= t[1];
        }
    }
    for(int u : res) cout << (u ? "Yes\n" : "No\n");
}

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
	int tt;
    //cin >> tt;
	tt = 1;
	while (tt--) {
		solve();
	}
	return 0;
}

# Verdict Execution time Memory Grader output
1 Correct 74 ms 8780 KB Output is correct
2 Correct 109 ms 9464 KB Output is correct
3 Correct 84 ms 9464 KB Output is correct
4 Correct 69 ms 9164 KB Output is correct
5 Correct 68 ms 9172 KB Output is correct
6 Correct 68 ms 9020 KB Output is correct
7 Correct 108 ms 9344 KB Output is correct
8 Correct 91 ms 9552 KB Output is correct
9 Correct 83 ms 9548 KB Output is correct
10 Correct 79 ms 9524 KB Output is correct
11 Correct 90 ms 9516 KB Output is correct
12 Correct 83 ms 9548 KB Output is correct
13 Correct 90 ms 9436 KB Output is correct
14 Correct 85 ms 9576 KB Output is correct
15 Correct 82 ms 9460 KB Output is correct
16 Correct 88 ms 9476 KB Output is correct
17 Correct 123 ms 9456 KB Output is correct
18 Correct 79 ms 9548 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 74 ms 8780 KB Output is correct
2 Correct 109 ms 9464 KB Output is correct
3 Correct 84 ms 9464 KB Output is correct
4 Correct 69 ms 9164 KB Output is correct
5 Correct 68 ms 9172 KB Output is correct
6 Correct 68 ms 9020 KB Output is correct
7 Correct 108 ms 9344 KB Output is correct
8 Correct 91 ms 9552 KB Output is correct
9 Correct 83 ms 9548 KB Output is correct
10 Correct 79 ms 9524 KB Output is correct
11 Correct 90 ms 9516 KB Output is correct
12 Correct 83 ms 9548 KB Output is correct
13 Correct 90 ms 9436 KB Output is correct
14 Correct 85 ms 9576 KB Output is correct
15 Correct 82 ms 9460 KB Output is correct
16 Correct 88 ms 9476 KB Output is correct
17 Correct 123 ms 9456 KB Output is correct
18 Correct 79 ms 9548 KB Output is correct
19 Correct 543 ms 46232 KB Output is correct
20 Correct 335 ms 47924 KB Output is correct
21 Correct 249 ms 45388 KB Output is correct
22 Correct 265 ms 41776 KB Output is correct
23 Correct 122 ms 13628 KB Output is correct
24 Correct 134 ms 13564 KB Output is correct
25 Correct 257 ms 48012 KB Output is correct
26 Correct 292 ms 48016 KB Output is correct
27 Correct 360 ms 47996 KB Output is correct
28 Correct 337 ms 48004 KB Output is correct
29 Correct 299 ms 46836 KB Output is correct
30 Correct 148 ms 13620 KB Output is correct
31 Correct 273 ms 48016 KB Output is correct
32 Correct 382 ms 44596 KB Output is correct
33 Correct 125 ms 13544 KB Output is correct
34 Correct 338 ms 47996 KB Output is correct
35 Correct 267 ms 38124 KB Output is correct
36 Correct 135 ms 13672 KB Output is correct
37 Correct 122 ms 13648 KB Output is correct
38 Correct 323 ms 47912 KB Output is correct
39 Correct 173 ms 48060 KB Output is correct
40 Correct 245 ms 35732 KB Output is correct
41 Correct 501 ms 48292 KB Output is correct
42 Correct 91 ms 47524 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 74 ms 8780 KB Output is correct
2 Correct 109 ms 9464 KB Output is correct
3 Correct 84 ms 9464 KB Output is correct
4 Correct 69 ms 9164 KB Output is correct
5 Correct 68 ms 9172 KB Output is correct
6 Correct 68 ms 9020 KB Output is correct
7 Correct 108 ms 9344 KB Output is correct
8 Correct 91 ms 9552 KB Output is correct
9 Correct 83 ms 9548 KB Output is correct
10 Correct 79 ms 9524 KB Output is correct
11 Correct 90 ms 9516 KB Output is correct
12 Correct 83 ms 9548 KB Output is correct
13 Correct 90 ms 9436 KB Output is correct
14 Correct 85 ms 9576 KB Output is correct
15 Correct 82 ms 9460 KB Output is correct
16 Correct 88 ms 9476 KB Output is correct
17 Correct 123 ms 9456 KB Output is correct
18 Correct 79 ms 9548 KB Output is correct
19 Correct 445 ms 9068 KB Output is correct
20 Correct 435 ms 9460 KB Output is correct
21 Correct 140 ms 9456 KB Output is correct
22 Correct 124 ms 8668 KB Output is correct
23 Correct 142 ms 9448 KB Output is correct
24 Correct 133 ms 9200 KB Output is correct
25 Correct 147 ms 9472 KB Output is correct
26 Correct 131 ms 9176 KB Output is correct
27 Correct 141 ms 9456 KB Output is correct
28 Correct 125 ms 8660 KB Output is correct
29 Correct 148 ms 9456 KB Output is correct
30 Correct 123 ms 8848 KB Output is correct
31 Correct 342 ms 9460 KB Output is correct
32 Correct 335 ms 9440 KB Output is correct
33 Correct 358 ms 9464 KB Output is correct
34 Correct 306 ms 9036 KB Output is correct
35 Correct 338 ms 9460 KB Output is correct
36 Correct 361 ms 9464 KB Output is correct
37 Correct 357 ms 9460 KB Output is correct
38 Correct 375 ms 9456 KB Output is correct
39 Correct 351 ms 9460 KB Output is correct
40 Correct 358 ms 9460 KB Output is correct
41 Correct 361 ms 9464 KB Output is correct
42 Correct 346 ms 9568 KB Output is correct
43 Correct 343 ms 9344 KB Output is correct
44 Correct 347 ms 9456 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 74 ms 8780 KB Output is correct
2 Correct 109 ms 9464 KB Output is correct
3 Correct 84 ms 9464 KB Output is correct
4 Correct 69 ms 9164 KB Output is correct
5 Correct 68 ms 9172 KB Output is correct
6 Correct 68 ms 9020 KB Output is correct
7 Correct 108 ms 9344 KB Output is correct
8 Correct 91 ms 9552 KB Output is correct
9 Correct 83 ms 9548 KB Output is correct
10 Correct 79 ms 9524 KB Output is correct
11 Correct 90 ms 9516 KB Output is correct
12 Correct 83 ms 9548 KB Output is correct
13 Correct 90 ms 9436 KB Output is correct
14 Correct 85 ms 9576 KB Output is correct
15 Correct 82 ms 9460 KB Output is correct
16 Correct 88 ms 9476 KB Output is correct
17 Correct 123 ms 9456 KB Output is correct
18 Correct 79 ms 9548 KB Output is correct
19 Correct 543 ms 46232 KB Output is correct
20 Correct 335 ms 47924 KB Output is correct
21 Correct 249 ms 45388 KB Output is correct
22 Correct 265 ms 41776 KB Output is correct
23 Correct 122 ms 13628 KB Output is correct
24 Correct 134 ms 13564 KB Output is correct
25 Correct 257 ms 48012 KB Output is correct
26 Correct 292 ms 48016 KB Output is correct
27 Correct 360 ms 47996 KB Output is correct
28 Correct 337 ms 48004 KB Output is correct
29 Correct 299 ms 46836 KB Output is correct
30 Correct 148 ms 13620 KB Output is correct
31 Correct 273 ms 48016 KB Output is correct
32 Correct 382 ms 44596 KB Output is correct
33 Correct 125 ms 13544 KB Output is correct
34 Correct 338 ms 47996 KB Output is correct
35 Correct 267 ms 38124 KB Output is correct
36 Correct 135 ms 13672 KB Output is correct
37 Correct 122 ms 13648 KB Output is correct
38 Correct 323 ms 47912 KB Output is correct
39 Correct 173 ms 48060 KB Output is correct
40 Correct 245 ms 35732 KB Output is correct
41 Correct 501 ms 48292 KB Output is correct
42 Correct 91 ms 47524 KB Output is correct
43 Correct 445 ms 9068 KB Output is correct
44 Correct 435 ms 9460 KB Output is correct
45 Correct 140 ms 9456 KB Output is correct
46 Correct 124 ms 8668 KB Output is correct
47 Correct 142 ms 9448 KB Output is correct
48 Correct 133 ms 9200 KB Output is correct
49 Correct 147 ms 9472 KB Output is correct
50 Correct 131 ms 9176 KB Output is correct
51 Correct 141 ms 9456 KB Output is correct
52 Correct 125 ms 8660 KB Output is correct
53 Correct 148 ms 9456 KB Output is correct
54 Correct 123 ms 8848 KB Output is correct
55 Correct 342 ms 9460 KB Output is correct
56 Correct 335 ms 9440 KB Output is correct
57 Correct 358 ms 9464 KB Output is correct
58 Correct 306 ms 9036 KB Output is correct
59 Correct 338 ms 9460 KB Output is correct
60 Correct 361 ms 9464 KB Output is correct
61 Correct 357 ms 9460 KB Output is correct
62 Correct 375 ms 9456 KB Output is correct
63 Correct 351 ms 9460 KB Output is correct
64 Correct 358 ms 9460 KB Output is correct
65 Correct 361 ms 9464 KB Output is correct
66 Correct 346 ms 9568 KB Output is correct
67 Correct 343 ms 9344 KB Output is correct
68 Correct 347 ms 9456 KB Output is correct
69 Correct 3291 ms 43668 KB Output is correct
70 Correct 2647 ms 50844 KB Output is correct
71 Correct 258 ms 13616 KB Output is correct
72 Correct 267 ms 13672 KB Output is correct
73 Correct 261 ms 13784 KB Output is correct
74 Correct 563 ms 41552 KB Output is correct
75 Correct 268 ms 13568 KB Output is correct
76 Correct 600 ms 48492 KB Output is correct
77 Correct 668 ms 41952 KB Output is correct
78 Correct 260 ms 13596 KB Output is correct
79 Correct 257 ms 13744 KB Output is correct
80 Correct 1847 ms 38852 KB Output is correct
81 Correct 711 ms 13772 KB Output is correct
82 Correct 2230 ms 50932 KB Output is correct
83 Correct 2435 ms 48268 KB Output is correct
84 Correct 878 ms 13704 KB Output is correct
85 Correct 794 ms 13676 KB Output is correct
86 Correct 2190 ms 40792 KB Output is correct
87 Correct 2597 ms 50992 KB Output is correct
88 Correct 787 ms 13840 KB Output is correct
89 Correct 2167 ms 45632 KB Output is correct
90 Correct 2390 ms 50940 KB Output is correct
91 Correct 838 ms 13708 KB Output is correct
92 Correct 1758 ms 40532 KB Output is correct
93 Correct 746 ms 13712 KB Output is correct
94 Correct 766 ms 13680 KB Output is correct
95 Correct 717 ms 13772 KB Output is correct
96 Correct 281 ms 47884 KB Output is correct
97 Correct 1016 ms 50988 KB Output is correct
98 Correct 1960 ms 37656 KB Output is correct
99 Correct 4323 ms 51192 KB Output is correct
100 Correct 657 ms 50532 KB Output is correct