답안 #608845

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
608845 2022-07-27T10:48:20 Z DeMen100ns Crossing (JOI21_crossing) C++17
100 / 100
873 ms 20560 KB
/*
Author : DeMen100ns (a.k.a Vo Khac Trieu)
School : VNU-HCM High school for the Gifted
fuck you adhoc
*/

#include <bits/stdc++.h>

using namespace std;

const int N = 2e5 + 5;
const long long INF = numeric_limits<long long>::max() / 2;
const int MAXA = 1e9;
const int B = sqrt(N) + 5;

string cross(string a, string b){
    if (a.empty()) return b;

    string ans = "";
    for(int i = 0; i < a.size(); ++i){
        if (a[i] == b[i]) ans += a[i];
        else {
            int sum = (int)a[i] + b[i];
            if (sum == (int)'J' + 'O') ans += 'I';
            if (sum == (int)'I' + 'O') ans += 'J';
            if (sum == (int)'J' + 'I') ans += 'O';
        }
    }
    return ans;
}

vector <string> res;
bool f[20][4 * N];
bool d[4 * N];
char g[20][4 * N], sc[4 * N], lazy[4 * N];

void build(int id, int l, int r, string &s){
    for(int id2 = 0; id2 < res.size(); ++id2){
        f[id2][id] = true;
        for(int i = l; i <= r; ++i){
            f[id2][id] &= (s[i] == res[id2][i]);
        }
        bool ch = true;
        for(int i = l; i <= r; ++i){
            ch &= (res[id2][i] == res[id2][l]);
        }
        if (ch) g[id2][id] = res[id2][l];
        else g[id2][id] = 'z';
    }
    sc[id] = s[l];

    if (l == r) return;

    int mid = (l + r) >> 1;
    build(id << 1, l, mid, s);
    build(id << 1 | 1, mid + 1, r, s);
}

void down(int id){
    char ch = lazy[id];

    sc[id << 1] = sc[id << 1 | 1] = lazy[id << 1] = lazy[id << 1 | 1] = ch;
    d[id << 1] = d[id << 1 | 1] = true;
    for(int id2 = 0; id2 < res.size(); ++id2){
        f[id2][id << 1] = (g[id2][id << 1] == ch);
        f[id2][id << 1 | 1] = (g[id2][id << 1 | 1] == ch);
    }

    d[id] = false;
}

void upd(int id, int l, int r, int u, int v, char c){
    if (l > v || r < u) return;
    if (l >= u && r <= v){
        for(int id2 = 0; id2 < res.size(); ++id2){
            f[id2][id] = (g[id2][id] == c);
        }
        sc[id] = lazy[id] = c;
        d[id] = true;
        return;
    }
    if (d[id]) down(id);

    int mid = (l + r) >> 1;
    upd(id << 1, l, mid, u, v, c);
    upd(id << 1 | 1, mid + 1, r, u, v, c);

    for(int id2 = 0; id2 < res.size(); ++id2){
        f[id2][id] = (f[id2][id << 1] & f[id2][id << 1 | 1]);
    }
}

bool check(){
    bool g = false;
    for(int id2 = 0; id2 < res.size(); ++id2){
        g |= f[id2][1];
    }
    return g;
}

void solve()
{
    vector <string> v;

    int n; cin >> n;
    string S[3];
    for(int i = 0; i < 3; ++i) {
        cin >> S[i];
        v.push_back(S[i]);
    }

    //3 + 3 + 3 = 12

    sort(v.begin(), v.end());
    do{
        string ans = "";
        for(string s : v){
            ans = cross(ans, s);
            res.push_back(ans);
        }
    } while(next_permutation(v.begin(), v.end()));

    sort(res.begin(), res.end());
    res.resize(unique(res.begin(), res.end()) - res.begin());

    int q; cin >> q;
    string s; cin >> s;
    build(1, 0, n - 1, s);

    if (check()) cout << "Yes" << endl;
    else cout << "No" << endl;

    while (q--){
        int l, r; char c; cin >> l >> r >> c;
        --l; --r;

        upd(1, 0, n - 1, l, r, c);
        
        if (check()) cout << "Yes" << endl;
        else cout << "No" << endl;
    }
    //i i j = i j = o
    //i j i = o i = j...
}

signed main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    // freopen("codeforces.inp","r",stdin);
    // freopen("codeforces.out","w",stdout);

    int t = 1; //cin >> t;
    while (t--)
    {
        solve();
    }
}

Compilation message

Main.cpp: In function 'std::string cross(std::string, std::string)':
Main.cpp:20:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   20 |     for(int i = 0; i < a.size(); ++i){
      |                    ~~^~~~~~~~~~
Main.cpp: In function 'void build(int, int, int, std::string&)':
Main.cpp:38:26: 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]
   38 |     for(int id2 = 0; id2 < res.size(); ++id2){
      |                      ~~~~^~~~~~~~~~~~
Main.cpp: In function 'void down(int)':
Main.cpp:64:26: 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]
   64 |     for(int id2 = 0; id2 < res.size(); ++id2){
      |                      ~~~~^~~~~~~~~~~~
Main.cpp: In function 'void upd(int, int, int, int, int, char)':
Main.cpp:75:30: 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]
   75 |         for(int id2 = 0; id2 < res.size(); ++id2){
      |                          ~~~~^~~~~~~~~~~~
Main.cpp:88:26: 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]
   88 |     for(int id2 = 0; id2 < res.size(); ++id2){
      |                      ~~~~^~~~~~~~~~~~
Main.cpp: In function 'bool check()':
Main.cpp:95:26: 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]
   95 |     for(int id2 = 0; id2 < res.size(); ++id2){
      |                      ~~~~^~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 255 ms 2396 KB Output is correct
2 Correct 287 ms 2404 KB Output is correct
3 Correct 283 ms 2344 KB Output is correct
4 Correct 305 ms 2460 KB Output is correct
5 Correct 278 ms 2300 KB Output is correct
6 Correct 280 ms 2308 KB Output is correct
7 Correct 273 ms 2428 KB Output is correct
8 Correct 272 ms 2560 KB Output is correct
9 Correct 307 ms 2648 KB Output is correct
10 Correct 277 ms 2460 KB Output is correct
11 Correct 285 ms 2424 KB Output is correct
12 Correct 274 ms 2372 KB Output is correct
13 Correct 283 ms 2380 KB Output is correct
14 Correct 290 ms 2396 KB Output is correct
15 Correct 283 ms 2448 KB Output is correct
16 Correct 292 ms 2564 KB Output is correct
17 Correct 282 ms 2436 KB Output is correct
18 Correct 285 ms 2432 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 255 ms 2396 KB Output is correct
2 Correct 287 ms 2404 KB Output is correct
3 Correct 283 ms 2344 KB Output is correct
4 Correct 305 ms 2460 KB Output is correct
5 Correct 278 ms 2300 KB Output is correct
6 Correct 280 ms 2308 KB Output is correct
7 Correct 273 ms 2428 KB Output is correct
8 Correct 272 ms 2560 KB Output is correct
9 Correct 307 ms 2648 KB Output is correct
10 Correct 277 ms 2460 KB Output is correct
11 Correct 285 ms 2424 KB Output is correct
12 Correct 274 ms 2372 KB Output is correct
13 Correct 283 ms 2380 KB Output is correct
14 Correct 290 ms 2396 KB Output is correct
15 Correct 283 ms 2448 KB Output is correct
16 Correct 292 ms 2564 KB Output is correct
17 Correct 282 ms 2436 KB Output is correct
18 Correct 285 ms 2432 KB Output is correct
19 Correct 393 ms 9536 KB Output is correct
20 Correct 391 ms 8856 KB Output is correct
21 Correct 354 ms 9212 KB Output is correct
22 Correct 313 ms 8744 KB Output is correct
23 Correct 314 ms 3564 KB Output is correct
24 Correct 327 ms 3504 KB Output is correct
25 Correct 332 ms 9584 KB Output is correct
26 Correct 359 ms 9612 KB Output is correct
27 Correct 363 ms 9508 KB Output is correct
28 Correct 365 ms 9576 KB Output is correct
29 Correct 344 ms 9320 KB Output is correct
30 Correct 304 ms 3496 KB Output is correct
31 Correct 379 ms 9576 KB Output is correct
32 Correct 336 ms 9036 KB Output is correct
33 Correct 342 ms 3552 KB Output is correct
34 Correct 353 ms 9536 KB Output is correct
35 Correct 327 ms 8420 KB Output is correct
36 Correct 297 ms 3488 KB Output is correct
37 Correct 306 ms 3572 KB Output is correct
38 Correct 382 ms 8580 KB Output is correct
39 Correct 346 ms 8644 KB Output is correct
40 Correct 328 ms 7068 KB Output is correct
41 Correct 400 ms 9788 KB Output is correct
42 Correct 286 ms 7984 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 255 ms 2396 KB Output is correct
2 Correct 287 ms 2404 KB Output is correct
3 Correct 283 ms 2344 KB Output is correct
4 Correct 305 ms 2460 KB Output is correct
5 Correct 278 ms 2300 KB Output is correct
6 Correct 280 ms 2308 KB Output is correct
7 Correct 273 ms 2428 KB Output is correct
8 Correct 272 ms 2560 KB Output is correct
9 Correct 307 ms 2648 KB Output is correct
10 Correct 277 ms 2460 KB Output is correct
11 Correct 285 ms 2424 KB Output is correct
12 Correct 274 ms 2372 KB Output is correct
13 Correct 283 ms 2380 KB Output is correct
14 Correct 290 ms 2396 KB Output is correct
15 Correct 283 ms 2448 KB Output is correct
16 Correct 292 ms 2564 KB Output is correct
17 Correct 282 ms 2436 KB Output is correct
18 Correct 285 ms 2432 KB Output is correct
19 Correct 299 ms 2412 KB Output is correct
20 Correct 310 ms 2556 KB Output is correct
21 Correct 302 ms 2388 KB Output is correct
22 Correct 261 ms 2188 KB Output is correct
23 Correct 277 ms 2408 KB Output is correct
24 Correct 273 ms 2328 KB Output is correct
25 Correct 287 ms 2676 KB Output is correct
26 Correct 267 ms 2380 KB Output is correct
27 Correct 287 ms 2612 KB Output is correct
28 Correct 262 ms 2192 KB Output is correct
29 Correct 287 ms 2452 KB Output is correct
30 Correct 279 ms 2252 KB Output is correct
31 Correct 300 ms 2500 KB Output is correct
32 Correct 293 ms 2728 KB Output is correct
33 Correct 343 ms 2528 KB Output is correct
34 Correct 278 ms 2380 KB Output is correct
35 Correct 330 ms 2552 KB Output is correct
36 Correct 303 ms 2548 KB Output is correct
37 Correct 339 ms 2464 KB Output is correct
38 Correct 296 ms 2544 KB Output is correct
39 Correct 311 ms 2512 KB Output is correct
40 Correct 325 ms 2464 KB Output is correct
41 Correct 349 ms 2464 KB Output is correct
42 Correct 341 ms 2512 KB Output is correct
43 Correct 302 ms 2556 KB Output is correct
44 Correct 305 ms 2512 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 255 ms 2396 KB Output is correct
2 Correct 287 ms 2404 KB Output is correct
3 Correct 283 ms 2344 KB Output is correct
4 Correct 305 ms 2460 KB Output is correct
5 Correct 278 ms 2300 KB Output is correct
6 Correct 280 ms 2308 KB Output is correct
7 Correct 273 ms 2428 KB Output is correct
8 Correct 272 ms 2560 KB Output is correct
9 Correct 307 ms 2648 KB Output is correct
10 Correct 277 ms 2460 KB Output is correct
11 Correct 285 ms 2424 KB Output is correct
12 Correct 274 ms 2372 KB Output is correct
13 Correct 283 ms 2380 KB Output is correct
14 Correct 290 ms 2396 KB Output is correct
15 Correct 283 ms 2448 KB Output is correct
16 Correct 292 ms 2564 KB Output is correct
17 Correct 282 ms 2436 KB Output is correct
18 Correct 285 ms 2432 KB Output is correct
19 Correct 393 ms 9536 KB Output is correct
20 Correct 391 ms 8856 KB Output is correct
21 Correct 354 ms 9212 KB Output is correct
22 Correct 313 ms 8744 KB Output is correct
23 Correct 314 ms 3564 KB Output is correct
24 Correct 327 ms 3504 KB Output is correct
25 Correct 332 ms 9584 KB Output is correct
26 Correct 359 ms 9612 KB Output is correct
27 Correct 363 ms 9508 KB Output is correct
28 Correct 365 ms 9576 KB Output is correct
29 Correct 344 ms 9320 KB Output is correct
30 Correct 304 ms 3496 KB Output is correct
31 Correct 379 ms 9576 KB Output is correct
32 Correct 336 ms 9036 KB Output is correct
33 Correct 342 ms 3552 KB Output is correct
34 Correct 353 ms 9536 KB Output is correct
35 Correct 327 ms 8420 KB Output is correct
36 Correct 297 ms 3488 KB Output is correct
37 Correct 306 ms 3572 KB Output is correct
38 Correct 382 ms 8580 KB Output is correct
39 Correct 346 ms 8644 KB Output is correct
40 Correct 328 ms 7068 KB Output is correct
41 Correct 400 ms 9788 KB Output is correct
42 Correct 286 ms 7984 KB Output is correct
43 Correct 299 ms 2412 KB Output is correct
44 Correct 310 ms 2556 KB Output is correct
45 Correct 302 ms 2388 KB Output is correct
46 Correct 261 ms 2188 KB Output is correct
47 Correct 277 ms 2408 KB Output is correct
48 Correct 273 ms 2328 KB Output is correct
49 Correct 287 ms 2676 KB Output is correct
50 Correct 267 ms 2380 KB Output is correct
51 Correct 287 ms 2612 KB Output is correct
52 Correct 262 ms 2192 KB Output is correct
53 Correct 287 ms 2452 KB Output is correct
54 Correct 279 ms 2252 KB Output is correct
55 Correct 300 ms 2500 KB Output is correct
56 Correct 293 ms 2728 KB Output is correct
57 Correct 343 ms 2528 KB Output is correct
58 Correct 278 ms 2380 KB Output is correct
59 Correct 330 ms 2552 KB Output is correct
60 Correct 303 ms 2548 KB Output is correct
61 Correct 339 ms 2464 KB Output is correct
62 Correct 296 ms 2544 KB Output is correct
63 Correct 311 ms 2512 KB Output is correct
64 Correct 325 ms 2464 KB Output is correct
65 Correct 349 ms 2464 KB Output is correct
66 Correct 341 ms 2512 KB Output is correct
67 Correct 302 ms 2556 KB Output is correct
68 Correct 305 ms 2512 KB Output is correct
69 Correct 578 ms 18896 KB Output is correct
70 Correct 687 ms 19652 KB Output is correct
71 Correct 353 ms 3788 KB Output is correct
72 Correct 309 ms 3720 KB Output is correct
73 Correct 319 ms 3720 KB Output is correct
74 Correct 352 ms 13184 KB Output is correct
75 Correct 334 ms 3784 KB Output is correct
76 Correct 387 ms 14236 KB Output is correct
77 Correct 396 ms 13280 KB Output is correct
78 Correct 320 ms 3884 KB Output is correct
79 Correct 318 ms 3812 KB Output is correct
80 Correct 525 ms 18668 KB Output is correct
81 Correct 372 ms 4368 KB Output is correct
82 Correct 528 ms 20560 KB Output is correct
83 Correct 605 ms 20172 KB Output is correct
84 Correct 360 ms 4376 KB Output is correct
85 Correct 382 ms 4372 KB Output is correct
86 Correct 511 ms 18360 KB Output is correct
87 Correct 602 ms 19984 KB Output is correct
88 Correct 363 ms 4316 KB Output is correct
89 Correct 534 ms 19508 KB Output is correct
90 Correct 569 ms 20444 KB Output is correct
91 Correct 369 ms 4300 KB Output is correct
92 Correct 450 ms 18372 KB Output is correct
93 Correct 378 ms 4360 KB Output is correct
94 Correct 368 ms 4300 KB Output is correct
95 Correct 349 ms 4364 KB Output is correct
96 Correct 397 ms 8536 KB Output is correct
97 Correct 423 ms 19620 KB Output is correct
98 Correct 568 ms 13020 KB Output is correct
99 Correct 873 ms 20348 KB Output is correct
100 Correct 374 ms 18496 KB Output is correct