Submission #1108753

# Submission time Handle Problem Language Result Execution time Memory
1108753 2024-11-05T01:50:06 Z kyaruru Fish (IOI08_fish) C++17
20 / 100
204 ms 30160 KB
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

ll a, b, c;

void update(vector<ll>& seg, int idx, ll value) {
    seg[idx] += value;
    for (idx /= 2; idx >= 1; idx /= 2) seg[idx] = seg[2 * idx] * seg[2 * idx + 1];
}

ll query(vector<ll>& seg, int l, int r) {
    ll v = 1;
    while (l <= r) {
        if (l % 2 == 1) v *= seg[l++] % c;
        if (r % 2 == 0) v *= seg[r--] % c;
        l /= 2, r /= 2;
    }
    return v;
}

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cin >> a >> b >> c;
    pll k[a + 1];
    for (int i = 1; i <= a; i++) {
        ll x, y;
        cin >> x >> y;
        k[i] = {x, y};
    }

    int h = ceil(log2(b));
    int n = (1 << h) - 1;
    vector<ll> seg(1 << (h + 1), 1), sega(1 << (h + 1), 1);

    sort(k + 1, k + a + 1);

    ll ed[b + 1], sv[b + 1], u[b + 1];
    memset(ed, -1, sizeof(ed));
    memset(u, -1, sizeof(u));
    memset(sv, 0, sizeof(sv));

    int m = b;
    for (int i = a; i >= 1; i--) {
        if (ed[k[i].second] == -1) ed[k[i].second] = m--;
        k[i].second = ed[k[i].second];
    }

    vector<int> ka;
    memset(ed, -1, sizeof(ed));
    for (int i = a; i >= 1; i--) {
        if (ed[k[i].second] == -1)
            ed[k[i].second] = i, ka.push_back(k[i].first), u[k[i].second] = k[i].first;
        else if (2 * k[i].first > k[ed[k[i].second]].first)
            u[k[i].second] = k[i].first;
    }
    sort(ka.begin(), ka.end());

    ll g = 1, ans = 0;
    for (int i = 1; i <= a; i++) {
        while (2 * k[g].first <= k[i].first) update(sega, k[g++].second + n, 1);
        if (ed[k[i].second] == i) {
            ans += query(sega, 1 + n, k[i].second + n);
            int v = lower_bound(ka.begin(), ka.end(), 2 * u[k[i].second]) - ka.begin();
            ll t = query(sega, k[i].second + 1 + n, v + n) - 1;
            ll tt = query(sega, 1 + n, k[i].second - 1 + n);
            ans += t * tt;
        }
    }

    cout << (ans % c + c) % c;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 580 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Incorrect 116 ms 14144 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 424 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 336 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 39 ms 5968 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 592 KB Output is correct
2 Incorrect 2 ms 592 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 76 ms 9032 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 105 ms 14232 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 69 ms 9544 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 104 ms 14664 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 124 ms 17224 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 119 ms 16456 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 169 ms 27448 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 153 ms 25400 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 204 ms 30160 KB Output isn't correct
2 Halted 0 ms 0 KB -