Submission #446063

# Submission time Handle Problem Language Result Execution time Memory
446063 2021-07-20T15:57:45 Z lohacho Fish (IOI08_fish) C++14
48 / 100
1363 ms 65540 KB
#include <bits/stdc++.h>
#define int long long
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(1ll, 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(long long int, long long int, long long int, long long int, long long int)':
fish.cpp:22:19: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   22 |         int m = s + e >> 1;
      |                 ~~^~~
fish.cpp: In member function 'long long int Seg::get(long long int, long long int, long long int, long long int, long long 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 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 0 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 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 Runtime error 33 ms 65540 KB Execution killed with signal 9
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 844 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 177 ms 26936 KB Output is correct
2 Correct 211 ms 33600 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 588 KB Output is correct
2 Incorrect 8 ms 1120 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 325 ms 40260 KB Output is correct
2 Runtime error 38 ms 65540 KB Execution killed with signal 9
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 39 ms 65540 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 299 ms 40356 KB Output is correct
2 Runtime error 35 ms 65540 KB Execution killed with signal 9
# Verdict Execution time Memory Grader output
1 Correct 613 ms 61528 KB Output is correct
# Verdict Execution time Memory Grader output
1 Runtime error 36 ms 65540 KB Execution killed with signal 9
# Verdict Execution time Memory Grader output
1 Correct 685 ms 54468 KB Output is correct
2 Runtime error 35 ms 65540 KB Execution killed with signal 9
# Verdict Execution time Memory Grader output
1 Correct 1363 ms 65536 KB Output is correct
2 Correct 1010 ms 42584 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1107 ms 64652 KB Output is correct
2 Runtime error 35 ms 65540 KB Execution killed with signal 9
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 34 ms 65540 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -