QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#249458#7627. Phonyucup-team191#WA 0ms3712kbC++143.1kb2023-11-12 06:59:582023-11-12 06:59:58

Judging History

你现在查看的是最新测评结果

  • [2023-11-12 06:59:58]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3712kb
  • [2023-11-12 06:59:58]
  • 提交

answer

#include<bits/stdc++.h>
#include<bits/extc++.h>

using namespace std;
using namespace __gnu_pbds;

typedef long long llint;
typedef pair <llint, llint> pi;

template <class T>
using Tree = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

const int MAXN = 500005;

llint n, m, k;
llint a[MAXN];

llint idx, ofs;
__int128 ost;
map <llint, llint> mp_top_k, mp_ostali;
Tree <pi> top_k;
Tree <pi> ostali;

llint get_mod_k (llint val) {
    val %= k;
    if (val < 0) return val + k;
    return val;
}

llint get_val (llint j) {
    llint res = ofs * k + (top_k.find_by_order(j) -> first);
    if (j < idx) res += k;
    return res;
}

void update_ostali () {
    if (ostali.empty()) {
        ost = -1;
        return;
    }
    llint siz = top_k.size();
    llint val = ostali.begin() -> first;
    llint ostatak = get_mod_k(val);
    auto it = top_k.upper_bound({ostatak, 1e18});
    if (it != top_k.begin()) {
        it--;
    } else {
        it = top_k.end(); it--;
    }

    llint j = top_k.order_of_key(*it);
    llint val_j = get_val(j);

    ost = (j + 1 - idx);
    if (ost < 0) ost += siz;
    ost += ((val - val_j) / k - 1) * ((__int128) siz);
}

void ubaci_top_k (llint val) {
    top_k.insert({val, mp_top_k[val]});
    mp_top_k[val]++;
}

void ubaci_ostali (llint val) {
    ostali.insert({val, mp_ostali[val]});
    mp_ostali[val]++;
}

void init () {
    llint mn = 2e18;
    for (int i = 1; i <= n; i++) {
        mn = min(mn, a[i]);
    }
    for (int i = 1; i <= n; i++) {
        if (a[i] <= mn + k) {
            ubaci_top_k(get_mod_k(a[i]));
        } else {
            ubaci_ostali(a[i]);
        }
    }
    idx = top_k.order_of_key({mn, 0});
    ofs = (mn - get_mod_k(mn)) / k;
    update_ostali();
}

void prebaci () {
    pi curr = *top_k.find_by_order(idx);

    llint br = ostali.begin() -> first;
    ostali.erase(ostali.begin());
    ubaci_top_k(get_mod_k(br));

    idx = top_k.order_of_key(curr);
}

void advance_once (llint d) {
    llint siz = top_k.size();

    ofs += d / siz;
    d %= siz;

    llint novi_idx = (idx + d) % siz;
    if (novi_idx < idx) ofs++;
    idx = novi_idx;
}

void advance (llint d) {
    while (ost <= d && ost != -1) {
        advance_once(ost);
        d -= ost;
        prebaci();
        update_ostali();
    }
    if (d > 0) {
        advance_once(d);
        if (ost != -1) ost -= d;
    }
}

llint upit (llint val) {
    llint siz = top_k.size();
    if (val > siz) {
        val -= siz;
        val--;
        return ostali.find_by_order(val) -> first;
    } else {
        val--;
        llint j = (idx + val) % siz;
        return get_val(j);
    }
}

int main () {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cin >> n >> m >> k;
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
        a[i] = -a[i];
    }
    init();
    for (int i = 1; i <= m; i++) {
        char tip; llint val;
        cin >> tip >> val;
        if (tip == 'C') {
            advance(val);
        } else {
            cout << -upit(val) << '\n';
        }
    }
    return 0;
}

详细

Test #1:

score: 100
Accepted
time: 0ms
memory: 3588kb

input:

3 5 5
7 3 9
A 3
C 1
A 2
C 2
A 3

output:

3
4
-1

result:

ok 3 lines

Test #2:

score: 0
Accepted
time: 0ms
memory: 3628kb

input:

5 8 8
294 928 293 392 719
A 4
C 200
A 5
C 10
A 2
C 120
A 1
A 3

output:

294
200
191
0
-2

result:

ok 5 lines

Test #3:

score: -100
Wrong Answer
time: 0ms
memory: 3712kb

input:

100 100 233
5101 8001 6561 6329 6305 7745 4321 811 49 1121 3953 8054 8415 9876 6701 4097 6817 6081 495 5521 2389 2042 4721 8119 7441 7840 8001 5756 5561 129 1 5981 4801 7201 8465 7251 6945 5201 5626 3361 5741 3650 7901 2513 8637 3841 5621 9377 101 3661 5105 4241 5137 7501 5561 3581 4901 561 8721 811...

output:

6881
9162
4721
8234
2945
7745
7557
5291
5001
2042
4721
4721
6881
4097
7251
7280
7065
7064
811
6813
2561
6736
6135
6181
3581
5291
1485
6013
5425
2042
5344
5203
5275
4721
5137
4029
4097
4629
4851
4624
4735
2042
4591
4484
4638
4461
3581
4382
115
2042
4335
2042
4326
1485
4371
-17530

result:

wrong answer 2nd lines differ - expected: '9161', found: '9162'