Submission #1059767

#TimeUsernameProblemLanguageResultExecution timeMemory
1059767becaidoRadio Towers (IOI22_towers)C++17
17 / 100
811 ms12020 KiB
#pragma GCC optimize("O3,unroll-loops") #pragma GCC target("avx,popcnt,sse4,abm") #include <bits/stdc++.h> using namespace std; #ifndef WAIMAI #include "towers.h" #else #include "stub.cpp" #endif #ifdef WAIMAI #define debug(HEHE...) cout << "[" << #HEHE << "] : ", dout(HEHE) void dout() {cout << '\n';} template<typename T, typename...U> void dout(T t, U...u) {cout << t << (sizeof...(u) ? ", " : ""), dout(u...);} #else #define debug(...) 7122 #endif #define ll long long #define Waimai ios::sync_with_stdio(false), cin.tie(0) #define FOR(x,a,b) for (int x = a, I = b; x <= I; x++) #define pb emplace_back #define F first #define S second const int INF = 2e9 + 1; const int SIZE = 1e5 + 5; int n; int a[SIZE], ty[SIZE]; vector<pair<int, int>> ans; void init(int N, vector<int> H) { n = N; if (n == 1) return; FOR (i, 1, n) a[i] = H[i - 1]; FOR (i, 1, n) { if ((i == 1 || a[i] < a[i - 1]) && (i == n || a[i] < a[i + 1])) ty[i] = 1; if ((i == 1 || a[i] > a[i - 1]) && (i == n || a[i] > a[i + 1])) ty[i] = 2; } set<int> s; multiset<pair<int, int>> ms; for (int i = 1, x = 1; i <= n; i++) if (ty[i] == x) { s.insert(i); x ^= 3; } if (ty[*s.rbegin()] == 2) s.erase(*s.rbegin()); a[0] = a[n + 1] = INF; s.insert(0), s.insert(n + 1); ans.pb(0, s.size() / 2); bool f = 0; for (auto it = s.begin(); it != s.end(); it++) { f ^= 1; if (f == 0) continue; int i = *it; if (it != s.begin()) { int l = *prev(it); ms.emplace(a[i] - a[l], i); } if (next(it) != s.end()) { int r = *next(it); ms.emplace(a[i] - a[r], i); } } while (s.size() > 3) { int d = ms.begin()->F; while (ms.size() && ms.begin()->F == d) { auto [_, i] = *ms.begin(); auto it = s.lower_bound(i), lit = prev(it), rit = next(it); int l = *lit, r = *rit; int il = *prev(lit), ir = *next(rit); if (a[l] > a[r]) { ms.erase(ms.find({a[i] - a[l], i})); ms.erase(ms.find({a[il] - a[l], il})); if (a[i] < a[il]) { ms.erase({a[i] - a[r], i}); ms.emplace(a[il] - a[r], il); s.erase(i); } else { int j = *prev(s.find(il)); ms.erase(ms.find({a[il] - a[j], il})); ms.emplace(a[i] - a[j], i); s.erase(il); } s.erase(l); } else { ms.erase(ms.find({a[i] - a[r], i})); ms.erase(ms.find({a[ir] - a[r], ir})); if (a[i] < a[ir]) { ms.erase({a[i] - a[l], i}); ms.emplace(a[ir] - a[l], ir); s.erase(i); } else { int j = *next(s.find(ir)); ms.erase(ms.find({a[ir] - a[j], ir})); ms.emplace(a[i] - a[j], i); s.erase(ir); } s.erase(r); } } ans.pb(d + 1, s.size() / 2); } } int max_towers(int L, int R, int D) { L++, R++; if (L == R) return 1; int i = lower_bound(ans.begin(), ans.end(), make_pair(D + 1, 0)) - ans.begin() - 1; return ans[i].S; } /* in1 7 3 10 20 60 40 50 30 70 1 5 10 2 2 100 0 6 17 out1 3 1 2 */
#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...