Submission #989585

# Submission time Handle Problem Language Result Execution time Memory
989585 2024-05-28T11:04:35 Z huutuan Fish (IOI08_fish) C++14
32 / 100
3000 ms 22820 KB
#include<bits/stdc++.h>

using namespace std;

const int N=5e5+10, S=750;
int n, m, mod;
pair<int, int> a[N];
int cnt[N], cnt2[N], lst[N];
vector<pair<int, int>> v, v2;
int prod[S];

int solve(){
   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; i<S; ++i) prod[i]=1;
   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];
         int id=v[j].second/S;
         for (int k=0; k<S; ++k) prod[id]=prod[id]*(cnt2[id*S+k]+1)%mod;
      }
      if (v[i].second!=z && cnt2[v[i].second]>=cnt[v[i].second] && lst[v[i].second]==i){
         int cur=(cnt2[v[i].second]-cnt[v[i].second]+1);
         int id1=v[i].second/S, id2=z/S;
         for (int k=0; k<S; ++k) if (k!=id1 && k!=id2) cur=cur*prod[k]%mod;
         for (int k=id1*S; k<(id1+1)*S; ++k) if (k!=v[i].second) cur=cur*(cnt2[k]+1-(k==z))%mod;
         if (id1!=id2) for (int k=id2*S; k<(id2+1)*S; ++k) if (k!=v[i].second) cur=cur*(cnt2[k]+1-(k==z))%mod;
         ans=(ans+cur)%mod;
      }
   }
   v2.clear();
   for (auto &i:v) if (i.second!=z) v2.push_back(i);
   v.swap(v2);
   return (ans+solve())%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);
   v=vector<pair<int, int>>(a+1, a+n+1);
   cout << solve() << '\n';
   return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 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
# Verdict Execution time Memory Grader output
1 Correct 1 ms 604 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 15 ms 488 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 344 KB Output is correct
2 Execution timed out 3037 ms 18768 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 96 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 182 ms 604 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 3058 ms 8212 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 3053 ms 596 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 3003 ms 13260 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 3042 ms 18632 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 3041 ms 13752 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 3024 ms 18084 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 3059 ms 20276 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 3036 ms 17540 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 3047 ms 20428 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 3017 ms 18660 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 3035 ms 22820 KB Time limit exceeded
2 Halted 0 ms 0 KB -