Submission #1007008

#TimeUsernameProblemLanguageResultExecution timeMemory
1007008Ausp3x벽 (IOI14_wall)C++17
0 / 100
78 ms8020 KiB
// 人外有人,天外有天 // author: Ausp3x #include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> typedef long long lng; typedef unsigned int uint; typedef unsigned long long ulng; using namespace std; using namespace __gnu_pbds; int const INF32 = 0x3f3f3f3f; lng const INF64 = 0x3f3f3f3f3f3f3f3f; int nextPowOf2(int n) { n--; n |= n >> 1; n |= n >> 2; n |= n >> 4; n |= n >> 8; n |= n >> 16; n++; return n; } int n2; vector<pair<int, int>> segt; void update(int op, int l, int r, int turn, int h) { l += n2; r += n2; if (op == 1) while (l <= r) { if (l & 1) { if (segt[l].first == -1 || segt[l].second < h) segt[l] = {turn, h}; l++; } if (!(r & 1)) { if (segt[r].first == -1 || segt[r].second < h) segt[r] = {turn, h}; r--; } l >>= 1; r >>= 1; } else if (op == 2) { while (l <= r) { if (l & 1) { if (segt[l].first == -1 || segt[l].second > h) segt[l] = {turn, h}; l++; } if (!(r & 1)) { if (segt[r].first == -1 || segt[r].second > h) segt[r] = {turn, h}; r--; } l >>= 1; r >>= 1; } } return; } lng query(int op[], int i) { i += n2; vector<pair<int, int>> pending_updates; while (i > 0) { if (segt[i].first != -1) pending_updates.push_back(segt[i]); i >>= 1; } sort(pending_updates.begin(), pending_updates.end()); int res = 0; for (auto [turn, h] : pending_updates) if (op[turn] == 1 && res < h) res = h; else if (op[turn] == 2 && res > h) res = h; return res; } void buildWall(int n, int k, int op[], int left[], int right[], int height[], int finalHeight[]) { n2 = nextPowOf2(n); segt.clear(); segt.resize(2 * n2, {-1, 0}); for (int i = 0; i < k; i++) { update(op[i], left[i], right[i], i, height[i]); } for (int i = 0; i < n; i++) finalHeight[i] = query(op, i); // for (int i = 0; i < n; i++) // cout << finalHeight[i] << ' '; // cout << endl; return; } /* int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int t = 1; cin >> t; while (t--) { int n, k; cin >> n >> k; int op[k], left[k], right[k], height[k], finalHeight[n]; for (int i = 0; i < k; i++) cin >> op[i] >> left[i] >> right[i] >> height[i]; buildWall(n, k, op, left, right, height, finalHeight); } 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...