# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
537312 | LucaDantas | 케이크 (CEOI14_cake) | C++17 | 937 ms | 22732 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
constexpr int maxn = 2e6+10, logn = 22;
int a[maxn];
struct Query { int x, e; } qr[maxn];
set<pair<int,int>> st;
int main() {
int n, start; scanf("%d %d", &n, &start);
for(int i = 1; i <= n; i++)
scanf("%d", a+i), st.insert({a[i], i});
int q; scanf("%d", &q);
for(int i = 1; i <= q; i++) {
char c; scanf(" %c", &c);
if(c == 'E') {
scanf("%d %d", &qr[i].x, &qr[i].e);
} else {
int x; scanf("%d", &x);
qr[i] = {x, -1};
}
}
vector<int> l, r; // salvo os dois paretos
for(int i = start+1; i <= n; i++)
if(!r.size() || a[i] > a[r.back()])
r.push_back(i);
r.push_back(n+1); a[n+1] = 0x3f3f3f3f;
for(int i = start-1; i >= 1; i--)
if(!l.size() || a[i] > a[l.back()])
l.push_back(i);
l.push_back(0); a[0] = 0x3f3f3f3f;
for(int i = 1; i <= q; i++) {
if(qr[i].e == -1) {
// query
int x = qr[i].x;
if(x == start) puts("0");
else if(x > start) {
auto mx = *(--upper_bound(r.begin(), r.end(), x));
int L = 0, R = (int)(l.size())-1, ans = 1;
while(L <= R) {
int M = (L+R) >> 1;
if(a[l[M]] > a[mx])
ans = l[M]+1, R = M-1;
else
L = M+1;
}
printf("%d\n", x - ans); // não inclui x
} else {
auto mx = *lower_bound(l.rbegin(), l.rend(), x);
int L = 0, R = (int)(r.size())-1, ans = n;
while(L <= R) {
int M = (L+R) >> 1;
if(a[r[M]] > a[mx])
ans = r[M]-1, R = M-1;
else
L = M+1;
}
printf("%d\n", ans - x); // não inclui x
}
} else {
// upd
auto [x, e] = qr[i];
st.erase({a[x], x});
vector<pair<int,int>> add;
if(e == 1) a[x] = st.rbegin()->first+1;
else for(int k = 1; k < e; k++) {
auto p = *st.rbegin();
st.erase(p);
a[x] = p.first;
p.first++;
a[p.second]++;
add.push_back(p);
}
for(auto p : add)
st.insert(p);
st.insert({a[x], x});
if(x < start) swap(l, r);
vector<int> sv = {x};
while(r.size() && (x > start ? r.back() > x : r.back() < x))
sv.push_back(r.back()), r.pop_back();
for(int x : sv)
if(!r.size() || a[x] > a[r.back()])
r.push_back(x);
if(x < start) swap(l, r);
}
}
}
컴파일 시 표준 에러 (stderr) 메시지
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |