QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#18616#2327. Egma GameDoorKickersTL 3ms3640kbC++204.0kb2022-01-21 23:08:462022-05-06 01:52:35

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2022-05-06 01:52:35]
  • 评测
  • 测评结果:TL
  • 用时:3ms
  • 内存:3640kb
  • [2022-01-21 23:08:46]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pii pair<int, int>
#define mp make_pair
#define fi first
#define se second
signed main() {
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    int n; cin >> n;
    int B = sqrt(n);
    vector<int> a(n + 5);
    map<int, bool> vis;
    int mx(0), piv(0);
    for (int i = 1; i <= n; i++) {cin >> a[i]; vis[a[i]] = 1; mx = max(a[i], mx);}
    for (int i = 0; i <= mx + 1; i++) {
        if (!vis[i]) {
            // cout << "i = " << i << '\n';
            piv = i;
            break;
        }
    }
    int B_ = sqrt(piv);
    // cout << "B_ = " << B_ << '\n';
    map<int, int> vis_;
    vector<int> bull(piv / B_ + 5);
    int q; cin >> q;
    vector<pii> query(q + 5);
    for (int i = 1; i <= q; i++) {
        cin >> query[i].fi >> query[i].se;
    }
    vector<int> order(q + 5);
    iota(order.begin() + 1, order.begin() + 1 + q, 1);
    // for (int i = 1; i <= n; i++) {
    //     cout << "order[" << i << "] = " << order[i] << '\n';
    // }
    vector<int> len(piv / B_ + 5);
    for (int i = 1; i <= n; i++) {
        if (a[i] > piv) continue;
        len[a[i] / B_]++;
    }
    auto cmp = [&](int a_, int b_) {
        pii a = query[a_];
        pii b = query[b_];
        int temp = a.fi / B;
        int temp_ = (a.fi / B < b.fi / B);
        int temp__ = ((a.fi / B == b.fi / B) && ((temp % 2 == 0) ? a.se < b.se : a.se > b.se));
        int temp___ = (a.fi / B == b.fi / B);
        int temp____  = (temp % 2 == 0) ? a.se < b.se : a.se > b.se;
        // cout << "query[" << a_ << "] = " << query[a_].fi / B << '\n';
        // cout << "query[" << b_ << "] = " << query[b_].fi / B << '\n';
        // cout << "temp_ = " << temp_ << '\n';
        // cout << "temp__ = " << temp__ << '\n';
        // cout << "temp___ = " << temp___ << '\n';
        // cout << "temp____ = " << temp____ << '\n';
        // cout << "total = " << ((a.fi / B < b.fi / B) || ((a.fi / B == b.fi / B) && ((temp % 2 == 0) ? a.se < b.se : a.se > b.se))) << "这里后面是" << '\n';
        // cout << "or = " << temp_
        // cout << '\n';
        // cout << '\n';
        return (a.fi / B < b.fi / B) || ((a.fi / B == b.fi / B) && ((temp % 2 == 0) ? a.se < b.se : a.se > b.se)); 
    };
    sort(order.begin() + 1, order.begin() + 1 + q, cmp);
    auto remove = [&](int pos) {
        if (a[pos] > piv) return;
        vis_[a[pos]]--;
        bull[a[pos] / B_]--;
    };
    auto add = [&](int pos) {
        if (a[pos] > piv) return;
        vis_[a[pos]]++;
        bull[a[pos] / B_]++;
    };
    int l = 1;
    int r = 1;
    add(1);
    vector<int> ans(q + 5);
    for (int i = 1; i <= q; i++) {
        if (B_ == 0) {ans[order[i]] = 0; continue;}
        // cout << order[i] << " : " << query[order[i]].fi << ' ' << query[order[i]].se << '\n';
        while (l < query[order[i]].fi) remove(l++);
        while (l > query[order[i]].fi) add(--l);
        while (r < query[order[i]].se) add(++r);
        while (r > query[order[i]].se) remove(r--);
        int beg = 0;
        for (int j = 0; j <= piv / B_; j++) {
            // cout << "bull[" << j << "] = " << bull[j] << '\n';
            if (j == piv / B_) {
                for (int k = beg; k <= piv; k++) {
                    if (!vis_[k]) {
                        ans[order[i]] = k;
                        goto end;
                    }
                }
            }
            else {
                if (bull[j] != len[j]) {
                    for (int k = beg; k <= beg + B_ - 1; k++) {
                        if (!vis_[k]) {
                            ans[order[i]] = k;
                            goto end;
                        }
                    }
                }
            }
            beg += B_;
        }
        end:;
    }
    for (int i = 1; i <= q; i++) {
        cout << ans[i] << '\n';
    }
    return 0;
}
/*
6
5 3 0 1 2 3
i = 4
B_ = 2
6
5 2
1 1
5 2
1 1
5 2 
1 1
*/

详细

Test #1:

score: 100
Accepted
time: 3ms
memory: 3580kb

input:

5
1 2 3 0 5
2
1 3
1 4

output:

0
4

result:

ok 2 lines

Test #2:

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

input:

20
2 6 8 3 2 1 0 6 3 9 5 7 4 5 1 5 6 6 8 1
6
3 11
3 19
8 8
17 17
18 20
19 20

output:

4
10
0
0
0
0

result:

ok 6 lines

Test #3:

score: 0
Accepted
time: 3ms
memory: 3540kb

input:

2
1000000000 0
2
1 1
1 2

output:

0
1

result:

ok 2 lines

Test #4:

score: -100
Time Limit Exceeded

input:

500000
113500 171767 129776 204668 144688 243684 196619 110568 150466 2356 26733 173616 239824 118055 28013 96287 207607 5877 192363 187149 87221 38182 50377 131406 58562 103473 43635 208503 139095 174585 97707 35920 162202 107727 231465 137612 54481 84944 2478 171891 68834 26296 115626 35312 44152 ...

output:


result: