Submission #254870

# Submission time Handle Problem Language Result Execution time Memory
254870 2020-07-30T18:49:51 Z imeimi2000 Fish (IOI08_fish) C++17
100 / 100
527 ms 26104 KB
#include <bits/stdc++.h>

using namespace std;
typedef pair<int, int> pii;

const int sz = 1 << 19;
int n, k, mod;
pii L[500001];
int cnt[500001], last[500001];
int seg1[sz << 1], seg2[sz << 1];
bool used[500001];
int P[500001];

void update(int seg[], int i, int x) {
    seg[i += sz] += x % mod + mod;
    seg[i] %= mod;
    while (i /= 2) seg[i] = seg[i + i] * seg[i + i + 1] % mod;
}

int query(int seg[], int e) {
    int x = sz, y = sz + e;
    int ret = 1;
    while (x <= y) {
        if ((x & 1) == 1) ret = ret * seg[x++] % mod;
        if ((y & 1) == 0) ret = ret * seg[y--] % mod;
        x >>= 1;
        y >>= 1;
    }
    return ret;
}

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    cin >> n >> k >> mod;
    for (int i = 1; i <= n; ++i) {
        cin >> L[i].first >> L[i].second;
    }
    sort(L + 1, L + (n + 1));
    fill(seg1, seg1 + (sz << 1), 1);
    fill(seg2, seg2 + (sz << 1), 1);
    int j;
    for (j = 1; j <= n; ++j) {
        if (L[j].first * 2 > L[n].first) break;
        ++cnt[L[j].second];
        update(seg1, L[j].second, 1);
    }
    for (int i = 1; i <= k; ++i) last[i] = n;
    int ans = 0;
    for (int i = n; i > 0; --i) {
        if (used[L[i].second]) continue;
        while (j > 1 && L[j - 1].first * 2 > L[i].first) {
            int c = L[--j].second;
            --cnt[c];
            last[c] = i;
            if (used[c]) update(seg2, P[c], -1);
            else update(seg1, c, -1);
        }
        ans = (ans + seg1[1]) % mod;
        int p = seg1[L[i].second + sz] - 1;
        update(seg1, L[i].second, -p);
        ans = (ans + mod - seg1[1]) % mod;
        ans = (ans + seg1[1] * query(seg2, last[L[i].second])) % mod;
        update(seg2, P[L[i].second] = i, cnt[L[i].second]);
        used[L[i].second] = 1;
    }
    printf("%d\n", ans);
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 6 ms 8576 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 8584 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 8576 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 8576 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 8576 KB Output is correct
2 Correct 7 ms 8576 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 8576 KB Output is correct
2 Correct 209 ms 14812 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 8576 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 8704 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 103 ms 12536 KB Output is correct
2 Correct 127 ms 13796 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 8704 KB Output is correct
2 Correct 8 ms 8704 KB Output is correct
3 Correct 8 ms 8704 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 124 ms 14328 KB Output is correct
2 Correct 260 ms 19320 KB Output is correct
3 Correct 212 ms 19192 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 279 ms 14840 KB Output is correct
2 Correct 208 ms 19704 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 137 ms 14072 KB Output is correct
2 Correct 214 ms 14840 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 208 ms 14712 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 227 ms 14968 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 188 ms 14712 KB Output is correct
2 Correct 205 ms 17912 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 298 ms 16248 KB Output is correct
2 Correct 238 ms 17656 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 335 ms 16632 KB Output is correct
2 Correct 304 ms 21496 KB Output is correct
3 Correct 412 ms 21752 KB Output is correct
4 Correct 337 ms 21496 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 406 ms 17252 KB Output is correct
2 Correct 503 ms 26104 KB Output is correct
3 Correct 390 ms 25268 KB Output is correct
4 Correct 527 ms 25684 KB Output is correct