답안 #708724

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
708724 2023-03-12T08:44:45 Z becaido Abracadabra (CEOI22_abracadabra) C++17
10 / 100
1046 ms 524288 KB
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx,popcnt,sse4,abm")
#include <bits/stdc++.h>
using namespace std;

#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 SIZE = 2e5 + 5;
const int QSIZ = 1e6 + 5;

int n, q;
int a[SIZE], b[SIZE], ans[QSIZ];
tuple<int, int, int> ask[QSIZ];
vector<int> v[SIZE];

int bit[SIZE];
void upd(int pos, int x) {
    for (; pos <= n; pos += pos & -pos) bit[pos] += x;
}
int que(int pos) {
    int re = 0;
    for (; pos; pos -= pos & -pos) re += bit[pos];
    return re;
}
int sch(int x) {
    int pos = 0, sum = 0;
    for (int i = __lg(n); i >= 0; i--) if (pos + (1 << i) <= n && sum + bit[pos + (1 << i)] <= x) {
        sum += bit[pos += 1 << i];
    }
    return pos + 1;
}

bool work() {
    int k = sch(n / 2), sum = que(k - 1);
    if (sum == n / 2) return 0;
    vector<int> nv;
    int ncnt = v[k].size() - (n / 2 - sum);
    FOR (i, v[k].size() - ncnt, v[k].size() - 1) nv.pb(v[k][i]);
    v[k].resize(v[k].size() - ncnt);
    upd(k, -ncnt);
    int mx = 0, cnt = 0;
    for (int i = 0; i < nv.size(); i++) {
        if (nv[i] > mx) mx = nv[i], cnt = 0;
        v[mx].pb(nv[i]);
        cnt++;
        if (i == nv.size() - 1 || nv[i + 1] > mx) upd(mx, cnt);
    }
    return 1;
}

int cal(int p) {
    int k = sch(p - 1), sum = que(k - 1);
    return v[k][p - sum - 1];
}

void solve() {
    cin >> n >> q;
    FOR (i, 1, n) cin >> a[i];
    FOR (i, 1, q) {
        auto &[t, p, id] = ask[i];
        cin >> t >> p;
        id = i;
    }

    int mx = 0, cnt = 0;
    FOR (i, 1, n) {
        if (a[i] > mx) mx = a[i], cnt = 0;
        v[mx].pb(a[i]);
        cnt++;
        if (i == n || a[i + 1] > mx) upd(mx, cnt);
    }

    sort(ask + 1, ask + q + 1);
    int cur = 0, f = 1;
    FOR (i, 1, q) {
        auto [t, p, id] = ask[i];
        while (f && cur < t) {
            f &= work();
            cur++;
        }
        ans[id] = cal(p);
    }
    FOR (i, 1, q) cout << ans[i] << '\n';
}

int main() {
    Waimai;
    solve();
}

Compilation message

Main.cpp: In function 'bool work()':
Main.cpp:56:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   56 |     for (int i = 0; i < nv.size(); i++) {
      |                     ~~^~~~~~~~~~~
Main.cpp:60:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   60 |         if (i == nv.size() - 1 || nv[i + 1] > mx) upd(mx, cnt);
      |             ~~^~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 352 ms 25608 KB Output is correct
2 Correct 356 ms 24932 KB Output is correct
3 Correct 336 ms 24812 KB Output is correct
4 Correct 337 ms 24060 KB Output is correct
5 Correct 354 ms 24780 KB Output is correct
6 Correct 335 ms 24048 KB Output is correct
7 Correct 348 ms 24904 KB Output is correct
8 Correct 332 ms 24120 KB Output is correct
9 Correct 344 ms 24016 KB Output is correct
10 Correct 362 ms 24292 KB Output is correct
11 Correct 351 ms 24184 KB Output is correct
12 Correct 330 ms 24012 KB Output is correct
13 Correct 343 ms 24496 KB Output is correct
14 Correct 394 ms 24508 KB Output is correct
15 Correct 380 ms 24840 KB Output is correct
16 Correct 3 ms 4948 KB Output is correct
17 Correct 321 ms 24340 KB Output is correct
18 Correct 369 ms 24216 KB Output is correct
19 Correct 3 ms 4948 KB Output is correct
20 Correct 3 ms 4948 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1046 ms 524288 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 777 ms 524288 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 352 ms 25608 KB Output is correct
2 Correct 356 ms 24932 KB Output is correct
3 Correct 336 ms 24812 KB Output is correct
4 Correct 337 ms 24060 KB Output is correct
5 Correct 354 ms 24780 KB Output is correct
6 Correct 335 ms 24048 KB Output is correct
7 Correct 348 ms 24904 KB Output is correct
8 Correct 332 ms 24120 KB Output is correct
9 Correct 344 ms 24016 KB Output is correct
10 Correct 362 ms 24292 KB Output is correct
11 Correct 351 ms 24184 KB Output is correct
12 Correct 330 ms 24012 KB Output is correct
13 Correct 343 ms 24496 KB Output is correct
14 Correct 394 ms 24508 KB Output is correct
15 Correct 380 ms 24840 KB Output is correct
16 Correct 3 ms 4948 KB Output is correct
17 Correct 321 ms 24340 KB Output is correct
18 Correct 369 ms 24216 KB Output is correct
19 Correct 3 ms 4948 KB Output is correct
20 Correct 3 ms 4948 KB Output is correct
21 Runtime error 1046 ms 524288 KB Execution killed with signal 9
22 Halted 0 ms 0 KB -