Submission #446065

# Submission time Handle Problem Language Result Execution time Memory
446065 2021-07-20T16:10:24 Z lohacho Fish (IOI08_fish) C++14
89 / 100
2407 ms 45732 KB
#include <bits/stdc++.h>

using namespace std;
 
int mod;
 
struct Seg{
    int n;
    vector<int> tree;
    vector<int> a;
    Seg(int N):n(N + 1){
        tree = vector<int>(n * 4 + 4, 1);
        a = vector<int>(n, 0);
    }
    void push(int x, int s, int e, int pos, int val){
        if(pos < s || pos > e) return;
        if(s == e){
            a[s] += val;
            tree[x] = max(1, a[s] + 1) % mod;
            return;
        }
        int m = s + e >> 1;
        push(x * 2, s, m, pos, val), push(x * 2 + 1, m + 1, e, pos, val);
        tree[x] = tree[x * 2] * tree[x * 2 + 1] % mod;
    }
    int get(int x, int s, int e, int fs, int fe){
        if(fs > fe || fe < s || fs > e) return 1;
        if(fs <= s && fe >= e){
            return tree[x];
        }
        int m = s + e >> 1;
        return get(x * 2, s, m, fs, fe) * get(x * 2 + 1, m + 1, e, fs, fe) % mod;
    }
};
 
signed main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int n, k;
    cin >> n >> k >> mod;
    Seg tree(n + 4), zero(n + 4), seg(n + 4);
    vector<pair<int, int>> a(n);
    for(int i = 0; i < n; ++i){
        cin >> a[i].first >> a[i].second;
        zero.push(1, 1, k, a[i].second, 1), tree.push(1, 1, k, a[i].second, 1);
    }
    sort(a.begin(), a.end());
    int pos = n - 1, ans = 0;
    vector<int> chk(k + 1, n), did(k + 1);
    for(int i = n - 1; i >= 0; --i){
        while(pos >= 0 && a[pos].first * 2 > a[i].first){
            tree.push(1, 1, k, a[pos].second, -1), zero.push(1, 1, k, a[pos].second, -1);
            if(did[a[pos].second]) seg.push(1, 1, n, did[a[pos].second], -1);
            if(i < n - 1) chk[a[pos].second] = i;
            --pos;
        }
        if(did[a[i].second]) continue;
        zero.push(1, 1, k, a[i].second, 1);
        ans = (zero.get(1, 1, k, 1, k) - zero.get(1, 1, k, 1, a[i].second - 1) * zero.get(1, 1, k, a[i].second + 1, k) % mod + ans + mod) % mod;
        zero.push(1, 1, k, a[i].second, -1);
        if(i < n - 1){
            ans = (zero.get(1, 1, k, 1, a[i].second - 1) * zero.get(1, 1, k, a[i].second + 1, k) % mod
            * (seg.get(1, 1, n, i + 1, min(chk[a[i].second], n)) - 1) + ans) % mod;
        }
        seg.push(1, 1, n, i, tree.get(1, 1, k, a[i].second, a[i].second) - 1);
        zero.push(1, 1, k, a[i].second, -n);
        did[a[i].second] = i;
    }
    cout << ans;
    return 0;
}

Compilation message

fish.cpp: In member function 'void Seg::push(int, int, int, int, int)':
fish.cpp:22:19: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   22 |         int m = s + e >> 1;
      |                 ~~^~~
fish.cpp: In member function 'int Seg::get(int, int, int, int, int)':
fish.cpp:31:19: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   31 |         int m = s + e >> 1;
      |                 ~~^~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 354 ms 39636 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 588 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 172 ms 13644 KB Output is correct
2 Correct 215 ms 16956 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 436 KB Output is correct
2 Incorrect 8 ms 660 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 319 ms 20264 KB Output is correct
2 Correct 568 ms 40360 KB Output is correct
3 Correct 557 ms 40304 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 532 ms 39688 KB Output is correct
2 Correct 600 ms 40516 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 291 ms 20292 KB Output is correct
2 Correct 651 ms 40608 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 616 ms 30280 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 740 ms 41108 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 650 ms 27340 KB Output is correct
2 Correct 1020 ms 42144 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1259 ms 32456 KB Output is correct
2 Correct 932 ms 21428 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1032 ms 31436 KB Output is correct
2 Correct 1162 ms 42136 KB Output is correct
3 Incorrect 1386 ms 41780 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1469 ms 43192 KB Output is correct
2 Correct 1919 ms 44736 KB Output is correct
3 Correct 2407 ms 45732 KB Output is correct
4 Correct 2152 ms 44836 KB Output is correct