Submission #921161

# Submission time Handle Problem Language Result Execution time Memory
921161 2024-02-03T11:23:28 Z gs18103 Fish (IOI08_fish) C++17
9 / 100
212 ms 17748 KB
#include  <bits/stdc++.h>
#define fi first
#define se second
#define eb emplace_back
#define em emplace
#define all(v) v.begin(), v.end()

using namespace std;
typedef long long ll;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;

const int MAX = 202020;
const int INF = 1e9;
const ll LINF = 1e18;

struct SEG {
    vector <int> tree;
    int sz, mod;
    bool base;
    SEG(int n, int _mod, int x = 0, bool _base = true) : mod(_mod), base(_base) {
        for(sz = 1; sz < n; sz <<= 1) ;
        tree.resize(sz<<1);
        for(int &i : tree) i = x;
    }

    void update(int x, int val) {
        int node = x + sz - base;
        tree[node] += val;
        tree[node] %= mod;
        while(node >>= 1) {
            tree[node] = (tree[node<<1] * tree[node<<1|1]) % mod;
        }
    }

    int cal(int l, int r) {
        int ret = 1;
        for(l += sz - base, r += sz - base; l <= r; l >>= 1, r >>= 1) {
            if(l & 1) ret = (ret * tree[l++]) % mod;
            if(~r & 1) ret = (ret * tree[r--]) % mod;
        }
        return ret;
    }
};

int main() {
    ios::sync_with_stdio(false); cin.tie(0);

    int n, k, mod;
    cin >> n >> k >> mod;
    vector <pii> F(n), C(k);
    for(int i = 0; i < n; i++) {
        cin >> F[i].fi >> F[i].se;
        C[F[i].se-1].fi = max(C[F[i].se-1].fi, F[i].fi);
    }
    for(int i = 0; i < k; i++) {
        C[i].se = i + 1;
    }
    sort(all(F));
    sort(all(C));
    vector <int> num(k+1);
    for(int i = 0; i < k; i++) {
        num[C[i].se] = i;
    }

    vector <int> mx(k);
    for(int i = 0; i < n; i++) {
        if(F[i].fi * 2 > F[n-1].fi) break;
        mx[num[F[i].se]]++;
    }

    SEG ST(k, mod, 1, false);
    int ans = 0, idx = 0;
    for(int i = 0; i < n; i++) {
        while(idx < n && F[idx].fi * 2 <= F[i].fi) {
            ST.update(F[idx].se, 1);
            idx++;
        }
        F[i].se = num[F[i].se];
        if(C[F[i].se].fi == F[i].fi) {
            ans += ST.cal(0, F[i].se);
            ans %= mod;
            if(i + 1 < n && mx[F[i].se] + 1 == ST.cal(F[i].se, F[i].se)) {
                ans += ST.cal(0, F[i].se-1) * (ST.cal(F[i].se+1, k-1) - 1);
                ans %= mod;
                ans += mod;
                ans %= mod;
            }
        }
    }
    cout << ans << endl;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 500 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 456 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Incorrect 1 ms 348 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Incorrect 109 ms 10412 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 45 ms 4308 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Incorrect 2 ms 588 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 73 ms 6656 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 122 ms 10476 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 69 ms 7100 KB Output is correct
2 Incorrect 129 ms 11344 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 129 ms 10396 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 138 ms 12112 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 118 ms 10924 KB Output is correct
2 Correct 137 ms 14720 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 169 ms 15332 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 177 ms 13396 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 212 ms 17748 KB Output isn't correct
2 Halted 0 ms 0 KB -