QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#690853#9228. ICPC Inferenceucup-team3215WA 149ms37644kbC++235.1kb2024-10-31 05:59:572024-10-31 05:59:58

Judging History

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

  • [2024-10-31 05:59:58]
  • 评测
  • 测评结果:WA
  • 用时:149ms
  • 内存:37644kb
  • [2024-10-31 05:59:57]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;
using ll = long long;
using pl = array<ll, 2>;
constexpr int N = 5e6 + 5;

struct Fenwick {
    int n;
    vector<int> f;

    Fenwick(int n) : n(n), f(n) {}

    void upd(int i, int x) {
        for (; i < n; i |= i + 1)f[i] += x;
    }

    int get(int i) {
        int res = 0;
        for (; ~i; i &= i + 1, --i)res += f[i];
        return res;
    }

    int sum(int l, int r) {
        if (l > r)return 0;
        return get(r) - get(l - 1);
    }
};

int main() {
    cin.tie(0)->sync_with_stdio(false);
    ll n, d, l;
    cin >> n >> d >> l;
    vector<vector<ll>> all(d);
    for (ll i = 0; i < n; ++i) {
        ll x, t;
        cin >> x >> t;
        --x;
        all[x].push_back(t);
    }
    {
        vector<vector<ll>> nall;
        for (auto &v: all) {
            if (v.size())nall.push_back(v);
        }
        swap(all, nall);
        d = all.size();
    }
    ll res = d * (d - 1) * (d - 2);
    vector<pl> best(d);
    vector<ll> worst(d);
    for (ll i = 0; i < d; ++i) {
        for (ll j = 0; j < all[i].size() && j < 13; ++j) {
            best[i][0]++;
            best[i][1] += all[i][j];
        }
        worst[i] = (all[i].size() - 1) * 20 + all[i].back();
    }
    // 1 1 *
    {
        ll bad = 0;
        vector<ll> z;
        for (ll i = 0; i < d; ++i) {
            if (best[i][0] == 1)z.push_back(best[i][1]);
        }
        sort(z.begin(), z.end());
        vector<ll> t;
        for (ll i = 0; i < d; ++i) {
            t.push_back(worst[i]);
        }
        sort(t.begin(), t.end());
        ll ptr = 0;
        for (auto x: z) {
            while (ptr < t.size() && x > t[ptr])++ptr;
            bad += ptr * (d - 2);
        }
        res -= bad;
    }
    // 1 1 1
    {
        ll bad = 0;
        vector<pl> z;
        for (ll i = 0; i < d; ++i) {
            if (best[i][0] == 1)z.push_back({best[i][1], i});
        }
        auto w = worst;
        sort(z.begin(), z.end());
        sort(w.begin(), w.end());
        vector<vector<ll>> A(d);
        vector<ll> ptr(d, 1);
        set<pl> s;
        map<ll, ll> num;
        map<ll, ll> cnt;
        ll ways = 0;
        auto insert = [&](pl x) {
            s.insert(x);
            ++cnt[x[0]];
            ways += num[x[0]];
        };
        auto erase = [&](pl x) {
            s.erase(x);
            --cnt[x[0]];
            ways -= num[x[0]];
        };
        num[0] = 0;
        for (ll i = 0; i < d; ++i) {
            for (ll j = 0; j < all[i].size(); ++j) {
                A[i].push_back(j * 20 + all[i][j]);
                auto it = lower_bound(w.begin(), w.end(), A[i].back()) - w.begin();
                num[A[i].back()] = it;
            }
            insert({A[i][0], i});
        }
        for (auto &[v, id]: z) {
            while (s.size()) {
                auto it = *s.begin();
                if (it[0] >= v)break;
                erase(it);
                if (ptr[it[1]] < A[it[1]].size()) {
                    it[0] = A[it[1]][ptr[it[1]]++];
                    insert(it);
                }
            }
            erase({v, id});
            bad += ways - (s.size() - cnt[v]);
        }
        res -= bad;
    }
    // 2 1 1
    {
        ll bad = 0;
        vector<pl> z;
        vector<pl> two;
        vector<ll> num(d);
        auto w = worst;
        sort(w.begin(), w.end());
        Fenwick f(N);
        ll ways = 0;
        auto add = [&](ll id) {
            ways += num[id];
            f.upd(all[id][0], 1);
        };
        for (ll i = 0; i < d; ++i) {
            if (best[i][0] == 2) {
                z.push_back({best[i][1], i});
            }
            num[i] = lower_bound(w.begin(), w.end(), all[i][0]) - w.begin();
            if (all[i].size() >= 2) {
                ll k = all[i].size();
                ll it = all[i].end()[-1] + (k - 2) * 20 + all[i].end()[-2];
                two.push_back({it, i});
            } else {
                add(i);
            }
        }
        sort(z.begin(), z.end());
        sort(two.begin(), two.end());
        ll ptr = 0;
        for (auto [v, id]: z) {
            while (ptr < two.size() && two[ptr][0] < v) {
                add(two[ptr][1]);
                ++ptr;
            }
            bad += ways - f.sum(worst[id] + 1, N - 1);
        }
        res -= bad;
    }
    // 3 1 1
    {

        ll bad = 0;
        vector<pl> z;
        vector<ll> num(d);
        auto w = worst;
        sort(w.begin(), w.end());
        Fenwick f(N);
        ll ways = 0;
        for (ll i = 0; i < d; ++i) {
            if (best[i][0] >= 3) {
                z.push_back({best[i][1], i});
            }
            num[i] = lower_bound(w.begin(), w.end(), all[i][0]) - w.begin();
            if (best[i][0] == 1) {
                f.upd(all[i][0],1);
                ways += num[i];
            }
        }
        sort(z.begin(), z.end());
        for (auto [v, id]: z) {
            bad += ways - f.sum(worst[id] + 1, N - 1);
        }
        res -= bad;
    }
    cout << res;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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

input:

4 6 200000
6 1
6 1
1 2
2 2

output:

4

result:

ok 1 number(s): "4"

Test #3:

score: -100
Wrong Answer
time: 149ms
memory: 37644kb

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:

274503575290312

result:

wrong answer 1st numbers differ - expected: '274533940012863', found: '274503575290312'