답안 #874970

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
874970 2023-11-18T11:01:38 Z efedmrlr Crossing (JOI21_crossing) C++17
100 / 100
244 ms 25308 KB
#include <bits/stdc++.h>

using namespace std;

#define lli long long int
#define MP make_pair
#define pb push_back
#define REP(i,n) for(int (i) = 0; (i)<(n); (i)++)

void fastio() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
}

const int N = 2e5+5;
const lli MOD = 1e9+7;
const lli INF = 1e12;
const int M = 1e6+5;
const long double EPS = 0.00001;
const lli PRIME = 5;
int n,m,q;
vector<int> A,B,C;
lli pw[N];
lli powsm[N];
vector<lli> hs(9);
lli mult(lli x, lli y) {
    return x*y%MOD;
}
lli add(lli x, lli y) {
    return (x+y)%MOD;
}
lli subt(lli x, lli y) {
    if(x - y < 0) return x - y + MOD;
    return x - y;
}
lli find_pow_sum(int l, int r) {
    return subt(powsm[r] , (l > 0 ? powsm[l - 1] : 0ll));
}


struct SegTree {
    vector<lli> data, lazy;
    int sz;
    SegTree(int sz) {
        this->sz = sz;
        data.assign(4*(sz+5), 0);
        lazy.assign(4*(sz+5), -1);
    }
    void push(int tl, int tr, int v) {
        if(lazy[v] == -1) return;
        int tm = (tl + tr) >> 1;
        data[v*2] = mult(lazy[v] , find_pow_sum(tl, tm));
        data[v*2+1] = mult(lazy[v] , find_pow_sum(tm + 1, tr));
        lazy[v*2] = lazy[v];
        lazy[v*2+1] = lazy[v];
        lazy[v] = -1; 
    }

    void update(int tl, int tr, int v, int l, int r, int val) {
        if(tl >= l && tr <= r) {
            lazy[v] = val;
            data[v] = mult(val , find_pow_sum(tl, tr));
            return;
        }
        if(tl > r || tr < l) {
            return;
        }
        push(tl, tr, v);
        int tm = (tl + tr) >> 1;
        update(tl, tm, v*2, l, r, val);
        update(tm + 1, tr ,v*2+1, l, r, val);
        data[v] = add(data[v*2], data[v*2+1]);
    }
    void update(int l, int r, int val) {
        update(0, sz - 1, 1, l, r, val);
    }
    lli query(int tl, int tr, int v, int l, int r) {
        if(tl >= l && tr <= r) {
            return data[v];
        }
        if(tl > r || tr < l) {
            return 0;
        }
        push(tl, tr, v);
        int tm = (tl + tr) >> 1;
        return add(query(tl, tm, v*2, l, r), query(tm + 1, tr, v*2+1, l , r));
    }
    lli query(int l, int r) {
        return query(0, sz - 1, 1, l, r);
    }
};

void str_to_vec(string &src, vector<int> &nw) {
    nw.resize(src.size());
    for(int i = 0; i<src.size(); i++) {
        if(src[i] == 'J') nw[i] = 0;
        if(src[i] == 'O') nw[i] = 1;
        if(src[i] == 'I') nw[i] = 2;
    }
}
vector<int> cross(vector<int> &x, vector<int> &y) {
    vector<int> ret(n);
    for(int i = 0; i<n; i++) {
        int c1 = x[i],c2 = y[i];
        if(c1 > c2) swap(c1, c2);
        if(c1 == c2) {
            ret[i] = c1;
        }
        else if(c1 == 0 && c2 == 1) {
            ret[i] = 2;
        }
        else if(c1 == 1 && c2 == 2) {
            ret[i] = 0;
        }
        else if(c1 == 0 && c2 == 2) {
            ret[i] = 1;
        }
        else {
            assert(0);
        }

    }
    return ret;
}

lli find_hash(vector<int> &x) {
    lli ret = 0;
    for(int i = 0; i<n; i++) {
        ret = add(ret , mult(x[i] , pw[i]));
    }
    return ret;
}
void calc_hash() {
    hs[0] = find_hash(A);
    hs[1] = find_hash(B);
    hs[2] = find_hash(C);
    vector<int> ab = cross(A,B), ac = cross(A,C), bc = cross(B,C);
    hs[3] = find_hash(ab);
    hs[4] = find_hash(ac);
    hs[5] = find_hash(bc);
    vector<int> abC = cross(ab, C), acB = cross(ac, B), bcA = cross(bc, A);
    hs[6] = find_hash(abC);
    hs[7] = find_hash(acB);
    hs[8] = find_hash(bcA);
}
bool check(lli x) {
    for(auto ind : hs) {
        if(x == ind) return 1;
    }
    return 0;
}
signed main() {
    //PREC
    powsm[0] = 1ll;
    pw[0] = 1ll;
    for(int i = 1; i<N; i++) {
        pw[i] = mult(pw[i - 1], PRIME);
        powsm[i] = powsm[i - 1] + pw[i];
    }
    fastio();
    cin>>n;
    string tmp;
    cin>>tmp;
    str_to_vec(tmp, A);
    cin>>tmp;
    str_to_vec(tmp, B);
    cin>>tmp;
    str_to_vec(tmp, C);

    cin>>q;
    vector<int> t0;
    cin>>tmp;
    str_to_vec(tmp, t0);
    SegTree st(n);
    calc_hash();
    for(int i = 0; i<n; i++) {
        st.update(i, i, t0[i]);
    }
    if(check(st.query(0, n - 1))) {
        cout<<"Yes\n";
    }
    else {
        cout<<"No\n";
    }
    for(int i = 0; i<q; i++) {
        int l,r, cr;
        char c;
        cin>>l>>r>>c;
        l--; r--;
        if(c == 'J') cr = 0;
        if(c == 'O') cr = 1;
        if(c == 'I') cr = 2;
        st.update(l,r,cr);
        lli tmp = st.query(0, n - 1);
        if(check(tmp)) {
            cout<<"Yes\n";
        }
        else {
            cout<<"No\n";
        }
        
        
    }


}

Compilation message

