Submission #763131

# Submission time Handle Problem Language Result Execution time Memory
763131 2023-06-22T04:45:35 Z t6twotwo Werewolf (IOI18_werewolf) C++17
Compilation error
0 ms 0 KB
#include "seats.h"
#include <bits/stdc++.h>
using namespace std;
constexpr int inf = 6 << 22;
int N, M, ans, T;
vector<int> A, B, xmax, xmin, ymax, ymin;
int f(int k) {
    return (xmax[k] - xmin[k] + 1) * (ymax[k] - ymin[k] + 1) == k;
}
struct node {
    int xmin, xmax, ymin, ymax;
    node() {
        xmin = ymin = inf;
        xmax = ymax = -inf;
    }
    node(int a, int b, int c, int d) {
        xmin = a;
        xmax = b;
        ymin = c;
        ymax = d;
    }
};
node operator+(node a, node b) {
    node c;
    c.xmin = min(a.xmin, b.xmin);
    c.xmax = max(a.xmax, b.xmax);
    c.ymin = min(a.ymin, b.ymin);
    c.ymax = max(a.ymax, b.ymax);
    return c;
}
vector<node> st;
void give_initial_chart(int H, int W, std::vector<int> R, std::vector<int> C) {
    N = H, M = W;
    A = R, B = C;
    xmax.resize(N * M + 1, -1);
    xmin.resize(N * M + 1, N);
    ymax.resize(N * M + 1, -1);
    ymin.resize(N * M + 1, M);
    for (int i = 0; i < N * M; i++) {
        xmax[i + 1] = max(xmax[i], A[i]);
        xmin[i + 1] = min(xmin[i], A[i]);
        ymax[i + 1] = max(ymax[i], B[i]);
        ymin[i + 1] = min(ymin[i], B[i]);
        ans += f(i + 1);
    }
    T = 2 << __lg(N * M);
    st.resize(T * 2 - 1);
    for (int i = 0; i < N * M; i++) {
        st[T - 1 + i] = {A[i], A[i], B[i], B[i]};
    }
    for (int i = T - 2; i >= 0; i--) {
        st[i] = st[i * 2 + 1] + st[i * 2 + 2];
    }
}
void modify(int p, int l, int r, int x, node v) {
    if (r - l == 1) {
        st[p] = v;
        return;
    }
    int m = (l + r + 1) / 2;
    if (x < m) {
        modify(p * 2 + 1, l, m, x, v);
    } else {
        modify(p * 2 + 2, m, r, x, v);
    }
    st[p] = st[p * 2 + 1] + st[p * 2 + 2];
}
node query(int p, int l, int r, int L, int R) {
    if (R <= l || r <= L) {
        return node();
    }
    if (L <= l && r <= R) {
        return st[p];
    }
    int m = (l + r + 1) / 2;
    return query(p * 2 + 1, l, m, L, R) + query(p * 2 + 2, m, r, L, R);
}
int swap_seats(int a, int b) {
    swap(A[a], A[b]);
    swap(B[a], B[b]);
    if (abs(a - b) <= 100000) {
        for (int i = min(a, b); i <= max(a, b); i++) {
            ans -= f(i + 1);
            xmax[i + 1] = max(xmax[i], A[i]);
            xmin[i + 1] = min(xmin[i], A[i]);
            ymax[i + 1] = max(ymax[i], B[i]);
            ymin[i + 1] = min(ymin[i], B[i]);
            ans += f(i + 1);
        }
        return ans;
    }
    int ans = 1;
    modify(0, 0, T, a, {A[a], A[a], B[a], B[a]});
    modify(0, 0, T, b, {A[b], A[b], B[b], B[b]});
    int s = 0, L = B[0], R = B[0], U = A[0], D = A[0];
    while (L != 0 || R != M - 1 || U != 0 || D != N - 1) {
        int lo = s + 1, hi = N * M - 1;
        while (lo < hi) {
            int mi = (lo + hi) / 2;
            node t = query(0, 0, T, s + 1, mi + 1);
            if (t.xmin < U || t.xmax > D || t.ymin < L || t.ymax > R) {
                hi = mi;
            } else {
                lo = mi + 1;
            }
        }
        if ((D - U + 1) * (R - L + 1) == lo) {
            ans++;
        }
        U = min(U, A[lo]);
        D = max(D, A[lo]);
        L = min(L, B[lo]);
        R = max(R, B[lo]);
        s = lo;
    }
    return ans;
}

Compilation message

werewolf.cpp:1:10: fatal error: seats.h: No such file or directory
    1 | #include "seats.h"
      |          ^~~~~~~~~
compilation terminated.