답안 #304563

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
304563 2020-09-21T14:08:11 Z HynDuf 케이크 (CEOI14_cake) C++11
73.3333 / 100
1241 ms 2424 KB
#include <bits/stdc++.h>

#define task "C"
#define all(v) (v).begin(), (v).end()
#define rep(i, l, r) for (int i = (l); i <= (r); ++i)
#define Rep(i, r, l) for (int i = (r); i >= (l); --i)
#define DB(X) { cerr << #X << " = " << (X) << '\n'; }
#define DB1(A, _) { cerr << #A << "[" << _ << "] = " << (A[_]) << '\n'; }
#define DB2(A, _, __) { cerr << #A << "[" << _ << "][" << __ << "] = " << (A[_][__]) << '\n'; }
#define DB3(A, _, __, ___) { cerr << #A << "[" << _ << "][" << __ << "][" << ___ << "] = " << (A[_][__][___]) << '\n'; }
#define PR(A, l, r) { cerr << '\n'; rep(_, l, r) DB1(A, _); cerr << '\n';}
#define SZ(x) ((int)(x).size())
#define pb push_back
#define eb emplace_back
#define pf push_front
#define F first
#define S second
#define by(x) [](const auto& a, const auto& b) { return a.x < b.x; } // sort(arr, arr + N, by(a));
#define next ___next
#define prev ___prev
#define y1 ___y1
#define left ___left
#define right ___right
#define y0 ___y0
#define div ___div
#define j0 ___j0
#define jn ___jn

using ll = long long;
using ld = long double;
using ull = unsigned long long;
using namespace std;
typedef pair<int, int> ii;
typedef pair<ii, int> iii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<ll> vl;
const int N = 1e5 + 2;
int n, A, q, a[N];
set<ii> mxa;
int it[4 * N];
void build(int id, int l, int r)
{
    if (l == r)
    {
        it[id] = a[l];
        return;
    }
    int m = (l + r) >> 1;
    build(id << 1, l, m);
    build((id << 1) | 1, m + 1, r);
    it[id] = max(it[id << 1], it[(id << 1) | 1]);
}
void update(int id, int l, int r, int p)
{
    if (l > p || r < p) return;
    if (l == r)
    {
        it[id] = a[p];
        return;
    }
    int m = (l + r) >> 1;
    update(id << 1, l, m, p);
    update((id << 1) | 1, m + 1, r, p);
    it[id] = max(it[id << 1], it[(id << 1) | 1]);
}
int query(int id, int l, int r, int L, int R)
{
    if (l > R || r < L) return -1e9;
    if (L <= l && r <= R) return it[id];
    int m = (l + r) >> 1;
    return max(query(id << 1, l, m, L, R), query((id << 1) | 1, m + 1, r, L, R));
}
int main()
{
#ifdef HynDuf
    freopen(task".in", "r", stdin);
    //freopen(task".out", "w", stdout);
#else
    ios_base::sync_with_stdio(false); cin.tie(nullptr);
#endif
    cin >> n >> A;
    rep(i, 1, n)
    {
        cin >> a[i];
        mxa.insert({a[i], i});
        if (SZ(mxa) > 11) mxa.erase(mxa.begin());
    }
    build(1, 1, n);
    cin >> q;
    while (q--)
    {
        char t;
        int x;
        cin >> t >> x;
        if (t == 'E')
        {
            int r;
            cin >> r;
            vii change;
            rep(i, 1, r - 1)
            {
                assert(!mxa.empty());
                auto it = mxa.end(); it--;
                if (it->S != x)
                {
                    change.pb({it->F + 1, it->S});
                    a[it->S]++;
                    update(1, 1, n, it->S);
                } else i--;
                mxa.erase(it);
            }
            auto it = mxa.lower_bound({a[x], 0});
            if (it != mxa.end() && it->F == a[x]) mxa.erase(it);
            if (change.empty())
            {
                if (mxa.empty()) a[x] = N;
                else a[x] = mxa.rbegin()->F + 1;
            } else a[x] = change.back().F - 1;
            change.pb({a[x], x});
            update(1, 1, n, x);

            for (ii v : change) mxa.insert(v);
            if (SZ(mxa) > 11) mxa.erase(mxa.begin());

        } else if (x > A)
        {
            int mx = query(1, 1, n, A + 1, x);
            int l = 1, r = A - 1;
            while (l <= r)
            {
                int m = (l + r) >> 1;
                if (query(1, 1, n, m, A - 1) > mx) l = m + 1;
                else r = m - 1;
            }
            cout << x - l << '\n';
        } else if (x < A)
        {
            int mx = query(1, 1, n, x, A - 1);
            int l = A + 1, r = n;
            while (l <= r)
            {
                int m = (l + r) >> 1;
                if (query(1, 1, n, A + 1, m) > mx) r = m - 1;
                else l = m + 1;
            }
            cout << r - x << '\n';
        } else cout << "0\n";
    }
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 8 ms 384 KB Output is correct
5 Correct 24 ms 512 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 656 ms 552 KB Output is correct
2 Correct 384 ms 512 KB Output is correct
3 Correct 437 ms 512 KB Output is correct
4 Correct 233 ms 512 KB Output is correct
5 Correct 719 ms 760 KB Output is correct
6 Correct 591 ms 760 KB Output is correct
7 Correct 479 ms 640 KB Output is correct
8 Correct 239 ms 640 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 554 ms 2424 KB Output is correct
2 Correct 383 ms 2168 KB Output is correct
3 Correct 404 ms 2168 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Runtime error 18 ms 1272 KB Execution killed with signal 11 (could be triggered by violating memory limits)
6 Runtime error 21 ms 1280 KB Execution killed with signal 11 (could be triggered by violating memory limits)
7 Runtime error 21 ms 1280 KB Execution killed with signal 11 (could be triggered by violating memory limits)
# 결과 실행 시간 메모리 Grader output
1 Correct 116 ms 504 KB Output is correct
2 Correct 93 ms 512 KB Output is correct
3 Correct 248 ms 1272 KB Output is correct
4 Correct 231 ms 1400 KB Output is correct
5 Correct 249 ms 760 KB Output is correct
6 Correct 450 ms 1568 KB Output is correct
7 Correct 347 ms 1052 KB Output is correct
8 Correct 242 ms 1792 KB Output is correct
9 Incorrect 98 ms 1784 KB Output isn't correct
10 Correct 842 ms 1528 KB Output is correct
11 Correct 1241 ms 2328 KB Output is correct
12 Incorrect 442 ms 2424 KB Output isn't correct
13 Runtime error 18 ms 1280 KB Execution killed with signal 11 (could be triggered by violating memory limits)