Submission #446063

#TimeUsernameProblemLanguageResultExecution timeMemory
446063lohachoFish (IOI08_fish)C++14
48 / 100
1363 ms65540 KiB
#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 (stderr)

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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...