Submission #391838

#TimeUsernameProblemLanguageResultExecution timeMemory
391838wiwihoCake (CEOI14_cake)C++14
30 / 100
2093 ms14152 KiB
#include <bits/stdc++.h> #define eb emplace_back #define mp make_pair #define F first #define S second #define printv(a, b) {\ for(auto pv : a) b << pv << " ";\ b << "\n";\ } using namespace std; using pii = pair<int, int>; ostream& operator<<(ostream& o, pii p){ return o << '(' << p.F << ',' << p.S << ')'; } int main(){ ios_base::sync_with_stdio(false); cin.tie(0); int n, a; cin >> n >> a; vector<int> d(n + 1); map<int, int, greater<>> rk; for(int i = 1; i <= n; i++){ cin >> d[i]; rk[d[i]] = i; } //printv(d, cerr); //printv(rk, cerr); vector<int> pos(n + 1); int q; cin >> q; while(q--){ char c; cin >> c; if(c == 'F'){ int b; cin >> b; int l = a, r = a; pos[a] = 1; for(int i = 2; i <= n; i++){ if(r == n){ l--; pos[l] = i; //cerr << l << " " << i << "\n"; } else if(l == 1){ r++; pos[r] = i; //cerr << r << " " << i << "\n"; } else if(d[l - 1] < d[r + 1]){ l--; pos[l] = i; //cerr << l << " " << i << "\n"; } else{ r++; pos[r] = i; //cerr << r << " " << i << "\n"; } } cout << pos[b] - 1 << "\n"; continue; } int b, e; cin >> b >> e; vector<int> tmp; for(int i = 0; i < e - 1; i++){ tmp.eb(rk.begin()->S); rk.erase(rk.begin()); } tmp.eb(b); rk.erase(d[b]); while(!tmp.empty()){ int now = tmp.back(); tmp.pop_back(); d[now] = rk.empty() ? 1 : rk.begin()->F + 1; rk[d[now]] = now; } } 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...