Submission #989582

# Submission time Handle Problem Language Result Execution time Memory
989582 2024-05-28T10:55:58 Z huutuan Fish (IOI08_fish) C++14
32 / 100
3000 ms 65536 KB
#include<bits/stdc++.h>

using namespace std;

const int N=5e5+10;
int n, m, mod;
pair<int, int> a[N];
int cnt[N], cnt2[N], lst[N];

int solve(vector<pair<int, int>> v){
   if (v.empty()) return 0;
   int z=v.back().second;
   for (int i=1; i<=m; ++i) cnt[i]=cnt2[i]=lst[i]=0;
   for (auto &i:v) if (i.first*2<=v.back().first) ++cnt[i.second];
   int ans=accumulate(cnt+1, cnt+m+1, 1ll, [&](int x, int y){ return x*(y+1)%mod; });
   for (int i=0; i<(int)v.size(); ++i) lst[v[i].second]=i;
   for (int i=0, j=-1; i<(int)v.size(); ++i){
      while (v[j+1].first*2<=v[i].first){
         ++j;
         ++cnt2[v[j].second];
      }
      if (v[i].second!=z && cnt2[v[i].second]>=cnt[v[i].second] && lst[v[i].second]==i){
         int prod=(cnt2[v[i].second]-cnt[v[i].second]+1);
         for (int k=1; k<=m; ++k) if (k!=v[i].second) prod=prod*(cnt2[k]+1-(k==z))%mod;
         ans=(ans+prod)%mod;
      }
   }
   vector<pair<int, int>> v2;
   for (auto &i:v) if (i.second!=z) v2.push_back(i);
   return (ans+solve(v2))%mod;
}

int32_t main(){
   ios_base::sync_with_stdio(false);
   cin.tie(nullptr);
   cin >> n >> m >> mod;
   for (int i=1; i<=n; ++i) cin >> a[i].first >> a[i].second;
   sort(a+1, a+n+1);
   cout << solve(vector<pair<int, int>>(a+1, a+n+1)) << '\n';
   return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 604 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Runtime error 159 ms 65536 KB Execution killed with signal 9
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 1372 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 2140 KB Output is correct
# Verdict Execution time Memory Grader output
1 Runtime error 102 ms 65536 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 3069 ms 5704 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 199 ms 65536 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 140 ms 65536 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 643 ms 65536 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 3028 ms 49872 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 3044 ms 24116 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 3033 ms 7248 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 3058 ms 9044 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 3011 ms 9164 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 3093 ms 10580 KB Time limit exceeded
2 Halted 0 ms 0 KB -