QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#249203#4583. Concerto de Pandemicwarner1129TL 819ms18296kbC++203.0kb2023-11-12 02:00:212023-11-12 02:00:22

Judging History

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

  • [2023-11-12 02:00:22]
  • 评测
  • 测评结果:TL
  • 用时:819ms
  • 内存:18296kb
  • [2023-11-12 02:00:21]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;

#ifdef LOCAL
template<class... T> void dbg(T... x) { char e{}; ((cerr << e << x, e = ' '), ...); }
template<class T> void org(T l, T r) { while (l != r) cerr << ' ' << *l++; cerr << '\n'; }
#define debug(x...) dbg(#x, '=', x, '\n')
#define olist(x...) dbg(#x, '='), org(x)
#else
#define debug(...) ((void)0)
#define olist(...) ((void)0)
#endif
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define ff first
#define ss second

using i64 = long long;
using u64 = unsigned long long;
using i128 = __int128;
using u128 = unsigned __int128;

constexpr int inf = 1e9;
constexpr int mod = 998244353;

template<class T> bool chmin(T &a, T b) { return (b < a and (a = b, true)); }
template<class T> bool chmax(T &a, T b) { return (a < b and (a = b, true)); }
template<class... T> int add(T... x) { int t{}; return (((t += x) %= mod), ...), t; }
template<class... T> int mul(T... x) { i64 t{1}; return (((t *= x) %= mod), ...), t; }

void solve() {
    int n, m, K, P;
    cin >> n >> m >> K >> P;

    vector<i64> dis(n, 1);
    vector<bool> blk(n);
    for (int i = 0; i < m; i++) {
        int c, t;
        cin >> c >> t;
        c--;
        dis[c] += t;
        blk[c] = true;
    }
    partial_sum(all(dis), dis.begin());
    
    vector<bool> fan(n);
    for (int i = 0; i < K; i++) {
        int x;
        cin >> x;
        fan[x - 1] = true;
    }

    vector<i64> D;
    vector<bool> F;
    for (int i = 0; i < n; i++)
        if (!blk[i]) {
            F.push_back(fan[i]);
            D.push_back(dis[i]);
        }

    n = F.size();
    const int H = __lg(K);
    
    for (int i = 0; i < n; i++) {
        F.push_back(F[i]);
        D.push_back(D[i] + dis.back());
    }

    olist(all(F));
    olist(all(D));

    auto check = [&](i64 C) -> bool {
        vector<int> L, R;
        for (int l = 0, r = 0; l < n * 2; l++) {
            while (r < n * 2 and r - l < n and D[r] - D[l] <= C) {
                if (F[r]) L.push_back(l);
                r++;
            }
            if (F[l]) {
                R.push_back(r - 1);
            }
        }
        vector f(K * 2 + 1, vector<int>(H + 1, K * 2));
        for (int i = 0, j = 0; i < K * 2; i++) {
            while (j < K * 2 and L[j] <= R[i]) j++;
            f[i][0] = j;
        }
        for (int i = 0; i + 1 <= H; i++) {
            for (int j = 0; j < K * 2; j++)
                f[j][i + 1] = f[f[j][i]][i];
        }
        for (int i = 0; i < K; i++) {
            int p = i, s = 1;
            for (int j = H; j >= 0; j--)
                if (f[p][j] < i + K) {
                    p = f[p][j];
                    s += (1 << j);
                }
            if (s <= P) return false;
        }
        return true;
    };

    i64 ans = *ranges::partition_point(views::iota(0ll, (i64)1e18), check);

    cout << ans << '\n';
    
}

signed main() {
    cin.tie(0)->sync_with_stdio(false);
    cin.exceptions(cin.failbit);
    
    int T = 1;
    // cin >> T;
    while (T--) {
        solve();
    }
    
    return 0;
}


Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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: 3596kb

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: 3492kb

input:

5 2 2 1
1 14
2 14
3 5

output:

1

result:

ok single line: '1'

Test #4:

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

input:

2 1 1 1
1 200000
2

output:

0

result:

ok single line: '0'

Test #5:

score: 0
Accepted
time: 819ms
memory: 18296kb

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:

170531

result:

ok single line: '170531'

Test #6:

score: -100
Time Limit Exceeded

input:

198722 26425 169256 110599
33948 74442
51729 66300
40369 173859
42274 73043
117803 108716
149794 151005
147161 2675
148063 166634
132585 51612
141999 182365
32951 159790
120932 290
82655 150138
49337 10396
171146 129572
33311 193079
195115 171691
180568 77905
65397 110312
156436 149966
9377 55490
12...

output:


result: