QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#67825#4583. Concerto de PandemickarunaWA 1054ms127028kbC++173.6kb2022-12-12 14:49:132022-12-12 14:49:16

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2022-12-12 14:49:16]
  • 评测
  • 测评结果:WA
  • 用时:1054ms
  • 内存:127028kb
  • [2022-12-12 14:49:13]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;

const int N = 202020;
typedef long long ll;
int n, m, k, p, t[N], d[N], l[N], r[N];
ll pl[20][N], pr[20][N], cl[20][N], cr[20][N];
pair<int, int> V[2 * N], stk[N];

int main() {
    cin.tie(0); ios_base::sync_with_stdio(0);
    cin >> n >> m >> k >> p;
    for (int i = 0; i < m; i++) {
        int x; cin >> x;
        cin >> t[x - 1];
    }

    for (int i = 0; i < k; i++) {
        cin >> d[i];
        d[i]--;
    }
    sort(d, d + k);
    for (int i = 0; i < n; i++) {
        cl[0][i] = t[(i + n - 1) % n] + 1;
        cr[0][i] = t[(i + 1) % n] + 1;
        pl[0][i] = (i + n - 1) % n;
        pr[0][i] = (i + 1) % n;
    }
    for (int j = 1; j < 20; j++) for (int i = 0; i < n; i++) {
        cl[j][i] = cl[j - 1][i] + cl[j - 1][pl[j - 1][i]];
        cr[j][i] = cr[j - 1][i] + cr[j - 1][pr[j - 1][i]];
        pl[j][i] = pl[j - 1][pl[j - 1][i]];
        pr[j][i] = pr[j - 1][pr[j - 1][i]];
    }

    ll L = 0, R = 1e13;
    while (L < R) {
        ll M = (L + R) / 2;
        int sz = 0;
        for (int i = 0; i < k; i++) {
            ll x = M, y = M, l = 0, r = 0;
            int p = d[i], q = d[i];
            for (int j = 19; j >= 0; j--) {
                if (cl[j][p] <= x) {
                    x -= cl[j][p];
                    p = pl[j][p];
                    l ^= 1 << j;
                }
                if (cr[j][q] <= y) {
                    y -= cr[j][q];
                    q = pr[j][q];
                    r ^= 1 << j;
                }
            }
            if (l + r >= n - 1) continue;
            V[sz++] = {p, q};
        }


        if (sz == 0) {
            R = M; continue;
        }
        // cout << M << "!\n";
        // for (auto [l, r] : V) {
        //     cout << l << ' '<< r << '\n';
        // }

        int x = 0;
        while (x < sz && V[x].first > V[x].second) {
            ++x;
        }
        for (int i = 0; i < x; i++) {
            V[sz + i] = V[i];
        }
        for (int i = 0; i < sz; i++) {
            swap(V[i], V[i + x]);
        }

        int tz = 0;
        for (int i = 0; i < sz; i++) {
            auto [l, r] = V[i];
            if (r < l) r += n;

            // cout << l << ' ' << r << "?\n";
            while (tz != 0 && stk[tz - 1].second >= r) {
                --tz;
            }
            stk[tz++] = {l, r};
        }
        int rend = -1, lend = n + 1;

        int ans = 0;
        for (int i = 0; i < tz; i++) {
            if (stk[i].second >= n) continue;
            if (rend < stk[i].first) {
                ++ans;
                rend = stk[i].second;
            }
        }
        for (int i = tz - 1; i >= 0; i--) {
            if (stk[i].second >= n) continue;
            if (lend > stk[i].second) {
                lend = stk[i].first;
            }
        }
        // cout << lend << ' ' << rend << "!!\n";

        if (lend == -1 || rend == -1) {
            ans = 1;
        }
        else if (ans == 1) {
            auto [a, b] = stk[0];
            auto [c, d] = stk[tz - 1];
            if (b < c) {
                ans = 2;
            }
        }
        else {
            bool f = true;
            for (int i = 0; i < tz; i++) {
                if (stk[i].second < n) continue;
                auto [r, l] = stk[i]; 
                l -= n;
                if (l < lend && r > rend) {
                    f = false;
                }
            }
            ans += (!f);
        }

        if (ans <= p) R = M;
        else L = M + 1;
    }
    cout << L;
}   

詳細信息

Test #1:

score: 100
Accepted
time: 2ms
memory: 20220kb

input:

10 4 3 2
1 2
4 4
6 2
7 5
2 5 8

output:

4

result:

ok single line: '4'

Test #2:

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

input:

8 1 3 5
1 5
4 2 7

output:

0

result:

ok single line: '0'

Test #3:

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

input:

5 2 2 1
1 14
2 14
3 5

output:

1

result:

ok single line: '1'

Test #4:

score: 0
Accepted
time: 6ms
memory: 18072kb

input:

2 1 1 1
1 200000
2

output:

0

result:

ok single line: '0'

Test #5:

score: -100
Wrong Answer
time: 1054ms
memory: 127028kb

input:

190976 113222 55610 23475
51263 120558
10007 171596
46671 108981
117183 169457
18187 84735
149298 124718
79376 129184
28117 76880
109791 87521
114840 59510
38014 178362
41701 11344
27561 192741
173835 54534
71368 76692
122745 95537
152595 158352
43901 162441
98927 105784
22484 96000
19443 113614
370...

output:

167341

result:

wrong answer 1st lines differ - expected: '170531', found: '167341'