답안 #874960

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
874960 2023-11-18T10:20:27 Z efedmrlr Crossing (JOI21_crossing) C++17
26 / 100
216 ms 22344 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> s;
lli shash = 0;
lli pw[N];
lli powsm[N];

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;
    }
}


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 A;
    cin>>A;
    cin>>A;
    cin>>A;
    str_to_vec(A, s);

    cin>>q;
    vector<int> t0;
    cin>>A;
    str_to_vec(A, t0);
    SegTree st(n);
    for(int i = 0; i<n; i++) {
        shash = add(shash, mult(s[i], pw[i]));
    }
    for(int i = 0; i<n; i++) {
        st.update(i, i, t0[i]);
    }
    if(st.query(0, n - 1) == shash) {
        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 hs = st.query(0, n - 1);
        if(hs == shash) {
            cout<<"Yes\n";
        }
        else {
            cout<<"No\n";
        }
        
        
    }


}

Compilation message

Main.cpp: In function 'void str_to_vec(std::string&, std::vector<int>&)':
Main.cpp:96:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   96 |     for(int i = 0; i<src.size(); i++) {
      |                    ~^~~~~~~~~~~
Main.cpp: In function 'int main()':
Main.cpp:62:23: warning: 'cr' may be used uninitialized in this function [-Wmaybe-uninitialized]
   62 |             lazy[v] = val;
      |                       ^~~
Main.cpp:138:18: note: 'cr' was declared here
  138 |         int l,r, cr;
      |                  ^~
# 결과 실행 시간 메모리 Grader output
1 Correct 48 ms 5416 KB Output is correct
2 Correct 54 ms 5572 KB Output is correct
3 Correct 54 ms 5408 KB Output is correct
4 Correct 58 ms 5592 KB Output is correct
5 Correct 46 ms 5584 KB Output is correct
6 Correct 46 ms 5460 KB Output is correct
7 Correct 47 ms 5656 KB Output is correct
8 Correct 48 ms 5684 KB Output is correct
9 Correct 49 ms 5688 KB Output is correct
10 Correct 53 ms 5716 KB Output is correct
11 Correct 50 ms 5528 KB Output is correct
12 Correct 49 ms 5716 KB Output is correct
13 Correct 49 ms 5500 KB Output is correct
14 Correct 63 ms 5552 KB Output is correct
15 Correct 49 ms 5712 KB Output is correct
16 Correct 49 ms 5684 KB Output is correct
17 Correct 50 ms 5684 KB Output is correct
18 Correct 50 ms 5640 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 48 ms 5416 KB Output is correct
2 Correct 54 ms 5572 KB Output is correct
3 Correct 54 ms 5408 KB Output is correct
4 Correct 58 ms 5592 KB Output is correct
5 Correct 46 ms 5584 KB Output is correct
6 Correct 46 ms 5460 KB Output is correct
7 Correct 47 ms 5656 KB Output is correct
8 Correct 48 ms 5684 KB Output is correct
9 Correct 49 ms 5688 KB Output is correct
10 Correct 53 ms 5716 KB Output is correct
11 Correct 50 ms 5528 KB Output is correct
12 Correct 49 ms 5716 KB Output is correct
13 Correct 49 ms 5500 KB Output is correct
14 Correct 63 ms 5552 KB Output is correct
15 Correct 49 ms 5712 KB Output is correct
16 Correct 49 ms 5684 KB Output is correct
17 Correct 50 ms 5684 KB Output is correct
18 Correct 50 ms 5640 KB Output is correct
19 Correct 216 ms 22084 KB Output is correct
20 Correct 195 ms 21984 KB Output is correct
21 Correct 153 ms 21216 KB Output is correct
22 Correct 145 ms 19480 KB Output is correct
23 Correct 83 ms 7252 KB Output is correct
24 Correct 79 ms 7252 KB Output is correct
25 Correct 154 ms 22156 KB Output is correct
26 Correct 154 ms 22092 KB Output is correct
27 Correct 166 ms 22200 KB Output is correct
28 Correct 173 ms 22088 KB Output is correct
29 Correct 196 ms 21668 KB Output is correct
30 Correct 86 ms 7140 KB Output is correct
31 Correct 164 ms 22212 KB Output is correct
32 Correct 164 ms 20696 KB Output is correct
33 Correct 80 ms 7212 KB Output is correct
34 Correct 174 ms 22084 KB Output is correct
35 Correct 130 ms 17916 KB Output is correct
36 Correct 79 ms 7032 KB Output is correct
37 Correct 80 ms 7256 KB Output is correct
38 Correct 174 ms 21976 KB Output is correct
39 Correct 134 ms 22232 KB Output is correct
40 Correct 174 ms 16900 KB Output is correct
41 Correct 216 ms 22344 KB Output is correct
42 Correct 77 ms 21724 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 48 ms 5416 KB Output is correct
2 Correct 54 ms 5572 KB Output is correct
3 Correct 54 ms 5408 KB Output is correct
4 Correct 58 ms 5592 KB Output is correct
5 Correct 46 ms 5584 KB Output is correct
6 Correct 46 ms 5460 KB Output is correct
7 Correct 47 ms 5656 KB Output is correct
8 Correct 48 ms 5684 KB Output is correct
9 Correct 49 ms 5688 KB Output is correct
10 Correct 53 ms 5716 KB Output is correct
11 Correct 50 ms 5528 KB Output is correct
12 Correct 49 ms 5716 KB Output is correct
13 Correct 49 ms 5500 KB Output is correct
14 Correct 63 ms 5552 KB Output is correct
15 Correct 49 ms 5712 KB Output is correct
16 Correct 49 ms 5684 KB Output is correct
17 Correct 50 ms 5684 KB Output is correct
18 Correct 50 ms 5640 KB Output is correct
19 Correct 55 ms 5460 KB Output is correct
20 Correct 59 ms 5624 KB Output is correct
21 Incorrect 54 ms 5628 KB Output isn't correct
22 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 48 ms 5416 KB Output is correct
2 Correct 54 ms 5572 KB Output is correct
3 Correct 54 ms 5408 KB Output is correct
4 Correct 58 ms 5592 KB Output is correct
5 Correct 46 ms 5584 KB Output is correct
6 Correct 46 ms 5460 KB Output is correct
7 Correct 47 ms 5656 KB Output is correct
8 Correct 48 ms 5684 KB Output is correct
9 Correct 49 ms 5688 KB Output is correct
10 Correct 53 ms 5716 KB Output is correct
11 Correct 50 ms 5528 KB Output is correct
12 Correct 49 ms 5716 KB Output is correct
13 Correct 49 ms 5500 KB Output is correct
14 Correct 63 ms 5552 KB Output is correct
15 Correct 49 ms 5712 KB Output is correct
16 Correct 49 ms 5684 KB Output is correct
17 Correct 50 ms 5684 KB Output is correct
18 Correct 50 ms 5640 KB Output is correct
19 Correct 216 ms 22084 KB Output is correct
20 Correct 195 ms 21984 KB Output is correct
21 Correct 153 ms 21216 KB Output is correct
22 Correct 145 ms 19480 KB Output is correct
23 Correct 83 ms 7252 KB Output is correct
24 Correct 79 ms 7252 KB Output is correct
25 Correct 154 ms 22156 KB Output is correct
26 Correct 154 ms 22092 KB Output is correct
27 Correct 166 ms 22200 KB Output is correct
28 Correct 173 ms 22088 KB Output is correct
29 Correct 196 ms 21668 KB Output is correct
30 Correct 86 ms 7140 KB Output is correct
31 Correct 164 ms 22212 KB Output is correct
32 Correct 164 ms 20696 KB Output is correct
33 Correct 80 ms 7212 KB Output is correct
34 Correct 174 ms 22084 KB Output is correct
35 Correct 130 ms 17916 KB Output is correct
36 Correct 79 ms 7032 KB Output is correct
37 Correct 80 ms 7256 KB Output is correct
38 Correct 174 ms 21976 KB Output is correct
39 Correct 134 ms 22232 KB Output is correct
40 Correct 174 ms 16900 KB Output is correct
41 Correct 216 ms 22344 KB Output is correct
42 Correct 77 ms 21724 KB Output is correct
43 Correct 55 ms 5460 KB Output is correct
44 Correct 59 ms 5624 KB Output is correct
45 Incorrect 54 ms 5628 KB Output isn't correct
46 Halted 0 ms 0 KB -