답안 #1051831

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1051831 2024-08-10T10:04:38 Z crafticat Crossing (JOI21_crossing) C++17
26 / 100
702 ms 62572 KB
#include <bits/stdc++.h>

using namespace std;

#include <bits/stdc++.h>

#include <utility>
using namespace std;

using ll = long long;
using pi = pair<int,int>;
using pl = pair<ll,ll>;

#define temp(T) template<class T>
temp(T) using V = vector<T>;
using vi = V<int>;
using vl = V<ll>;
using vvi = V<vi>;
using vpi = V<pi>;
using vb = V<bool>;
using vvb = V<vb>;
vi dx = {0,1,-1,0};
vi dy = {1,0,0,-1};

#define sz(x) x.size()
#define all(x) begin(x), end(x)
#define rall(x) rbegin(x), rend(x)
#define sor(x) sort(all(x))
#define rsz resize
#define ins insert
#define pb push_back
#define eb emplace_back
#define f first
#define s second

#define lb lower_bound
#define ub upper_bound

#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define F0R(i,a) FOR(i,0,a)
#define ROF(i,a,b) for (int i = (b)-1; i >= (a); --i)
#define R0F(i,a) ROF(i,0,a)
#define rep(a) F0R(_,a)
#define each(a,x) for (auto& a: x)

using str = string;

const int MOD = 1e9 + 7;
const ll BIG = 1e18;
const int INF = 1e9 + 2;

temp(T) bool ckmin(T& a, const T& b) {
    return b < a ? a = b, 1 : 0; } // set a = min(a,b)
temp(T) bool ckmax(T& a, const T& b) {
    return a < b ? a = b, 1 : 0; } // set a = max(a,b)

void unsyncIO() { cin.tie(0)->sync_with_stdio(0); }
// FILE I/O
void setIn(str s) { freopen(s.c_str(),"r",stdin); }
void setOut(str s) { freopen(s.c_str(),"w",stdout); }
void setIO(str s = "") {
    unsyncIO();
    if (sz(s)) setIn(s+".in"), setOut(s+".out"); // for USACO
}

#define read(x) int x; cin >> x

temp(T) void pr(T x) {
    cout << to_string(x);
}
temp(T) void prln(T x) {
    cout << to_string(x) << "\n";
}


vi readV(int n) {

    vi input(n);
    F0R(i,n)
        cin >> input[i];
    return input;
}

int rand(int a, int b) {
    return a + rand() % (b - a + 1);
}

#define gen(x,a,b) int x = rand(a,b)

temp(T) void moveAll(V<T> &a, V<T> &b) {
    each(x,b) {
        a.pb(x);
    }
    b.clear();
}

vi genArr(int n, int a, int b) {
    vi generated(n);
    F0R(i,n) {
        generated[i] = rand(a,b);
    }
    return generated;
}

vvi genTree(int n) {
    vvi g(n + 1);
    F0R(i,n) {
        gen(p,0,i);
        g[p].pb(i + 1);
        g[i + 1].pb(p);
    }

    return g;
}

vvb readGrid(int a, int b) {
    vvb grid(a + 2, vb(b + 2, true));

    F0R(i, a) {
        F0R(j, b) {
            bool k; cin >> k;
            grid[i + 1][j + 1] = k;
        }
    }
    return grid;
}

struct mint {
    ll v;

    mint(ll t) : v(t % MOD) {}
    mint() = default;
    mint operator*(mint other) {
        return {v * other.v};
    }
    void operator*=(mint other) {
        v *= other.v;
        v %= MOD;
    }
    mint operator+(mint other) {
        return {v + other.v};
    }
    void operator+=(mint other) {
        v += other.v;
        v %= MOD;
    }
};

V<V<mint>> prePrefix;
V<V<mint>> prePrefix2;

// TODO precompute
mint pow(mint a, int b) {
    if (b == 0) return 1;
    mint ans = pow(a, b / 2);
    ans = ans * ans;
    if (b % 2) ans *= a;
    return ans;
}

int v(char k) {
    if (k == 'O') return 0;
    if (k == 'I') return 1;
    if (k == 'J') return 2;
    exit(5);
}

struct Seg {
    Seg *left = nullptr, *right = nullptr;
    int l, r, mid;
    mint hash = 0;
    mint hash2 = 0;
    int lazy = -1;

    Seg(int l, int r, str &def) : l(l) ,r(r), mid((r + l) / 2) {
        if (r -l > 1) {
            left = new Seg(l,mid,def);
            right = new Seg(mid,r,def);
            hash = left->hash + right->hash * pow(mint(3), mid - l);
            hash2 = left->hash2 + right->hash2 * pow(mint(4), mid - l);
        } else {
            hash = v(def[l]);
            hash2 = v(def[l]);
        }
    }

