QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#535463#9228. ICPC Inferenceucup-team004TL 187ms22744kbC++204.2kb2024-08-28 03:41:052024-08-28 03:41:05

Judging History

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

  • [2024-08-28 03:41:05]
  • 评测
  • 测评结果:TL
  • 用时:187ms
  • 内存:22744kb
  • [2024-08-28 03:41:05]
  • 提交

answer

#include <bits/stdc++.h>

using i64 = long long;

constexpr int K = 20;

constexpr i64 M = 1E16;
template <typename T>
struct Fenwick {
    int n;
    std::vector<T> a;
    
    Fenwick(int n_ = 0) {
        init(n_);
    }
    
    void init(int n_) {
        n = n_;
        a.assign(n, T{});
    }
    
    void add(int x, const T &v) {
        for (int i = x + 1; i <= n; i += i & -i) {
            a[i - 1] = a[i - 1] + v;
        }
    }
    
    T sum(int x) {
        T ans{};
        for (int i = x; i > 0; i -= i & -i) {
            ans = ans + a[i - 1];
        }
        return ans;
    }
    
    T rangeSum(int l, int r) {
        return sum(r) - sum(l);
    }
    
    int select(const T &k) {
        int x = 0;
        T cur{};
        for (int i = 1 << std::__lg(n); i; i /= 2) {
            if (x + i <= n && cur + a[x + i - 1] <= k) {
                x += i;
                cur = cur + a[x - 1];
            }
        }
        return x;
    }
};

int main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    
    int N, D, L;
    std::cin >> N >> D >> L;
    
    std::vector<std::vector<int>> vec(D);
    for (int i = 0; i < N; i++) {
        int d, t;
        std::cin >> d >> t;
        d--;
        vec[d].push_back(t);
    }
    
    std::vector<i64> bronze(D), gold(D);
    
    std::vector<int> teams;
    for (int i = 0; i < D; i++) {
        if (vec[i].empty()) {
            continue;
        }
        teams.push_back(i);
    }
    
    for (auto i : teams) {
        bronze[i] = M - vec[i].back() - (vec[i].size() - 1) * K;
        for (int j = 0; j < std::min<int>(vec[i].size(), 13); j++) {
            gold[i] += M - vec[i][j];
        }
    }
    
    i64 ans = 0;
    
    std::vector<i64> b, g;
    for (auto i : teams) {
        b.push_back(bronze[i]);
        g.push_back(gold[i]);
    }
    std::sort(b.begin(), b.end());
    std::sort(g.begin(), g.end());
    
    std::vector<i64> pre(g.size() + 1);
    i64 tot = 0;
    for (int i = 0, j = 0; i < g.size(); i++) {
        while (j < b.size() && b[j] <= g[i]) {
            j++;
        }
        pre[i + 1] = pre[i] + j;
        tot += j - 1;
    }
    
    std::vector<std::array<i64, 2>> ask;
    // std::cerr << tot << "\n";
    for (auto i : teams) {
        // std::cerr << "- " << i + 1 << " " << bronze[i] << " " << gold[i] << "\n";
        std::vector<i64> s;
        for (int j = 0; j < vec[i].size(); j++) {
            for (int k = 0; k <= j; k++) {
                s.push_back(M - vec[i][j] - k * K);
            }
        }
        if (vec[i].size() >= 2) {
            s.push_back(2 * M - vec[i].back() - vec[i].end()[-2] - (vec[i].size() - 2) * K);
        }
        std::sort(s.begin(), s.end());
        ans += tot;
        
        auto check = [&](i64 l, i64 r) {
            if (l == r) {
                return;
            }
            l++;
            int lo = std::lower_bound(g.begin(), g.end(), l) - g.begin();
            int hi = std::lower_bound(g.begin(), g.end(), r) - g.begin();
            ans -= pre[hi] - pre[lo];
            ans += 1LL * (hi - lo) * (std::lower_bound(b.begin(), b.end(), l) - b.begin());
            ask.push_back({l, r});
        };
        
        check(0, s[0]);
        for (int j = 1; j < s.size(); j++) {
            check(s[j - 1], s[j]);
        }
        check(s.back(), 1E18);
        
        ans -= g.end() - std::lower_bound(g.begin(), g.end(), bronze[i]);
        ans -= std::upper_bound(b.begin(), b.end(), gold[i]) - b.begin();
        ans += 2;
    }
    
    Fenwick<int> fen(b.size());
    std::sort(ask.begin(), ask.end(), std::greater());
    auto ord = teams;
    std::sort(ord.begin(), ord.end(),
        [&](int i, int j) {
            return bronze[i] < bronze[j];
        });
    for (int i = ord.size(); auto [l, r] : ask) {
        while (i > 0 && bronze[ord[i - 1]] >= l) {
            i--;
            int j = std::lower_bound(g.begin(), g.end(), gold[ord[i]]) - g.begin();
            fen.add(j, 1);
        }
        ans += fen.sum(std::lower_bound(g.begin(), g.end(), r) - g.begin());
    }
    
    std::cout << ans << "\n";
    
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

4 3 300
1 10
2 25
2 30
3 50

output:

3

result:

ok 1 number(s): "3"

Test #2:

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

input:

4 6 200000
6 1
6 1
1 2
2 2

output:

4

result:

ok 1 number(s): "4"

Test #3:

score: 0
Accepted
time: 127ms
memory: 17916kb

input:

191580 64997 56
24878 1
35060 1
24245 1
64330 1
9650 1
15423 1
34953 1
21456 1
36718 1
21395 1
17613 1
16995 1
45257 1
31277 1
20026 1
1870 1
25581 1
9997 1
54701 1
30752 1
32269 1
705 1
64186 1
58881 1
24614 1
55311 1
18259 1
58886 1
23296 1
17628 1
3411 1
37469 1
47951 1
12188 1
60720 1
54168 1
45...

output:

274533940012863

result:

ok 1 number(s): "274533940012863"

Test #4:

score: 0
Accepted
time: 187ms
memory: 22744kb

input:

192309 96431 357
56446 1
42487 1
47313 1
71736 1
74439 1
19895 1
52024 1
66203 1
992 1
78744 1
9911 1
85130 1
73814 1
64499 1
92961 1
66255 1
88807 1
82217 1
36788 1
66999 1
35107 1
47933 1
34196 1
50534 1
83014 1
75035 1
30407 1
36014 1
7248 1
69915 1
57348 1
5356 1
37088 1
36455 1
29365 1
71376 1
...

output:

868523468626161

result:

ok 1 number(s): "868523468626161"

Test #5:

score: -100
Time Limit Exceeded

input:

200000 200000 200000
151464 4
1477 6
95966 8
121582 8
19239 11
668 13
109329 15
173254 15
153807 16
75865 16
123829 17
101156 17
8881 18
116717 18
124985 18
125918 18
132143 19
35899 20
90547 20
106065 22
176481 23
11727 23
527 24
77206 25
85757 25
169873 26
139187 26
5970 28
37134 29
199855 30
9598...

output:


result: