Submission #923220

#TimeUsernameProblemLanguageResultExecution timeMemory
923220math_rabbit_1028Fish (IOI08_fish)C++14
0 / 100
3072 ms30292 KiB
#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)

fish.cpp: In function 'int main()':
fish.cpp:38:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   38 |             while (q < vec[i].size() && vec[i][q] <= vec[j].back()/2) q++;
      |                    ~~^~~~~~~~~~~~~~~
#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...