Submission #1017012

# Submission time Handle Problem Language Result Execution time Memory
1017012 2024-07-08T17:08:37 Z huutuan Fish (IOI08_fish) C++14
43 / 100
3000 ms 30036 KB
#include<bits/stdc++.h>

using namespace std;

const int N=5e5+10;
int n, m, mod, mx[N], cnt[N], f[N], vis[N], cnt2[N];
vector<int> v[N];
pair<int, int> a[N];

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);
   for (int i=1; i<=n; ++i) mx[a[i].second]=i, ++cnt[a[i].second], f[a[i].second]=1;
   for (int i=1; i<=n; ++i) if (a[i].first*2<=a[mx[a[i].second]].first) ++f[a[i].second];
   int ans=0;
   for (int i=n, j=n; i>=1; --i) if (mx[a[i].second]==i){
      while (j && a[j].first*2>a[i].first){
         --cnt[a[j].second];
         --j;
      }
      {
         int cur=1;
         for (int k=1; k<=m; ++k) if (mx[k]<=i) cur=cur*(cnt[k]+1)%mod;
         ans=(ans+cur)%mod;
      }
      for (int k:v[a[i].second]) vis[k]=0;
      {
         for (int k=1; k<=m; ++k) if (mx[k]<i){
            if (f[k]>cnt[k]){
               int j2=j;
               while (j && a[j].first*2>a[mx[k]].first){
                  --cnt[a[j].second];
                  --j;
               }
               {
                  int cur=1;
                  for (int t=1; t<=m; ++t) if (mx[t]<=i){
                     if (t==a[i].second) cur=cur*cnt[t]%mod;
                     else if (t!=k) cur=cur*(cnt[t]+1)%mod;
                  }
                  ans=(ans+cur)%mod;
               }
               while (j!=j2){
                  ++j;
                  ++cnt[a[j].second];
               }
            }
         }
      }
   }
   cout << ans << '\n';
   return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 3 ms 20828 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 20824 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 20828 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 20824 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 20824 KB Output is correct
2 Correct 4 ms 20828 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 20828 KB Output is correct
2 Correct 89 ms 28308 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 20828 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 20828 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 54 ms 24656 KB Output is correct
2 Correct 60 ms 26192 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 3053 ms 20828 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 3030 ms 26448 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1317 ms 28436 KB Output is correct
2 Execution timed out 3043 ms 30036 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 3032 ms 26448 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 3062 ms 28516 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 3026 ms 29520 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 3050 ms 28244 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 3069 ms 29268 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 3061 ms 27612 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 3029 ms 30036 KB Time limit exceeded
2 Halted 0 ms 0 KB -