제출 #950417

#제출 시각아이디문제언어결과실행 시간메모리
950417arbuzickCell Automaton (JOI23_cell)C++17
24 / 100
8086 ms2097152 KiB
#include <bits/stdc++.h>
#define int long long

using namespace std;

void solve() {
    int n, q;
    cin >> n >> q;
    vector<pair<int, int>> xy(n);
    bool check = true;
    for (int i = 0; i < n; ++i) {
        cin >> xy[i].first >> xy[i].second;
        if (xy[i].first != xy[i].second) {
            check = false;
        }
    }
    vector<int> t(q);
    for (int i = 0; i < q; ++i) {
        cin >> t[i];
    }
    if (!check) {
        vector<int> ans(t[q - 1] + 1);
        ans[0] = xy.size();
        set<pair<int, int>> black, gray;
        for (int i = 0; i < n; ++i) {
            black.insert(xy[i]);
        }
        for (int i = 1; i <= t[q - 1]; ++i) {
            set<pair<int, int>> black_nw;
            for (auto [x, y] : black) {
                if (!black.count({x + 1, y}) && !gray.count({x + 1, y})) {
                    black_nw.emplace(x + 1, y);
                }
                if (!black.count({x - 1, y}) && !gray.count({x - 1, y})) {
                    black_nw.emplace(x - 1, y);
                }
                if (!black.count({x, y + 1}) && !gray.count({x, y + 1})) {
                    black_nw.emplace(x, y + 1);
                }
                if (!black.count({x, y - 1}) && !gray.count({x, y - 1})) {
                    black_nw.emplace(x, y - 1);
                }
            }
            gray = black;
            black = black_nw;
            ans[i] = black.size();
        }
        for (int i = 0; i < q; ++i) {
            cout << ans[t[i]] << '\n';
        }
    } else {
        sort(xy.begin(), xy.end());
        vector<pair<int, int>> tms;
        for (int i = 0; i < q; ++i) {
            tms.emplace_back(t[i], n);
        }
        for (int i = 0; i + 1 < n; ++i) {
            tms.emplace_back(xy[i + 1].first - xy[i].first, i);
            tms.emplace_back(xy[i + 1].first - xy[i].first + 1, i);
        }
        sort(tms.begin(), tms.end());
        map<int, long long> ans;
        set<pair<int, int>> segms;
        for (int i = 0; i < n; ++i) {
            segms.emplace(i, i + 1);
        }
        int cntp = 0;
        for (auto [t, ind] : tms) {
            if (ind < n) {
                if (t == xy[ind + 1].first - xy[ind].first) {
                    auto it = segms.lower_bound(make_pair(ind + 1, -1));
                    int r = it->second;
                    it--;
                    int l = it->first;
                    segms.erase(segms.lower_bound(make_pair(l, -1)));
                    segms.erase(segms.lower_bound(make_pair(ind + 1, -1)));
                    segms.emplace(l, r);
                    cntp++;
                } else {
                    cntp--;
                }
            } else {
                if (t == 0) {
                    ans[t] = n;
                } else {
                    for (auto [l, r] : segms) {
                        ans[t] += (xy[r - 1].first - xy[l].first + 1 + t) * 1LL * 2 + (t - 1) * 1LL * 2;
                    }
                    ans[t] += cntp * 1LL * (t - 1);
                }
            }
        }
        for (int i = 0; i < q; ++i) {
            cout << ans[t[i]] << '\n';
        }
    }
}

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int t = 1;
    // cin >> t;
    while (t--) {
        solve();
    }
    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...