    void push() {
        if (lazy != -1) {
            hash = prePrefix[lazy][r - l];
            hash2 = prePrefix2[lazy][r - l];
            if (r - l > 1) {
                left->lazy = lazy;
                right->lazy = lazy;
            }
            lazy = -1;
        }
    }

    void update(int a, int b, int k) {
        push();
        if (b <= l || a >= r) return;
        if (a <= l && b >= r) {
            lazy = k;
            push();
            return;
        }

        left->update(a,b,k);
        right->update(a,b,k);
        hash = left->hash + right->hash * pow(mint(3), mid - l);
        hash2 = left->hash2 + right->hash2 * pow(mint(4), mid - l);
    }
};


int main() {
    setIO();

    int n; cin >> n;
    string start;

    F0R(i, 3) {
        cin >> start;
    }

    int q; cin >> q;
    string def; cin >> def;
    Seg seg(0, sz(def), def);
    Seg seg2(0, sz(start), start);

    prePrefix.rsz(3, V<mint>(n + 1));
    prePrefix2.rsz(3, V<mint>(n + 1));
    F0R(i, 3) {
        mint h = 0;
        mint h2 = 0;
        mint power = 1;
        mint power2 = 1;
        F0R(j, n + 1) {
            prePrefix[i][j] = h;
            prePrefix2[i][j] = h2;
            h += power * (i);
            h2 += power2 * (i);
            power *= 3;
            power2 *= 4;
        }
    }

    cout << ((seg2.hash.v == seg.hash.v && seg2.hash2.v == seg.hash2.v) ? "Yes" : "No") << "\n";
    F0R(i, q) {
        int l, r; cin >> l >> r;
        l--;
        char c; cin >> c;

        seg.update(l, r, v(c));
        cout << ((seg2.hash.v == seg.hash.v && seg2.hash2.v == seg.hash2.v) ? "Yes" : "No") << "\n";
    }

    return 0;
}

Compilation message

Main.cpp: In function 'void setIn(str)':
Main.cpp:59:28: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   59 | void setIn(str s) { freopen(s.c_str(),"r",stdin); }
      |                     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~
Main.cpp: In function 'void setOut(str)':
Main.cpp:60:29: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   60 | void setOut(str s) { freopen(s.c_str(),"w",stdout); }
      |                      ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 64 ms 788 KB Output is correct
2 Correct 76 ms 852 KB Output is correct
3 Correct 80 ms 848 KB Output is correct
4 Correct 69 ms 988 KB Output is correct
5 Correct 70 ms 984 KB Output is correct
6 Correct 61 ms 928 KB Output is correct
7 Correct 65 ms 916 KB Output is correct
8 Correct 67 ms 884 KB Output is correct
9 Correct 68 ms 1072 KB Output is correct
10 Correct 82 ms 852 KB Output is correct
11 Correct 86 ms 1056 KB Output is correct
12 Correct 84 ms 852 KB Output is correct
13 Correct 74 ms 848 KB Output is correct
14 Correct 68 ms 848 KB Output is correct
15 Correct 68 ms 848 KB Output is correct
16 Correct 67 ms 848 KB Output is correct
17 Correct 91 ms 836 KB Output is correct
18 Correct 70 ms 1008 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 64 ms 788 KB Output is correct
2 Correct 76 ms 852 KB Output is correct
3 Correct 80 ms 848 KB Output is correct
4 Correct 69 ms 988 KB Output is correct
5 Correct 70 ms 984 KB Output is correct
6 Correct 61 ms 928 KB Output is correct
7 Correct 65 ms 916 KB Output is correct
8 Correct 67 ms 884 KB Output is correct
9 Correct 68 ms 1072 KB Output is correct
10 Correct 82 ms 852 KB Output is correct
11 Correct 86 ms 1056 KB Output is correct
12 Correct 84 ms 852 KB Output is correct
13 Correct 74 ms 848 KB Output is correct
14 Correct 68 ms 848 KB Output is correct
15 Correct 68 ms 848 KB Output is correct
16 Correct 67 ms 848 KB Output is correct
17 Correct 91 ms 836 KB Output is correct
18 Correct 70 ms 1008 KB Output is correct
19 Correct 609 ms 62312 KB Output is correct
20 Correct 702 ms 62432 KB Output is correct
21 Correct 487 ms 58616 KB Output is correct
22 Correct 433 ms 52728 KB Output is correct
23 Correct 235 ms 4192 KB Output is correct
24 Correct 244 ms 3920 KB Output is correct
25 Correct 463 ms 62316 KB Output is correct
26 Correct 440 ms 62300 KB Output is correct
27 Correct 525 ms 62396 KB Output is correct
28 Correct 502 ms 62292 KB Output is correct
29 Correct 545 ms 60560 KB Output is correct
30 Correct 250 ms 3976 KB Output is correct
31 Correct 495 ms 62440 KB Output is correct
32 Correct 475 ms 56972 KB Output is correct
33 Correct 258 ms 3940 KB Output is correct
34 Correct 486 ms 62416 KB Output is correct
35 Correct 396 ms 46756 KB Output is correct
36 Correct 237 ms 4072 KB Output is correct
37 Correct 232 ms 3920 KB Output is correct
38 Correct 523 ms 62472 KB Output is correct
39 Correct 404 ms 62312 KB Output is correct
40 Correct 325 ms 41320 KB Output is correct
41 Correct 659 ms 62572 KB Output is correct
42 Correct 58 ms 62572 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 64 ms 788 KB Output is correct
2 Correct 76 ms 852 KB Output is correct
3 Correct 80 ms 848 KB Output is correct
4 Correct 69 ms 988 KB Output is correct
5 Correct 70 ms 984 KB Output is correct
6 Correct 61 ms 928 KB Output is correct
7 Correct 65 ms 916 KB Output is correct
8 Correct 67 ms 884 KB Output is correct
9 Correct 68 ms 1072 KB Output is correct
10 Correct 82 ms 852 KB Output is correct
11 Correct 86 ms 1056 KB Output is correct
12 Correct 84 ms 852 KB Output is correct
13 Correct 74 ms 848 KB Output is correct
14 Correct 68 ms 848 KB Output is correct
15 Correct 68 ms 848 KB Output is correct
16 Correct 67 ms 848 KB Output is correct
17 Correct 91 ms 836 KB Output is correct
18 Correct 70 ms 1008 KB Output is correct
19 Correct 73 ms 800 KB Output is correct
20 Correct 82 ms 1016 KB Output is correct
21 Incorrect 68 ms 848 KB Output isn't correct
22 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 64 ms 788 KB Output is correct
2 Correct 76 ms 852 KB Output is correct
3 Correct 80 ms 848 KB Output is correct
4 Correct 69 ms 988 KB Output is correct
5 Correct 70 ms 984 KB Output is correct
6 Correct 61 ms 928 KB Output is correct
7 Correct 65 ms 916 KB Output is correct
8 Correct 67 ms 884 KB Output is correct
9 Correct 68 ms 1072 KB Output is correct
10 Correct 82 ms 852 KB Output is correct
11 Correct 86 ms 1056 KB Output is correct
12 Correct 84 ms 852 KB Output is correct
13 Correct 74 ms 848 KB Output is correct
14 Correct 68 ms 848 KB Output is correct
15 Correct 68 ms 848 KB Output is correct
16 Correct 67 ms 848 KB Output is correct
17 Correct 91 ms 836 KB Output is correct
18 Correct 70 ms 1008 KB Output is correct
19 Correct 609 ms 62312 KB Output is correct
20 Correct 702 ms 62432 KB Output is correct
21 Correct 487 ms 58616 KB Output is correct
22 Correct 433 ms 52728 KB Output is correct
23 Correct 235 ms 4192 KB Output is correct
24 Correct 244 ms 3920 KB Output is correct
25 Correct 463 ms 62316 KB Output is correct
26 Correct 440 ms 62300 KB Output is correct
27 Correct 525 ms 62396 KB Output is correct
28 Correct 502 ms 62292 KB Output is correct
29 Correct 545 ms 60560 KB Output is correct
30 Correct 250 ms 3976 KB Output is correct
31 Correct 495 ms 62440 KB Output is correct
32 Correct 475 ms 56972 KB Output is correct
33 Correct 258 ms 3940 KB Output is correct
34 Correct 486 ms 62416 KB Output is correct
35 Correct 396 ms 46756 KB Output is correct
36 Correct 237 ms 4072 KB Output is correct
37 Correct 232 ms 3920 KB Output is correct
38 Correct 523 ms 62472 KB Output is correct
39 Correct 404 ms 62312 KB Output is correct
40 Correct 325 ms 41320 KB Output is correct
41 Correct 659 ms 62572 KB Output is correct
42 Correct 58 ms 62572 KB Output is correct
43 Correct 73 ms 800 KB Output is correct
44 Correct 82 ms 1016 KB Output is correct
45 Incorrect 68 ms 848 KB Output isn't correct
46 Halted 0 ms 0 KB -