Submission #734020

# Submission time Handle Problem Language Result Execution time Memory
734020 2023-05-01T13:45:08 Z lorenzoferrari Fish (IOI08_fish) C++17
0 / 100
3000 ms 44392 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));
    for (int i = 1; i < n; ++i) {
        assert(a[i].l >= a[i-1].l);
    }
    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) {
            inc(a[l].g, m);
            ++l;
            continue;

            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 28 ms 27604 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 27 ms 27660 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 31 ms 27604 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 28 ms 27640 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 28 ms 27696 KB Output is correct
2 Incorrect 378 ms 42692 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 28 ms 27732 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 34 ms 27736 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 154 ms 33512 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 42 ms 27784 KB Output is correct
2 Correct 38 ms 27808 KB Output is correct
3 Incorrect 45 ms 27760 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 264 ms 36368 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 329 ms 43592 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 270 ms 36112 KB Output is correct
2 Incorrect 490 ms 42184 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 653 ms 41016 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1175 ms 42432 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 3064 ms 39872 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 3062 ms 42044 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 3058 ms 42348 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 3041 ms 44392 KB Time limit exceeded
2 Halted 0 ms 0 KB -