Submission #778603

# Submission time Handle Problem Language Result Execution time Memory
778603 2023-07-10T13:13:21 Z loctildore Fish (IOI08_fish) C++14
100 / 100
1060 ms 55828 KB
#include <bits/stdc++.h>
using namespace std;
// trans rights
#define ll long long
#define f first
#define s second
#define endl '\n'
#define all(x) begin(x), end(x)
int f, k, MOD;
/*struct node{
    int l, r;
    node *lft, *rht;
    int val;
    node(int tl, int tr): l(tl), r(tr), val(1) {
        if (l + 1 == r) {
            lft = rht = NULL;
            return;
        }
        lft = new node(l, (l + r) / 2);
        rht = new node((l + r) / 2, r);
    }

    void upd(int x, int tval) {
        if (x < l || x >= r) return;
        if (l + 1 == r) {
            val = tval % MOD;
            return;
        }
        lft->upd(x, tval);
        rht->upd(x, tval);
        val = (lft->val * rht->val) % MOD;
    }

    int fnd(int tl, int tr) {
        if (tr <= l || r <= tl) return 1;
        if (tl <= l && r <= tr) return val;
        return (lft->fnd(tl, tr) * rht->fnd(tl, tr)) % MOD;
    }
} *root;*/

int val[2000069];
void upd(int x, int l, int r, int pos, int tval) {
    if (pos < l || pos >= r) return;
    if (l + 1 == r) {
        val[x] = tval % MOD;
        return;
    }
    upd(x * 2, l, (l + r) / 2, pos, tval);
    upd(x * 2 + 1, (l + r) / 2, r, pos, tval);
    val[x] = (val[x * 2] * val[x * 2 + 1]) % MOD;
}

int fnd(int x, int l, int r, int tl, int tr) {
    if (tr <= l || r <= tl) return 1;
    if (tl <= l && r <= tr) return val[x];
    return (fnd(x * 2, l, (l + r) / 2, tl, tr) * fnd(x * 2 + 1, (l + r) / 2, r, tl, tr)) % MOD;
}

int ans;
int maxi[500069], loc[500069];
int chng[500069];
int cnt[500069];
vector<int> vals[500069];
priority_queue<pair<int,int>> pq;
vector<pair<int,int>> ord;
signed main() {
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    // freopen("fish.in", "r", stdin);
    // freopen("fish.out", "w", stdout);
    cin>>f>>k>>MOD;
    //root = new node(0, k);
    for (int i = 0; i < f; i++) {
        int a, b;
        cin>>a>>b; b--;
        maxi[b] = max(maxi[b], a);
        vals[b].push_back(a);
        pq.push({a, b});
    }
    for (int i = 0; i < k; i++) {
        ord.push_back({maxi[i], i});
    }
    sort(all(ord));
    for (int i = 0; i < k; i++) loc[ord[i].s] = i;
    for (int i = 0; i < k; i++) {
        sort(all(vals[i]));
        int t = *upper_bound(all(vals[i]), *vals[i].rbegin() / 2);
        chng[loc[i]] = lower_bound(all(ord), make_pair(t * 2, INT_MIN)) - begin(ord);
        cnt[loc[i]] = vals[i].size();
        //root->upd(loc[i], cnt[loc[i]] + 1);
        upd(1, 0, k, loc[i], cnt[loc[i]] + 1);
    }
    for (int i = k - 1; ~i; i--) {
        while (pq.size()) {
            auto t = pq.top();
            if (t.f * 2 <= ord[i].f) break;
            pq.pop();
            int pos = loc[t.s];
            cnt[pos]--;
            //root->upd(pos, cnt[pos] + 1);
            upd(1, 0, k, pos, cnt[pos] + 1);
        }

        //root->upd(i, 1);
        upd(1, 0, k, i, 1);
        //ans = (ans + root->fnd(0, chng[i])) % MOD;
        ans = (ans + fnd(1, 0, k, 0, chng[i])) % MOD;
        //root->upd(i, cnt[i]);
        upd(1, 0, k, i, cnt[i]);
        //ans = (ans + root->fnd(0, i + 1)) % MOD;
        ans = (ans + fnd(1, 0, k, 0, i + 1)) % MOD;
        //root->upd(i, cnt[i] + 1);
        upd(1, 0, k, i, cnt[i] + 1);
    }
    cout<<ans<<endl;
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 7 ms 11988 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 12072 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 12068 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 11988 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 12116 KB Output is correct
2 Correct 8 ms 12080 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 12080 KB Output is correct
2 Correct 152 ms 18648 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 12116 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 12116 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 93 ms 15080 KB Output is correct
2 Correct 88 ms 16068 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 12244 KB Output is correct
2 Correct 8 ms 12212 KB Output is correct
3 Correct 9 ms 12212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 110 ms 18048 KB Output is correct
2 Correct 211 ms 18776 KB Output is correct
3 Correct 203 ms 19800 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 213 ms 19312 KB Output is correct
2 Correct 181 ms 19524 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 140 ms 18168 KB Output is correct
2 Correct 199 ms 19400 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 219 ms 19168 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 267 ms 20520 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 252 ms 20348 KB Output is correct
2 Correct 422 ms 25280 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 550 ms 28616 KB Output is correct
2 Correct 429 ms 27308 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 441 ms 29756 KB Output is correct
2 Correct 504 ms 25432 KB Output is correct
3 Correct 562 ms 32680 KB Output is correct
4 Correct 495 ms 25476 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 671 ms 31408 KB Output is correct
2 Correct 1060 ms 54832 KB Output is correct
3 Correct 1038 ms 55828 KB Output is correct
4 Correct 1008 ms 50332 KB Output is correct