Submission #734003

# Submission time Handle Problem Language Result Execution time Memory
734003 2023-05-01T13:13:27 Z lorenzoferrari Fish (IOI08_fish) C++17
0 / 100
490 ms 59948 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].push_back(pw[f[c]+1].back() * ((f[c]+1) % m) % m);
}

static void dec(int c, int m) {
    assert(f[c]);
    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].push_back(pw[f[c]+1].back() * ((f[c]+1) % m) % m);
}

static int calc(int c, 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<vector<int>> fut(n);
    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 {
                fut[last[a[l].g]].push_back(l);
            }
            ++l;
        }
        for (int i : fut[r]) {
            inc(a[i].g, m);
        }
        ans += calc(a[r].g, m);
        if (ans >= m) ans -= m;
    }
    
    cout << ans << "\n";
}

Compilation message

fish.cpp:34:13: warning: 'void dec(long long int, long long int)' defined but not used [-Wunused-function]
   34 | static void dec(int c, int m) {
      |             ^~~
# 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 30 ms 27684 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 29 ms 27700 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 26 ms 27708 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 29 ms 27708 KB Output is correct
2 Incorrect 30 ms 27716 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 30 ms 27640 KB Output is correct
2 Incorrect 392 ms 53516 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 40 ms 27716 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 33 ms 27952 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 179 ms 38504 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 28 ms 27876 KB Output is correct
2 Correct 31 ms 28084 KB Output is correct
3 Incorrect 45 ms 27864 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 301 ms 43752 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 374 ms 58184 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 274 ms 41484 KB Output is correct
2 Incorrect 414 ms 53656 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 377 ms 52280 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 421 ms 53936 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 349 ms 49108 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 449 ms 54820 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 368 ms 56636 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 490 ms 59948 KB Output isn't correct
2 Halted 0 ms 0 KB -