Submission #697088

# Submission time Handle Problem Language Result Execution time Memory
697088 2023-02-08T08:10:57 Z mjhmjh1104 Fish (IOI08_fish) C++17
9 / 100
566 ms 13540 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]) {
                if (!cnt[v[i].second]) continue;
                cnt[v[i].second]--;
                cnt[v[i].second] = max(cnt[v[i].second], 0);
            }
            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;
        }
    }
    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 6 ms 2260 KB Output is correct
# 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 Incorrect 6 ms 2376 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 7 ms 2308 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 7 ms 2388 KB Output is correct
2 Incorrect 7 ms 2388 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 7 ms 2348 KB Output is correct
2 Incorrect 275 ms 11212 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 7 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 115 ms 7256 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 9 ms 2484 KB Output is correct
2 Incorrect 11 ms 2608 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 179 ms 8716 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 334 ms 10988 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 150 ms 8740 KB Output is correct
2 Incorrect 289 ms 11020 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 263 ms 10600 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 302 ms 11256 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 234 ms 10508 KB Output is correct
2 Correct 189 ms 12344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 421 ms 12352 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 476 ms 12264 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 566 ms 13540 KB Output isn't correct
2 Halted 0 ms 0 KB -