답안 #479620

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
479620 2021-10-12T11:06:20 Z nicolaalexandra Crossing (JOI21_crossing) C++14
100 / 100
1212 ms 38132 KB
#include <bits/stdc++.h>
#define DIM 200010
#define MOD1 1000000007
#define MOD2 1000000009
using namespace std;

struct segment_tree{
    long long hash1,hash2;
    int lazy;
} aint[DIM*4];

string a,b,c,v,aux;
deque <string> d,w;
map <pair<long long,long long>, int> f;
int poz[DIM];
long long p1[DIM],p2[DIM],sp1[DIM],sp2[DIM];
int n,i,j,x,y,q;
char ch;

int convert (char ch){
    if (ch == 'J')
        return 1;
    if (ch == 'O')
        return 2;
    return 3;
}

pair <long long,long long> get_hash (string s){

    long long hash1 = 0, hash2 = 0;
    for (int i=0;i<n;i++){

        int val = convert(s[i]);

        hash1 = (hash1 * 4 % MOD1 + val) % MOD1;
        hash2 = (hash2 * 4 % MOD2 + val) % MOD2;
    }

    return make_pair (hash1,hash2);
}

void crossing (string a, string b){
    for (int i=0;i<n;i++){
        if (a[i] == b[i])
            aux[i] = a[i];
        else {
            if (a[i] != 'J' && b[i] != 'J')
                aux[i] = 'J';
            else {
                if (a[i] != 'O' && b[i] != 'O')
                    aux[i] = 'O';
                else aux[i] = 'I';
            }}}}

void update_nod (int nod, int st, int dr){
    int fiu_st = nod<<1, fiu_dr = (nod<<1)|1;
    int mid = (st+dr)>>1;

    aint[nod].hash1 = (aint[fiu_st].hash1 * p1[dr-mid] + aint[fiu_dr].hash1) % MOD1;
    aint[nod].hash2 = (aint[fiu_st].hash2 * p2[dr-mid] + aint[fiu_dr].hash2) % MOD2;

}

void update_lazy (int nod, int st, int dr){
    if (!aint[nod].lazy)
        return;

    if (st != dr){
        int mid = (st+dr)>>1;
        int fiu_st = nod<<1, fiu_dr = (nod<<1)|1;

        aint[fiu_st].hash1 = 1LL * aint[nod].lazy * sp1[mid-st] % MOD1;
        aint[fiu_st].hash2 = 1LL * aint[nod].lazy * sp2[mid-st] % MOD2;
        aint[fiu_st].lazy = aint[nod].lazy;

        aint[fiu_dr].hash1 = 1LL * aint[nod].lazy * sp1[dr-mid-1] % MOD1;
        aint[fiu_dr].hash2 = 1LL * aint[nod].lazy * sp2[dr-mid-1] % MOD2;
        aint[fiu_dr].lazy = aint[nod].lazy;

    }

    aint[nod].lazy = 0;
}

void build (int nod, int st, int dr){
    if (st == dr){
        aint[nod].hash1 = aint[nod].hash2 = convert (v[st-1]);
        return;
    }
    int mid = (st+dr)>>1;
    build (nod<<1,st,mid);
    build ((nod<<1)|1,mid+1,dr);

    update_nod (nod,st,dr);
}

void update (int nod, int st, int dr, int x, int y, int val){
    update_lazy (nod,st,dr);
    if (x <= st && dr <= y){

        aint[nod].hash1 = 1LL * val * sp1[dr-st] % MOD1;
        aint[nod].hash2 = 1LL * val * sp2[dr-st] % MOD2;

        aint[nod].lazy = val;

        update_lazy (nod,st,dr);
        return;
    }
    int mid = (st+dr)>>1;
    if (x <= mid)
        update (nod<<1,st,mid,x,y,val);
    if (y > mid)
        update ((nod<<1)|1,mid+1,dr,x,y,val);

    update_lazy (nod<<1,st,mid);
    update_lazy ((nod<<1)|1,mid+1,dr);

    update_nod (nod,st,dr);
}

int main (){

    //ifstream cin ("date.in");
    //ofstream cout ("date.out");

    cin>>n;
    cin>>a>>b>>c;

    d.push_back(a);
    f[get_hash(a)] = 1;
    poz[0] = 0;

    pair<long long,long long> val = get_hash(b);
    if (!f[val]){
        f[val] = 1;
        d.push_back(b);
        poz[1] = 1;
    }

    val = get_hash(c);

    if (!f[val]){
        f[val] = 1;
        d.push_back(c);
        poz[2] = 2;
    }

    for (i=1;i<=n;i++)  /// nus cum sa declar un string care sa nu fie gol
        aux += "J";

    for (;;){
        w.clear();
        for (i=0;i<d.size();i++){
            for (j=poz[i]+1;j<d.size();j++){
                crossing (d[i],d[j]);

                pair <long long,long long> val = get_hash(aux);
                if (!f[val]){
                    w.push_back(aux);
                    f[val] = 1;
                }

            }
            poz[i] = d.size()-1;
        }

        if (w.empty())
            break;

        for (auto it : w)
            d.push_back(it);
    }


    cin>>q;
    cin>>v;

    p1[0] = p2[0] = 1;
    sp1[0] = sp2[0] = 1;
    for (i=1;i<=n;i++){
        p1[i] = p1[i-1] * 4 % MOD1;
        p2[i] = p2[i-1] * 4 % MOD2;

        sp1[i] = (sp1[i-1] + p1[i]) % MOD1;
        sp2[i] = (sp2[i-1] + p2[i]) % MOD2;
    }



    build (1,1,n);

    if (f[make_pair(aint[1].hash1,aint[1].hash2)])
        cout<<"Yes\n";
    else cout<<"No\n";

    for (;q--;){
        cin>>x>>y>>ch;

        int val = convert(ch);

        update (1,1,n,x,y,val);

        if (f[make_pair(aint[1].hash1,aint[1].hash2)])
            cout<<"Yes\n";
        else cout<<"No\n";
    }


    return 0;
}

Compilation message

Main.cpp: In function 'int main()':
Main.cpp:153:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::deque<std::__cxx11::basic_string<char> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  153 |         for (i=0;i<d.size();i++){
      |                  ~^~~~~~~~~
Main.cpp:154:30: warning: comparison of integer expressions of different signedness: 'int' and 'std::deque<std::__cxx11::basic_string<char> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  154 |             for (j=poz[i]+1;j<d.size();j++){
      |                             ~^~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 559 ms 11760 KB Output is correct
2 Correct 619 ms 11364 KB Output is correct
3 Correct 545 ms 4932 KB Output is correct
4 Correct 524 ms 11432 KB Output is correct
5 Correct 531 ms 11516 KB Output is correct
6 Correct 514 ms 10688 KB Output is correct
7 Correct 532 ms 10944 KB Output is correct
8 Correct 552 ms 11820 KB Output is correct
9 Correct 543 ms 11352 KB Output is correct
10 Correct 555 ms 12852 KB Output is correct
11 Correct 554 ms 11972 KB Output is correct
12 Correct 579 ms 12860 KB Output is correct
13 Correct 578 ms 12036 KB Output is correct
14 Correct 539 ms 12812 KB Output is correct
15 Correct 552 ms 11992 KB Output is correct
16 Correct 575 ms 12852 KB Output is correct
17 Correct 535 ms 12108 KB Output is correct
18 Correct 470 ms 3188 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 559 ms 11760 KB Output is correct
2 Correct 619 ms 11364 KB Output is correct
3 Correct 545 ms 4932 KB Output is correct
4 Correct 524 ms 11432 KB Output is correct
5 Correct 531 ms 11516 KB Output is correct
6 Correct 514 ms 10688 KB Output is correct
7 Correct 532 ms 10944 KB Output is correct
8 Correct 552 ms 11820 KB Output is correct
9 Correct 543 ms 11352 KB Output is correct
10 Correct 555 ms 12852 KB Output is correct
11 Correct 554 ms 11972 KB Output is correct
12 Correct 579 ms 12860 KB Output is correct
13 Correct 578 ms 12036 KB Output is correct
14 Correct 539 ms 12812 KB Output is correct
15 Correct 552 ms 11992 KB Output is correct
16 Correct 575 ms 12852 KB Output is correct
17 Correct 535 ms 12108 KB Output is correct
18 Correct 470 ms 3188 KB Output is correct
19 Correct 1012 ms 31904 KB Output is correct
20 Correct 979 ms 34824 KB Output is correct
21 Correct 761 ms 35188 KB Output is correct
22 Correct 723 ms 32292 KB Output is correct
23 Correct 678 ms 16864 KB Output is correct
24 Correct 643 ms 15568 KB Output is correct
25 Correct 810 ms 36496 KB Output is correct
26 Correct 787 ms 34516 KB Output is correct
27 Correct 932 ms 36756 KB Output is correct
28 Correct 894 ms 34368 KB Output is correct
29 Correct 857 ms 36240 KB Output is correct
30 Correct 725 ms 16944 KB Output is correct
31 Correct 903 ms 36876 KB Output is correct
32 Correct 903 ms 33352 KB Output is correct
33 Correct 688 ms 15452 KB Output is correct
34 Correct 919 ms 34568 KB Output is correct
35 Correct 792 ms 32304 KB Output is correct
36 Correct 776 ms 15692 KB Output is correct
37 Correct 709 ms 15620 KB Output is correct
38 Correct 912 ms 31900 KB Output is correct
39 Correct 624 ms 30684 KB Output is correct
40 Correct 766 ms 25820 KB Output is correct
41 Correct 899 ms 24756 KB Output is correct
42 Correct 458 ms 24176 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 559 ms 11760 KB Output is correct
2 Correct 619 ms 11364 KB Output is correct
3 Correct 545 ms 4932 KB Output is correct
4 Correct 524 ms 11432 KB Output is correct
5 Correct 531 ms 11516 KB Output is correct
6 Correct 514 ms 10688 KB Output is correct
7 Correct 532 ms 10944 KB Output is correct
8 Correct 552 ms 11820 KB Output is correct
9 Correct 543 ms 11352 KB Output is correct
10 Correct 555 ms 12852 KB Output is correct
11 Correct 554 ms 11972 KB Output is correct
12 Correct 579 ms 12860 KB Output is correct
13 Correct 578 ms 12036 KB Output is correct
14 Correct 539 ms 12812 KB Output is correct
15 Correct 552 ms 11992 KB Output is correct
16 Correct 575 ms 12852 KB Output is correct
17 Correct 535 ms 12108 KB Output is correct
18 Correct 470 ms 3188 KB Output is correct
19 Correct 530 ms 11096 KB Output is correct
20 Correct 485 ms 4916 KB Output is correct
21 Correct 568 ms 12116 KB Output is correct
22 Correct 505 ms 10288 KB Output is correct
23 Correct 561 ms 12344 KB Output is correct
24 Correct 531 ms 11204 KB Output is correct
25 Correct 546 ms 12224 KB Output is correct
26 Correct 496 ms 10816 KB Output is correct
27 Correct 574 ms 12264 KB Output is correct
28 Correct 487 ms 11200 KB Output is correct
29 Correct 523 ms 11724 KB Output is correct
30 Correct 482 ms 10564 KB Output is correct
31 Correct 557 ms 12688 KB Output is correct
32 Correct 578 ms 12296 KB Output is correct
33 Correct 558 ms 11940 KB Output is correct
34 Correct 514 ms 10964 KB Output is correct
35 Correct 572 ms 12944 KB Output is correct
36 Correct 584 ms 12144 KB Output is correct
37 Correct 568 ms 12780 KB Output is correct
38 Correct 550 ms 11980 KB Output is correct
39 Correct 563 ms 12892 KB Output is correct
40 Correct 566 ms 12080 KB Output is correct
41 Correct 575 ms 12860 KB Output is correct
42 Correct 585 ms 12096 KB Output is correct
43 Correct 525 ms 11396 KB Output is correct
44 Correct 536 ms 11948 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 559 ms 11760 KB Output is correct
2 Correct 619 ms 11364 KB Output is correct
3 Correct 545 ms 4932 KB Output is correct
4 Correct 524 ms 11432 KB Output is correct
5 Correct 531 ms 11516 KB Output is correct
6 Correct 514 ms 10688 KB Output is correct
7 Correct 532 ms 10944 KB Output is correct
8 Correct 552 ms 11820 KB Output is correct
9 Correct 543 ms 11352 KB Output is correct
10 Correct 555 ms 12852 KB Output is correct
11 Correct 554 ms 11972 KB Output is correct
12 Correct 579 ms 12860 KB Output is correct
13 Correct 578 ms 12036 KB Output is correct
14 Correct 539 ms 12812 KB Output is correct
15 Correct 552 ms 11992 KB Output is correct
16 Correct 575 ms 12852 KB Output is correct
17 Correct 535 ms 12108 KB Output is correct
18 Correct 470 ms 3188 KB Output is correct
19 Correct 1012 ms 31904 KB Output is correct
20 Correct 979 ms 34824 KB Output is correct
21 Correct 761 ms 35188 KB Output is correct
22 Correct 723 ms 32292 KB Output is correct
23 Correct 678 ms 16864 KB Output is correct
24 Correct 643 ms 15568 KB Output is correct
25 Correct 810 ms 36496 KB Output is correct
26 Correct 787 ms 34516 KB Output is correct
27 Correct 932 ms 36756 KB Output is correct
28 Correct 894 ms 34368 KB Output is correct
29 Correct 857 ms 36240 KB Output is correct
30 Correct 725 ms 16944 KB Output is correct
31 Correct 903 ms 36876 KB Output is correct
32 Correct 903 ms 33352 KB Output is correct
33 Correct 688 ms 15452 KB Output is correct
34 Correct 919 ms 34568 KB Output is correct
35 Correct 792 ms 32304 KB Output is correct
36 Correct 776 ms 15692 KB Output is correct
37 Correct 709 ms 15620 KB Output is correct
38 Correct 912 ms 31900 KB Output is correct
39 Correct 624 ms 30684 KB Output is correct
40 Correct 766 ms 25820 KB Output is correct
41 Correct 899 ms 24756 KB Output is correct
42 Correct 458 ms 24176 KB Output is correct
43 Correct 530 ms 11096 KB Output is correct
44 Correct 485 ms 4916 KB Output is correct
45 Correct 568 ms 12116 KB Output is correct
46 Correct 505 ms 10288 KB Output is correct
47 Correct 561 ms 12344 KB Output is correct
48 Correct 531 ms 11204 KB Output is correct
49 Correct 546 ms 12224 KB Output is correct
50 Correct 496 ms 10816 KB Output is correct
51 Correct 574 ms 12264 KB Output is correct
52 Correct 487 ms 11200 KB Output is correct
53 Correct 523 ms 11724 KB Output is correct
54 Correct 482 ms 10564 KB Output is correct
55 Correct 557 ms 12688 KB Output is correct
56 Correct 578 ms 12296 KB Output is correct
57 Correct 558 ms 11940 KB Output is correct
58 Correct 514 ms 10964 KB Output is correct
59 Correct 572 ms 12944 KB Output is correct
60 Correct 584 ms 12144 KB Output is correct
61 Correct 568 ms 12780 KB Output is correct
62 Correct 550 ms 11980 KB Output is correct
63 Correct 563 ms 12892 KB Output is correct
64 Correct 566 ms 12080 KB Output is correct
65 Correct 575 ms 12860 KB Output is correct
66 Correct 585 ms 12096 KB Output is correct
67 Correct 525 ms 11396 KB Output is correct
68 Correct 536 ms 11948 KB Output is correct
69 Correct 1096 ms 32936 KB Output is correct
70 Correct 1212 ms 36320 KB Output is correct
71 Correct 637 ms 15828 KB Output is correct
72 Correct 699 ms 15660 KB Output is correct
73 Correct 655 ms 15752 KB Output is correct
74 Correct 737 ms 33972 KB Output is correct
75 Correct 665 ms 16864 KB Output is correct
76 Correct 817 ms 36844 KB Output is correct
77 Correct 766 ms 32656 KB Output is correct
78 Correct 656 ms 15716 KB Output is correct
79 Correct 675 ms 15672 KB Output is correct
80 Correct 938 ms 33364 KB Output is correct
81 Correct 721 ms 17092 KB Output is correct
82 Correct 1101 ms 38132 KB Output is correct
83 Correct 1059 ms 35044 KB Output is correct
84 Correct 683 ms 15640 KB Output is correct
85 Correct 698 ms 15760 KB Output is correct
86 Correct 902 ms 32940 KB Output is correct
87 Correct 1027 ms 36024 KB Output is correct
88 Correct 681 ms 15176 KB Output is correct
89 Correct 931 ms 34316 KB Output is correct
90 Correct 1033 ms 36392 KB Output is correct
91 Correct 669 ms 15088 KB Output is correct
92 Correct 937 ms 33856 KB Output is correct
93 Correct 679 ms 15668 KB Output is correct
94 Correct 696 ms 15776 KB Output is correct
95 Correct 687 ms 15764 KB Output is correct
96 Correct 927 ms 31964 KB Output is correct
97 Correct 850 ms 33636 KB Output is correct
98 Correct 929 ms 26872 KB Output is correct
99 Correct 1063 ms 26808 KB Output is correct
100 Correct 690 ms 26128 KB Output is correct