Submission #688456

# Submission time Handle Problem Language Result Execution time Memory
688456 2023-01-27T13:21:39 Z finn__ Fish (IOI08_fish) C++17
0 / 100
641 ms 23468 KB
#include <bits/stdc++.h>
using namespace std;

class SegmentTree
{
    vector<unsigned> t;
    size_t l, m;

public:
    SegmentTree(size_t _n, size_t _m)
    {
        l = 1 << (32 - __builtin_clz(_n));
        m = _m;
        t = vector<unsigned>(2 * l, 1);
    }

    void update(size_t i, unsigned x)
    {
        i += l;
        t[i] = x % m;

        while (i >>= 1)
            t[i] = (t[2 * i] * t[2 * i + 1]) % m;
    }

    unsigned range_prod(size_t i, size_t j)
    {
        if (j > l)
            return 1;
        unsigned x = 1;
        i += l, j += l;

        while (i <= j)
        {
            if (i & 1)
                x = (x * t[i++]) % m;
            if (!(j & 1))
                x = (x * t[j--]) % m;
            i >>= 1;
            j >>= 1;
        }

        return x;
    }
};

int main()
{
    size_t n, k, m;
    cin >> n >> k >> m;

    vector<pair<unsigned, unsigned>> fish(n), largest(k, {0, 0});
    for (auto &[l, g] : fish)
    {
        cin >> l >> g;
        g--;
        largest[g] = max(largest[g], {l, g});
    }

    sort(fish.begin(), fish.end());
    sort(largest.begin(), largest.end());

    vector<vector<unsigned>> v(k);
    for (auto const &[l, g] : fish)
    {
        v[g].push_back(l);
    }

    vector<unsigned> t(k), c(k, 0);
    for (size_t i = 0; i < k; i++)
    {
        t[largest[i].second] = i;
    }

    size_t j = 0;
    SegmentTree tree(k, m);
    unsigned ans = 0;

    for (auto const &[l, g] : largest)
    {
        while (j < n && 2 * fish[j].first <= l)
        {
            c[fish[j].second]++;
            tree.update(t[fish[j].second], c[fish[j].second]);
            j++;
        }

        unsigned a = t[g] + 1, b = k - 1;

        // Binary search over larger fishes for the greatest fish that cannot
        // catch more fish of type g.
        while (a <= b)
        {
            unsigned mid = (a + b) / 2;
            if (upper_bound(v[g].begin(), v[g].end(), largest[mid].first / 2) - v[g].begin() <= c[g])
            {
                a = mid + 1;
            }
            else
            {
                b = mid - 1;
            }
        }

        tree.update(t[g], 1);
        ans = (ans + tree.range_prod(0, a - 1) +
               (c[g] % m) * tree.range_prod(0, t[g])) %
              m;
        tree.update(t[g], c[g] + 1);
    }

    cout << ans << '\n';
}
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Incorrect 1 ms 212 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Incorrect 341 ms 6760 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 336 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 126 ms 3136 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 468 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 212 ms 4696 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 339 ms 7032 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 215 ms 7516 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 332 ms 10264 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 388 ms 11464 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 326 ms 11224 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 641 ms 19836 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 408 ms 20780 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 608 ms 23468 KB Output isn't correct
2 Halted 0 ms 0 KB -