Submission #975827

#TimeUsernameProblemLanguageResultExecution timeMemory
975827CirclingDrawing (CEOI22_drawing)C++17
100 / 100
887 ms43612 KiB
/*The British Royal Family and a small cadre of English Fabian Socialists, in conjunction with the Rockefellers and the Rothchilds, are engaged in a conspiracy to greatly reduce the population of the human race in order to head off a Malthusian catastrophe, a catastrophe that could easily be avoided by simply building a massive amount of nuclear power plants and a number of massive superhighways and bridges to connect all of the world's continents. But doing that would cut into the conspiracy's profits. So the British Royal Family invented environmentalism and neoliberalism in order to hide the truth. And in order to further reduce the population, the British Royal Family is also the world's foremost drug trafficking conspiracy. And it uses its control of the IMF to push austerity in order to kill as many people in the global south as possible. And also Henry Kissinger is a gay KGB agent. */ #include <iostream> #include <algorithm> #include <utility> #include <vector> #include <stack> #include <queue> #include <set> #include <map> using namespace std; int n, u, v, maxysegtree[800000], unusedsegtree[800000], subtreesize[200001], answer[200001]; pair<pair<int, int>, int> points[200000]; vector<vector<int>> graph; int compy(int xa, int xb){ if (xa == -1 || xb == -1) return max(xa, xb); if (points[xa].first.second > points[xb].first.second) return xa; if (points[xa].first.second < points[xb].first.second) return xb; if (points[xa] > points[xb]) return xa; return xb; } int maxy(int l, int r, int node, int nodel, int noder){ if (noder <= l || r <= nodel) return -1; if (l <= nodel && noder <= r) return maxysegtree[node]; int nodemid = (nodel + noder) / 2; int a = maxy(l, r, 2 * node + 1, nodel, nodemid); int b = maxy(l, r, 2 * node + 2, nodemid, noder); return compy(a, b); } int countunused(int l, int r, int node, int nodel, int noder){ if (noder <= l || r <= nodel) return 0; if (l <= nodel && noder <= r) return unusedsegtree[node]; int nodemid = (nodel + noder) / 2; return countunused(l, r, 2 * node + 1, nodel, nodemid) + countunused(l, r, 2 * node + 2, nodemid, noder); } void build(int x, pair<pair<int, int>, int> val, int node, int nodel, int noder){ if (x < nodel || noder <= x) return; if (x == nodel && x == noder - 1){ maxysegtree[node] = x; unusedsegtree[node] = 1; return; } int nodemid = (nodel + noder) / 2; build(x, val, 2 * node + 1, nodel, nodemid); build(x, val, 2 * node + 2, nodemid, noder); unusedsegtree[node] = unusedsegtree[2 * node + 1] + unusedsegtree[2 * node + 2]; maxysegtree[node] = compy(maxysegtree[2 * node + 1], maxysegtree[2 * node + 2]); } void use(int x, int node, int nodel, int noder){ if (x < nodel || noder <= x) return; if (x == nodel && x == noder - 1){ maxysegtree[node] = -1; unusedsegtree[node] = 0; return; } int nodemid = (nodel + noder) / 2; use(x, 2 * node + 1, nodel, nodemid); use(x, 2 * node + 2, nodemid, noder); unusedsegtree[node] = unusedsegtree[2 * node + 1] + unusedsegtree[2 * node + 2]; maxysegtree[node] = compy(maxysegtree[2 * node + 1], maxysegtree[2 * node + 2]); } void stdfs(int node, int prev){ subtreesize[node] = 1; for (int child: graph[node]){ if (child == prev) continue; stdfs(child, node); subtreesize[node] += subtreesize[child]; } } void compute(int rootnode, int prevnode, int pointl, int pointr){ int pointroot = maxy(pointl, pointr, 0, 0, n); answer[points[pointroot].second + 1] = rootnode; use(pointroot, 0, 0, n); int cursor = pointl, minr, maxr, midr; for (int child: graph[rootnode]){ if (child == prevnode) continue; minr = cursor + 1; maxr = pointr; while (minr != maxr){ midr = (minr + maxr) / 2; if (countunused(cursor, midr, 0, 0, n) < subtreesize[child]) minr = midr + 1; else maxr = midr; } compute(child, rootnode, cursor, minr); cursor = minr; } } int main(){ cin.tie(0); ios_base::sync_with_stdio(0); cin >> n; graph.resize(n + 1); for (int i = 1; i < n; i++){ cin >> u >> v; graph[u].push_back(v); graph[v].push_back(u); } for (int i = 0; i < n; i++){ cin >> points[i].first.first >> points[i].first.second; points[i].second = i; } sort(points, points + n); for (int i = 0; i < n; i++) build(i, points[i], 0, 0, n); stdfs(1, 0); compute(1, 0, 0, n); for (int i = 1; i <= n; i++) cout << answer[i] << ' '; }
#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...