Submission #734011

# Submission time Handle Problem Language Result Execution time Memory
734011 2023-05-01T13:33:22 Z lorenzoferrari Fish (IOI08_fish) C++17
0 / 100
3000 ms 43720 KB
#include "bits/stdc++.h"
using namespace std;

#define int long long

static constexpr int N = 5e5+5;

struct fish {
    int l;
    int g;
    bool operator<(const fish& oth) {
        return l < oth.l;
    }
};

static int f[N];    // frq of each colour
static int ff[N];   // frq of each frq
set<int> s;         // {j | ff[j] != 0}
vector<int> pw[N];

static void inc(int c, int m) {
    if (ff[f[c]] == 1) {
        s.erase(f[c]);
    }
    --ff[f[c]];
    ++f[c];
    ++ff[f[c]];
    if (ff[f[c]] == 1) {
        s.insert(f[c]);
    }
    pw[f[c]+1].emplace_back(pw[f[c]+1].back() * ((f[c]+1) % m) % m);
}

static int calc(int m) {
    int ans = 1;
    for (int j : s) {
        ans = ans * pw[j+1][ff[j]] % m;
    }
    return ans;
}

signed main() {
    for (int i = 0; i < N; ++i) {
        pw[i].emplace_back(1);
    }

    int n; cin >> n;
    int k; cin >> k;
    int m; cin >> m;
    vector<fish> a(n);
    for (int i = 0; i < n; ++i) {
        cin >> a[i].l >> a[i].g; --a[i].g;
    }
    sort(begin(a), end(a));
    vector<int> last(k);
    for (int i = 0; i < n; ++i) {
        last[a[i].g] = i;
    }

    int ans = 0;
    vector<int> d(n);
    vector<int> rs;
    for (int r = 0, l = 0; r < n; ++r) {
        if (last[a[r].g] != r) continue;
        while (2*a[l].l <= a[r].l) {
            if (last[a[l].g] < r) {
                inc(a[l].g, m);
            } else {
                ++d[last[a[l].g]];
            }
            ++l;
        }
        while (d[r]--) {
            inc(a[r].g, m);
        }

        rs.push_back(r);

        int cur = 1;
        for (int i : rs) {
            cur = (cur * (f[a[i].g]+1)) % m;
        }
        ans += cur;
        ans %= m;
        
        // ans = (ans + calc(m)) % m;
    }
    
    cout << ans << "\n";
}

Compilation message

fish.cpp:34:12: warning: 'long long int calc(long long int)' defined but not used [-Wunused-function]
   34 | static int calc(int m) {
      |            ^~~~
# Verdict Execution time Memory Grader output
1 Incorrect 27 ms 27604 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 37 ms 27604 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 31 ms 27584 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 29 ms 27644 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 27 ms 27604 KB Output is correct
2 Incorrect 27 ms 27732 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 27 ms 27712 KB Output is correct
2 Incorrect 402 ms 42768 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 30 ms 27664 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 28 ms 27800 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 168 ms 33512 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 52 ms 27796 KB Output is correct
2 Correct 44 ms 27892 KB Output is correct
3 Incorrect 44 ms 27896 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 251 ms 36552 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 375 ms 43720 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 324 ms 36108 KB Output is correct
2 Incorrect 509 ms 42296 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 680 ms 41068 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1241 ms 42436 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 3058 ms 39476 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 3078 ms 41260 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 3067 ms 41308 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 3075 ms 43352 KB Time limit exceeded
2 Halted 0 ms 0 KB -