Submission #624970

#TimeUsernameProblemLanguageResultExecution timeMemory
624970Mohammed_AtalahWall (IOI14_wall)C++17
0 / 100
1286 ms85716 KiB
#include "wall.h" #include <bits/stdc++.h> using namespace std; void buildWall(int n, int k, int op[], int left[], int right[], int height[], int finalHeight[]) { int o = k; vector<vector<int>> v; int e = 0; for (int i = 0; i < k ; i++) { if (op[i] == 2) { o = i; break; } e += 2; v.push_back({left[i], height[i], 1}); v.push_back({right[i] + 1, height[i], -1}); } sort(v.begin(), v.end()); set<int> s; map<int, int> mp; vector<int> v1(n); for (int i = 0; i < e; i++) { if (v[i][0] >= n) { break; } if (v[i][2] == -1) { mp[v[i][1]]--; if (mp[v[i][1]] == 0) { s.erase(s.lower_bound(v[i][1])); if (s.size() == 0) { v1[v[i][0]] = -1; } else { auto it = s.end(); it--; v1[v[i][0]] = *it; } } } else { mp[v[i][1]]++; if (mp[v[i][1]] == 1) { s.insert(v[i][1]); } auto it = s.end(); it--; v1[v[i][0]] = *it; } } for (int i = 1; i < n; i++) { if (v1[i] == 0) { v1[i] = v1[i - 1]; } else if (v1[i] == -1) { v1[i] = 0; } } vector<vector<int>> vv; e = 0; for (int i = o; i < k ; i++) { e += 2; vv.push_back({left[i], height[i], 1}); vv.push_back({right[i] + 1, height[i], -1}); } sort(vv.begin(), vv.end()); set<int> ss; map<int, int> mpp; vector<int> v2(n); v2[0] = -1; for (int i = 0; i < e; i++) { if (vv[i][0] >= n) { break; } if (vv[i][2] == -1) { mpp[vv[i][1]]--; if (mpp[vv[i][1]] == 0) { ss.erase(ss.lower_bound(vv[i][1])); if (ss.size() == 0) { v2[vv[i][0]] = -1; } else { v2[vv[i][0]] = *ss.begin(); } } } else { mpp[vv[i][1]]++; if (mpp[vv[i][1]] == 1) { ss.insert(vv[i][1]); } v2[vv[i][0]] = *ss.begin(); } } for (int i = 1; i < n; i++) { if (v2[i] == 0) { v2[i] = v2[i - 1]; } } for (int i = 0; i < n; i++) { if (v2[i] != -1) { finalHeight[i] = min(v1[i], v2[i]); } else { finalHeight[i] = v1[i]; } } return; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...