Main.cpp: In function 'void str_to_vec(std::string&, std::vector<int>&)':
Main.cpp:95:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   95 |     for(int i = 0; i<src.size(); i++) {
      |                    ~^~~~~~~~~~~
Main.cpp: In function 'int main()':
Main.cpp:61:23: warning: 'cr' may be used uninitialized in this function [-Wmaybe-uninitialized]
   61 |             lazy[v] = val;
      |                       ^~~
Main.cpp:186:18: note: 'cr' was declared here
  186 |         int l,r, cr;
      |                  ^~
# 결과 실행 시간 메모리 Grader output
1 Correct 55 ms 4928 KB Output is correct
2 Correct 57 ms 5200 KB Output is correct
3 Correct 55 ms 5112 KB Output is correct
4 Correct 49 ms 4956 KB Output is correct
5 Correct 48 ms 5032 KB Output is correct
6 Correct 59 ms 5136 KB Output is correct
7 Correct 56 ms 4988 KB Output is correct
8 Correct 50 ms 5132 KB Output is correct
9 Correct 53 ms 5204 KB Output is correct
10 Correct 51 ms 5212 KB Output is correct
11 Correct 51 ms 5040 KB Output is correct
12 Correct 52 ms 5200 KB Output is correct
13 Correct 52 ms 5204 KB Output is correct
14 Correct 51 ms 4976 KB Output is correct
15 Correct 52 ms 5204 KB Output is correct
16 Correct 51 ms 4988 KB Output is correct
17 Correct 51 ms 5200 KB Output is correct
18 Correct 52 ms 5228 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 55 ms 4928 KB Output is correct
2 Correct 57 ms 5200 KB Output is correct
3 Correct 55 ms 5112 KB Output is correct
4 Correct 49 ms 4956 KB Output is correct
5 Correct 48 ms 5032 KB Output is correct
6 Correct 59 ms 5136 KB Output is correct
7 Correct 56 ms 4988 KB Output is correct
8 Correct 50 ms 5132 KB Output is correct
9 Correct 53 ms 5204 KB Output is correct
10 Correct 51 ms 5212 KB Output is correct
11 Correct 51 ms 5040 KB Output is correct
12 Correct 52 ms 5200 KB Output is correct
13 Correct 52 ms 5204 KB Output is correct
14 Correct 51 ms 4976 KB Output is correct
15 Correct 52 ms 5204 KB Output is correct
16 Correct 51 ms 4988 KB Output is correct
17 Correct 51 ms 5200 KB Output is correct
18 Correct 52 ms 5228 KB Output is correct
19 Correct 226 ms 24808 KB Output is correct
20 Correct 212 ms 25056 KB Output is correct
21 Correct 167 ms 23780 KB Output is correct
22 Correct 156 ms 21736 KB Output is correct
23 Correct 88 ms 6504 KB Output is correct
24 Correct 84 ms 6628 KB Output is correct
25 Correct 163 ms 25052 KB Output is correct
26 Correct 177 ms 25064 KB Output is correct
27 Correct 183 ms 25052 KB Output is correct
28 Correct 203 ms 25064 KB Output is correct
29 Correct 186 ms 24548 KB Output is correct
30 Correct 91 ms 6624 KB Output is correct
31 Correct 183 ms 25064 KB Output is correct
32 Correct 166 ms 23272 KB Output is correct
33 Correct 83 ms 6644 KB Output is correct
34 Correct 178 ms 25064 KB Output is correct
35 Correct 137 ms 19664 KB Output is correct
36 Correct 82 ms 6632 KB Output is correct
37 Correct 85 ms 6632 KB Output is correct
38 Correct 185 ms 25248 KB Output is correct
39 Correct 144 ms 25308 KB Output is correct
40 Correct 136 ms 17884 KB Output is correct
41 Correct 235 ms 25076 KB Output is correct
42 Correct 86 ms 25052 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 55 ms 4928 KB Output is correct
2 Correct 57 ms 5200 KB Output is correct
3 Correct 55 ms 5112 KB Output is correct
4 Correct 49 ms 4956 KB Output is correct
5 Correct 48 ms 5032 KB Output is correct
6 Correct 59 ms 5136 KB Output is correct
7 Correct 56 ms 4988 KB Output is correct
8 Correct 50 ms 5132 KB Output is correct
9 Correct 53 ms 5204 KB Output is correct
10 Correct 51 ms 5212 KB Output is correct
11 Correct 51 ms 5040 KB Output is correct
12 Correct 52 ms 5200 KB Output is correct
13 Correct 52 ms 5204 KB Output is correct
14 Correct 51 ms 4976 KB Output is correct
15 Correct 52 ms 5204 KB Output is correct
16 Correct 51 ms 4988 KB Output is correct
17 Correct 51 ms 5200 KB Output is correct
18 Correct 52 ms 5228 KB Output is correct
19 Correct 58 ms 4944 KB Output is correct
20 Correct 56 ms 5140 KB Output is correct
21 Correct 55 ms 4976 KB Output is correct
22 Correct 45 ms 5464 KB Output is correct
23 Correct 52 ms 5712 KB Output is correct
24 Correct 51 ms 5460 KB Output is correct
25 Correct 54 ms 5712 KB Output is correct
26 Correct 48 ms 5460 KB Output is correct
27 Correct 54 ms 5488 KB Output is correct
28 Correct 47 ms 5460 KB Output is correct
29 Correct 52 ms 5716 KB Output is correct
30 Correct 46 ms 5456 KB Output is correct
31 Correct 51 ms 5624 KB Output is correct
32 Correct 67 ms 5692 KB Output is correct
33 Correct 51 ms 5640 KB Output is correct
34 Correct 54 ms 5460 KB Output is correct
35 Correct 51 ms 5680 KB Output is correct
36 Correct 53 ms 5564 KB Output is correct
37 Correct 51 ms 5692 KB Output is correct
38 Correct 53 ms 5724 KB Output is correct
39 Correct 68 ms 5504 KB Output is correct
40 Correct 52 ms 5692 KB Output is correct
41 Correct 52 ms 5640 KB Output is correct
42 Correct 52 ms 5716 KB Output is correct
43 Correct 49 ms 5460 KB Output is correct
44 Correct 51 ms 5712 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 55 ms 4928 KB Output is correct
2 Correct 57 ms 5200 KB Output is correct
3 Correct 55 ms 5112 KB Output is correct
4 Correct 49 ms 4956 KB Output is correct
5 Correct 48 ms 5032 KB Output is correct
6 Correct 59 ms 5136 KB Output is correct
7 Correct 56 ms 4988 KB Output is correct
8 Correct 50 ms 5132 KB Output is correct
9 Correct 53 ms 5204 KB Output is correct
10 Correct 51 ms 5212 KB Output is correct
11 Correct 51 ms 5040 KB Output is correct
12 Correct 52 ms 5200 KB Output is correct
13 Correct 52 ms 5204 KB Output is correct
14 Correct 51 ms 4976 KB Output is correct
15 Correct 52 ms 5204 KB Output is correct
16 Correct 51 ms 4988 KB Output is correct
17 Correct 51 ms 5200 KB Output is correct
18 Correct 52 ms 5228 KB Output is correct
19 Correct 226 ms 24808 KB Output is correct
20 Correct 212 ms 25056 KB Output is correct
21 Correct 167 ms 23780 KB Output is correct
22 Correct 156 ms 21736 KB Output is correct
23 Correct 88 ms 6504 KB Output is correct
24 Correct 84 ms 6628 KB Output is correct
25 Correct 163 ms 25052 KB Output is correct
26 Correct 177 ms 25064 KB Output is correct
27 Correct 183 ms 25052 KB Output is correct
28 Correct 203 ms 25064 KB Output is correct
29 Correct 186 ms 24548 KB Output is correct
30 Correct 91 ms 6624 KB Output is correct
31 Correct 183 ms 25064 KB Output is correct
32 Correct 166 ms 23272 KB Output is correct
33 Correct 83 ms 6644 KB Output is correct
34 Correct 178 ms 25064 KB Output is correct
35 Correct 137 ms 19664 KB Output is correct
36 Correct 82 ms 6632 KB Output is correct
37 Correct 85 ms 6632 KB Output is correct
38 Correct 185 ms 25248 KB Output is correct
39 Correct 144 ms 25308 KB Output is correct
40 Correct 136 ms 17884 KB Output is correct
41 Correct 235 ms 25076 KB Output is correct
42 Correct 86 ms 25052 KB Output is correct
43 Correct 58 ms 4944 KB Output is correct
44 Correct 56 ms 5140 KB Output is correct
45 Correct 55 ms 4976 KB Output is correct
46 Correct 45 ms 5464 KB Output is correct
47 Correct 52 ms 5712 KB Output is correct
48 Correct 51 ms 5460 KB Output is correct
49 Correct 54 ms 5712 KB Output is correct
50 Correct 48 ms 5460 KB Output is correct
51 Correct 54 ms 5488 KB Output is correct
52 Correct 47 ms 5460 KB Output is correct
53 Correct 52 ms 5716 KB Output is correct
54 Correct 46 ms 5456 KB Output is correct
55 Correct 51 ms 5624 KB Output is correct
56 Correct 67 ms 5692 KB Output is correct
57 Correct 51 ms 5640 KB Output is correct
58 Correct 54 ms 5460 KB Output is correct
59 Correct 51 ms 5680 KB Output is correct
60 Correct 53 ms 5564 KB Output is correct
61 Correct 51 ms 5692 KB Output is correct
62 Correct 53 ms 5724 KB Output is correct
63 Correct 68 ms 5504 KB Output is correct
64 Correct 52 ms 5692 KB Output is correct
65 Correct 52 ms 5640 KB Output is correct
66 Correct 52 ms 5716 KB Output is correct
67 Correct 49 ms 5460 KB Output is correct
68 Correct 51 ms 5712 KB Output is correct
69 Correct 202 ms 21776 KB Output is correct
70 Correct 221 ms 25248 KB Output is correct
71 Correct 82 ms 7296 KB Output is correct
72 Correct 87 ms 7828 KB Output is correct
73 Correct 86 ms 7524 KB Output is correct
74 Correct 196 ms 21472 KB Output is correct
75 Correct 90 ms 7904 KB Output is correct
76 Correct 168 ms 25056 KB Output is correct
77 Correct 153 ms 21724 KB Output is correct
78 Correct 84 ms 7356 KB Output is correct
79 Correct 89 ms 7476 KB Output is correct
80 Correct 164 ms 18908 KB Output is correct
81 Correct 90 ms 7396 KB Output is correct
82 Correct 189 ms 25052 KB Output is correct
83 Correct 177 ms 23776 KB Output is correct
84 Correct 84 ms 7408 KB Output is correct
85 Correct 85 ms 7456 KB Output is correct
86 Correct 170 ms 19940 KB Output is correct
87 Correct 185 ms 25060 KB Output is correct
88 Correct 88 ms 7392 KB Output is correct
89 Correct 166 ms 22928 KB Output is correct
90 Correct 174 ms 25060 KB Output is correct
91 Correct 87 ms 7396 KB Output is correct
92 Correct 148 ms 19688 KB Output is correct
93 Correct 82 ms 7396 KB Output is correct
94 Correct 81 ms 7472 KB Output is correct
95 Correct 82 ms 7280 KB Output is correct
96 Correct 186 ms 25056 KB Output is correct
97 Correct 145 ms 25052 KB Output is correct
98 Correct 144 ms 17892 KB Output is correct
99 Correct 244 ms 25052 KB Output is correct
100 Correct 98 ms 25052 KB Output is correct