Submission #448618

# Submission time Handle Problem Language Result Execution time Memory
448618 2021-07-31T07:42:19 Z prvocislo Fish (IOI08_fish) C++17
4 / 100
416 ms 37156 KB
#include <iostream>
#include <vector>
#include <algorithm>
typedef long long ll;
using namespace std;

int f, k, m;
void add(int& a, const int& b) { a += b; if (a >= m) a -= m; }
int mul(const int& a, const int& b) { return (a * b) % m; }
//const int maxn = 1 << 19, inf = 1e9 + 5;
const int maxn = 4, inf = 1e9 + 5;
vector<int> st(maxn * 2, 1);
void upd(int i)
{
    add(st[i += maxn], 1);
    for (i = (i >> 1); i > 0; i >>= 1) st[i] = mul(st[i << 1], st[i << 1 | 1]);
}
int query(int l, int r)
{
    int ans = 1;
    for (l += maxn, r += maxn+1; l < r; l >>= 1, r >>= 1)
    {
        if (l & 1) ans = mul(ans, st[l++]);
        if (r & 1) ans = mul(ans, st[--r]);
    }
    return ans;
}
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin >> f >> k >> m;
    vector<pair<int, int> > fish(f);
    vector<int> longest(k, -1), order(k, -1);
    vector<bool> is_long(f, false);
    vector<vector<int> > typ(k, vector<int>(1, inf));
    for (int i = 0; i < f; i++) cin >> fish[i].first >> fish[i].second, fish[i].second--;
    int num = k;
    sort(fish.begin(), fish.end());
    for (int i = f - 1; i >= 0; i--)
    {
        if (order[fish[i].second] == -1)
        {
            is_long[i] = true;
            order[fish[i].second] = --num;
            longest[num] = fish[i].first;
        }
        fish[i].second = order[fish[i].second];
        typ[fish[i].second].push_back(fish[i].first);
    }
    int j = -1, ans = 0;
    for (int i = 0; i < f; i++) if (is_long[i])
    {
        while (fish[j + 1].first * 2 <= fish[i].first)
            upd(fish[++j].second), typ[fish[j].second].pop_back();
        //cout << query(0, fish[i].second) << "\n";
        add(ans, mul(query(0, fish[i].second-1), (m + st[maxn+fish[i].second] - 1) % m));
        int r = lower_bound(longest.begin(), longest.end(), typ[fish[i].second].back() * 2) - longest.begin() - 1;
        //cout << query(0, fish[i].second - 1) << "*" << query(fish[i].second + 1, r) << "\n";
        add(ans,  mul(query(0, fish[i].second - 1), query(fish[i].second + 1, r)));
    }
    cout << ans << "\n";
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 204 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 204 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 204 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Runtime error 1 ms 460 KB Execution killed with signal 6
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Runtime error 178 ms 6976 KB Execution killed with signal 6
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 460 KB Execution killed with signal 6
# Verdict Execution time Memory Grader output
1 Runtime error 3 ms 588 KB Execution killed with signal 6
# Verdict Execution time Memory Grader output
1 Runtime error 68 ms 3328 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 460 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 134 ms 4712 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 192 ms 7140 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 112 ms 4732 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 199 ms 7364 KB Execution killed with signal 6
# Verdict Execution time Memory Grader output
1 Runtime error 229 ms 8488 KB Execution killed with signal 6
# Verdict Execution time Memory Grader output
1 Runtime error 212 ms 15952 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 316 ms 30436 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 293 ms 30696 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 416 ms 37156 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -