Submission #697092

# Submission time Handle Problem Language Result Execution time Memory
697092 2023-02-08T08:14:49 Z mjhmjh1104 Fish (IOI08_fish) C++17
9 / 100
582 ms 10864 KB
#include <cstdio>
#include <vector>
#include <utility>
#include <algorithm>
using namespace std;

int M;

int tree[1048576];

int query(int i, int b, int e, int l, int r) {
    if (r < l || r < b || e < l) return 1;
    if (l <= b && e <= r) return tree[i];
    int m = (b + e) / 2;
    return 1LL * query(i * 2 + 1, b, m, l, r) * query(i * 2 + 2, m + 1, e, l, r) % M;
}

int update(int i, int b, int e, int p, int v) {
    if (p < b || e < p) return tree[i];
    if (b == e) return tree[i] = v;
    int m = (b + e) / 2;
    return tree[i] = 1LL * update(i * 2 + 1, b, m, p, v) * update(i * 2 + 2, m + 1, e, p, v) % M;
}

int n, k, cnt[500006], cnt2[500006], t, rt[500006];
bool visited[500006];
vector<pair<int, int>> v;

int main() {
    scanf("%d%d%d", &n, &k, &M);
    for (int i = 0; i < n; i++) {
        int x, y;
        scanf("%d%d", &x, &y);
        y--;
        v.push_back({ x, y });
    }
    sort(v.begin(), v.end());
    for (int i = 0; i < n; i++) {
        while (t < n && v[t].first * 2 <= v[i].first) cnt[v[t++].second]++;
        rt[i] = t;
    }
    int res = 0;
    for (int i = 0; i < k; i++) cnt2[i] = cnt[i];
    for (int i = 0; i < k; i++) tree[524287 + i] = (cnt[i] + 1) % M;
    for (int i = 524286; i >= 0; i--) tree[i] = 1LL * tree[i * 2 + 1] * tree[i * 2 + 2] % M;
    for (int i = n - 1; i >= 0; i--) {
        while (t > rt[i]) {
            --t;
            cnt[v[t].second]--;
            update(0, 0, 524287, v[t].second, (cnt[v[t].second] + 1) % M);
        }
        if (!visited[v[i].second] && cnt[v[i].second] == cnt2[v[i].second]) {
            visited[v[i].second] = true;
            int curr = 1LL * query(0, 0, 524287, 0, v[i].second - 1) * query(0, 0, 524287, v[i].second + 1, k - 1) % M;
            res = (res + curr) % M;
        }
    }
    for (int i = 0; i < k; i++) cnt[i] = 0;
    t = 0;
    for (int i = 0; i < n; i++) {
        while (t < n && v[t].first * 2 <= v[i].first) cnt[v[t++].second]++;
        rt[i] = t;
    }
    for (int i = 0; i < k; i++) tree[524287 + i] = (cnt[i] + 1) % M, visited[i] = false;
    for (int i = 524286; i >= 0; i--) tree[i] = 1LL * tree[i * 2 + 1] * tree[i * 2 + 2] % M;
    for (int i = n - 1; i >= 0; i--) {
        while (t > rt[i]) {
            --t;
            cnt[v[t].second]--;
            cnt[v[t].second] = max(cnt[v[t].second], 0);
            update(0, 0, 524287, v[t].second, (cnt[v[t].second] + 1) % M);
        }
        if (!visited[v[i].second]) {
            visited[v[i].second] = true;
            if (cnt[v[i].second] == cnt2[v[i].second]) {
                cnt[v[i].second]--;
                cnt[v[i].second] = max(cnt[v[i].second], -1);
                update(0, 0, 524287, v[i].second, (cnt[v[i].second] + 1) % M);
            }
            int curr = query(0, 0, 524287, 0, k - 1);
            res = (res + curr) % M;
            update(0, 0, 524287, v[i].second, 1);
            cnt[v[i].second] = 0;
            update(0, 0, 524287, v[i].second, (cnt[v[i].second] + 1) % M);
        }
    }
    printf("%d", res);
}

Compilation message

fish.cpp: In function 'int main()':
fish.cpp:30:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   30 |     scanf("%d%d%d", &n, &k, &M);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~~~~
fish.cpp:33:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   33 |         scanf("%d%d", &x, &y);
      |         ~~~~~^~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 7 ms 2260 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 6 ms 2248 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 6 ms 2260 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 7 ms 2260 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 6 ms 2260 KB Output is correct
2 Incorrect 7 ms 2280 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 7 ms 2388 KB Output is correct
2 Incorrect 299 ms 8376 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 6 ms 2388 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 8 ms 2388 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 118 ms 4800 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 9 ms 2368 KB Output is correct
2 Incorrect 10 ms 2528 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 182 ms 6024 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 365 ms 8376 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 154 ms 6056 KB Output is correct
2 Incorrect 294 ms 8404 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 272 ms 7832 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 296 ms 8496 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 254 ms 7928 KB Output is correct
2 Correct 280 ms 9612 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 448 ms 9640 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 443 ms 9612 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 582 ms 10864 KB Output isn't correct
2 Halted 0 ms 0 KB -