Submission #171162

# Submission time Handle Problem Language Result Execution time Memory
171162 2019-12-27T14:37:37 Z dolphingarlic Synchronization (JOI13_synchronization) C++14
0 / 100
209 ms 16172 KB
#include <bits/stdc++.h>
#define FOR(i, x, y) for (int i = x; i < y; i++)
typedef long long ll;
using namespace std;

struct Node {
    int range_l, range_r, info_l, info_r;

    Node operator+(Node b) {
        return {min(range_l, b.range_l), max(range_r, b.range_r), min(info_l, b.info_l), max(info_r, b.info_r)};
    }
};

int n, m, q;
bool active[100001];
vector<int> graph[100001];
Node segtree[400001], lazy[400001];

void push_lazy(int node, int l, int r) {
    if (l == r) segtree[node] = lazy[node];
    else lazy[node * 2] = lazy[node * 2 + 1] = lazy[node];
}

void build(int node = 1, int l = 1, int r = n) {
    if (l == r) segtree[node] = {l, l, l, l};
    int mid = (l + r) / 2;
    build(node * 2, l, mid);
    build(node * 2 + 1, mid + 1, r);
}

void update(Node newval, int node = 1, int l = 1, int r = n) {
    push_lazy(node, l, r);
    if (l > newval.range_r || r < newval.range_l) return;
    if (l >= newval.range_l && r <= newval.range_r) lazy[node] = newval;
    else {
        int mid = (l + r) / 2;
        update(newval, node * 2, l, mid);
        update(newval, node * 2 + 1, mid + 1, r);
    }
}

Node query(int pos, int node = 1, int l = 1, int r = n) {
    push_lazy(node, l, r);
    if (l == r) return segtree[node];
    int mid = (l + r) / 2;
    if (pos > mid) return query(pos, node * 2 + 1, mid + 1, r);
    return query(pos, node * 2, l, mid);
}

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cin >> n >> m >> q;
    FOR(i, 1, n) {
        int a, b;
        cin >> a >> b;
        graph[a].push_back(b);
        graph[b].push_back(a);
    }

    if (q == 1) {

    } else {
        while (m--) {
            int x;
            cin >> x;
            if (active[x]) {
                Node curr = query(x);
                Node l = curr, r = curr;
                l.range_r = x;
                r.range_l = x + 1;
                update(l);
                update(r);
            } else {
                Node newval = query(x) + query(x + 1);
                update(newval);
            }
        }

        while (q--) {
            int x;
            cin >> x;
            Node ans = query(x);
            cout << ans.info_r - ans.info_l + 1 << '\n';
        }
    }
    return 0;
}
# Verdict Execution time Memory Grader output
1 Incorrect 4 ms 2808 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 35 ms 7504 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 2812 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 209 ms 16172 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 2808 KB Output isn't correct
2 Halted 0 ms 0 KB -