Submission #104897

#TimeUsernameProblemLanguageResultExecution timeMemory
104897WLZCake (CEOI14_cake)C++17
0 / 100
2097 ms9968 KiB
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(0); int n, a; cin >> n >> a; vector< pair<int, int> > d(n); for (int i = 0; i < n; i++) { cin >> d[i].first; d[i].second = i + 1; } sort(d.rbegin(), d.rend()); vector<int> top10; vector<int> v; for (int i = 0; i < min(10, n); i++) { top10.push_back(d[i].second); } for (int i = n; i >= 10; i--) { v.push_back(d[i].second); } int q; cin >> q; while (q--) { char t; cin >> t; if (t == 'F') { int b; cin >> b; int cur = n; vector<int> num(n + 1, -1); for (auto& x : top10) { if (num[x] == -1) { num[x] = cur--; } } for (int i = (int) v.size() - 1; i >= 0; i--) { if (num[v[i]] == -1) { num[v[i]] = cur--; } } priority_queue< pair<int, int>, vector< pair<int, int> >, greater< pair<int, int> > > pq; pq.push({num[a], a}); int cnt = 0; while (!pq.empty()) { int x = pq.top().second; pq.pop(); num[x] = -1; if (x == b) { cout << cnt << '\n'; } cnt++; if (x > 1 && num[x - 1] != -1) { pq.push({num[x - 1], x - 1}); } if (x < n && num[x + 1] != -1) { pq.push({num[x + 1], x + 1}); } } } else { int i, e; cin >> i >> e; auto it = top10.begin(); for (int j = 0; j < e - 1; j++) { it = next(it); } top10.insert(it, i); v.push_back(top10.back()); top10.pop_back(); } } 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...