# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
923220 | math_rabbit_1028 | Fish (IOI08_fish) | C++14 | 3072 ms | 30292 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> pii;
typedef long long ll;
int n, k, MOD;
vector<int> vec[505050];
ll dp[505050][2];
int p[505050];
bool compare(vector<int> A, vector<int> B) {
return A.back() > B.back();
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cin >> n >> k >> MOD;
for (int i = 1; i <= n; i++) {
int l, t;
cin >> l >> t;
vec[t].push_back(l);
}
for (int i = 1; i <= k; i++) sort(vec[i].begin(), vec[i].end());
sort(vec + 1, vec + k + 1, compare);
for (int j = 1; j <= k; j++) p[j] = vec[j].size();
for (int i = 1; i <= k; i++) {
dp[i][0] = dp[i][1] = 1;
int cnt = upper_bound(vec[i].begin(), vec[i].end(), vec[i].back()/2) - vec[i].begin();
int q = 0;
for (int j = k; j >= 1; j--) {
if (i == j) continue;
while (q < vec[i].size() && vec[i][q] <= vec[j].back()/2) q++;
while (p[j] > 0 && vec[j][p[j]-1] > vec[i].back()/2) p[j]--;
if (i < j) {
dp[i][0] = dp[i][0]*(1+p[j])%MOD;
dp[i][1] = dp[i][1]*(1+p[j])%MOD;
}
else {
if (q > cnt) continue;
dp[i][0] = dp[i][0]*(1+p[j])%MOD;
}
}
//cout << dp[i][0] << " " << dp[i][1] << "\n";
}
ll ans = 0;
for (int i = 1; i <= k; i++) {
ans += dp[i][0] + dp[i][1] - 1;
ans %= MOD;
}
cout << ans << "\n";
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |