답안 #533849

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
533849 2022-03-07T12:23:41 Z someone Crossing (JOI21_crossing) C++14
0 / 100
319 ms 33952 KB
#include <bits/stdc++.h>
#define int long long
using namespace std;
 
const int M = 1 << 18, N = 2 * M;

int n, q, ans = 0, val[3][M];

struct HashLazy {
    set<int> pos;
    int hashval[N], tag_a[N], tag_b[N], pow3[M+1], cumP[M+1], MOD;
    
    HashLazy(int mod) {
        MOD = mod;
        
        pow3[0] = 1;
        for(int i = 1; i <= M; i++)
            pow3[i] = (pow3[i-1] * 3) % MOD;
        for(int i = 1; i <= M; i++)
            cumP[i] = (pow3[i-1] + cumP[i-1]) % MOD;
        
        for(int i = 0; i < 3; i++)
            for(int j = 0; j < 3; j++) {
                int hashing = 0;
                for(int k = 0; k < n; k++)
                    hashing = (hashing * 3 + (i * (val[0][k] + val[1][k] + val[2][k]) + val[j][k]) % 3) % MOD;
                pos.insert(hashing);
            }
    }
 
    inline void updNode(int i, int a, int b, int d, int f) {
        if(a == 0) {
            tag_a[i] = 0;
            tag_b[i] = b;
            hashval[i] = (b * cumP[f - d]) % MOD;
        }
    }
     
    int update(int i, int deb, int fin, int a, int b, int d = 0, int f = M) {
        if(deb <= d && f <= fin) {
            updNode(i, a, b, d, f);
            return hashval[i];
        }
        if(f <= deb || fin <= d)
            return 0;
        
        int med = (d + f) >> 1;
        updNode(i*2, tag_a[i], tag_b[i], d, med);
        updNode(i*2+1, tag_a[i], tag_b[i], med, f);
        
        tag_a[i] = 1;
        tag_b[i] = 0;
        
        int val1 = update(i*2, deb, fin, a, b, d, med),
            val2 = update(i*2+1, deb, fin, a, b, med, f);
        
        hashval[i] = (hashval[i*2] * pow3[f-med] + hashval[i*2+1]) % MOD;
      
        if(deb < med && med < fin)
            return (val1 * pow3[fin-med] + val2) % MOD;
        else
            return max(val1, val2);
    }
    
    bool good() {
        return pos.find(update(1, 0, n, 1, 0)) != pos.end();
    }
};

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    
    cin >> n;
    
    for(int i = 0; i < 3; i++) {
        for(int j = 0; j < n; j++) {
            char c; cin >> c;
            if(c == 'O')
                val[i][j] = 1;
            else if(c == 'I')
                val[i][j] = 2;
        }
    }
    
    HashLazy a(1e9 + 7), b(1e9 + 9);
    
    cin >> q;
    for(int i = 0; i < n; i++) {
        char c; cin >> c;
        if(c == 'O') {
            a.update(1, i, i+1, 0, 1);
            b.update(1, i, i+1, 0, 1);
        } else if(c == 'I') {
            a.update(1, i, i+1, 0, 2);
            b.update(1, i, i+1, 0, 2);
        }
    }
    
    if(a.good() && b.good())
        cout << "Yes\n";
    else
        cout << "No\n";
    
    for(int i = 0; i < q; i++) {
        char c;
        int deb, fin;
        cin >> deb >> fin >> c;
        deb--;
        if(c == 'J') {
            a.update(1, deb, fin, 0, 0);
            b.update(1, deb, fin, 0, 0);
        } else if(c == 'O') {
            a.update(1, deb, fin, 0, 1);
            b.update(1, deb, fin, 0, 1);
        } else if(c == 'I') {
            a.update(1, deb, fin, 0, 2);
            b.update(1, deb, fin, 0, 2);
        }
    
    if(a.good() && b.good())
        cout << "Yes\n";
    else
        cout << "No\n";
    }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 279 ms 33784 KB Output is correct
2 Correct 298 ms 33692 KB Output is correct
3 Correct 319 ms 33732 KB Output is correct
4 Correct 286 ms 33668 KB Output is correct
5 Correct 300 ms 33732 KB Output is correct
6 Correct 281 ms 33768 KB Output is correct
7 Correct 299 ms 33732 KB Output is correct
8 Correct 303 ms 33952 KB Output is correct
9 Correct 299 ms 33688 KB Output is correct
10 Incorrect 283 ms 33692 KB Output isn't correct
11 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 279 ms 33784 KB Output is correct
2 Correct 298 ms 33692 KB Output is correct
3 Correct 319 ms 33732 KB Output is correct
4 Correct 286 ms 33668 KB Output is correct
5 Correct 300 ms 33732 KB Output is correct
6 Correct 281 ms 33768 KB Output is correct
7 Correct 299 ms 33732 KB Output is correct
8 Correct 303 ms 33952 KB Output is correct
9 Correct 299 ms 33688 KB Output is correct
10 Incorrect 283 ms 33692 KB Output isn't correct
11 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 279 ms 33784 KB Output is correct
2 Correct 298 ms 33692 KB Output is correct
3 Correct 319 ms 33732 KB Output is correct
4 Correct 286 ms 33668 KB Output is correct
5 Correct 300 ms 33732 KB Output is correct
6 Correct 281 ms 33768 KB Output is correct
7 Correct 299 ms 33732 KB Output is correct
8 Correct 303 ms 33952 KB Output is correct
9 Correct 299 ms 33688 KB Output is correct
10 Incorrect 283 ms 33692 KB Output isn't correct
11 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 279 ms 33784 KB Output is correct
2 Correct 298 ms 33692 KB Output is correct
3 Correct 319 ms 33732 KB Output is correct
4 Correct 286 ms 33668 KB Output is correct
5 Correct 300 ms 33732 KB Output is correct
6 Correct 281 ms 33768 KB Output is correct
7 Correct 299 ms 33732 KB Output is correct
8 Correct 303 ms 33952 KB Output is correct
9 Correct 299 ms 33688 KB Output is correct
10 Incorrect 283 ms 33692 KB Output isn't correct
11 Halted 0 ms 0 KB -