Submission #401386

# Submission time Handle Problem Language Result Execution time Memory
401386 2021-05-10T05:55:14 Z ja_kingy Fish (IOI08_fish) C++14
88 / 100
665 ms 50760 KB
#include <bits/stdc++.h>
using namespace std;

typedef pair<int,int> pii;
const int mxF = 5e5;
int f,k,m,cnt[mxF],ord[mxF],st[1<<20],ans;
vector<int> of_type[mxF];

void upd(int x, int v) {
    st[x += k] = v;
    for (; x/=2; ) st[x] = st[x*2]*st[x*2+1]%m; 
}

int qry(int l, int r) {
    int res = 1;
    for (l += k, r += k; l < r; l/=2, r/=2) {
        if (l&1) res=res*st[l++]%m;
        if (r&1) res=res*st[--r]%m;
    }
    return res;
}

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    fill(st, end(st), 1);
    cin >> f >> k >> m;
    vector<pii> fish(f);
    for (int i = 0,l,x; i < f; ++i) {
        cin >> l >> x;
        x--;
        of_type[x].push_back(l);
        fish[i] = {l, x};
    }
    sort(fish.begin(), fish.end());
    for (int x = 0; x < k; ++x) sort(of_type[x].begin(), of_type[x].end());
    vector<pii> types(k);
    for (int i = 0; i < k; ++i) {
        types[i] = {of_type[i].back(), i};
    }    
    sort(types.begin(), types.end());
    for (int i = 0; i < k; ++i) ord[types[i].second] = i;
    int smallest = 0;
    for (auto [l,x]: types) {
        while (fish[smallest].first <= l/2) {
            cnt[fish[smallest].second]++;
            upd(ord[fish[smallest].second], cnt[fish[smallest].second]+1);
            smallest++;
        }
        int ltm = qry(0, ord[x]);
        ans = (ans+(ltm*cnt[x]))%m;
        int sm_of_type = *upper_bound(of_type[x].begin(), of_type[x].end(), l/2);
        ans = (ans+(ltm*qry(ord[x]+1, lower_bound(types.begin(), types.end(), make_pair(2*sm_of_type,0))-types.begin())))%m;
    }
    cout << ans;
}

Compilation message

fish.cpp: In function 'int main()':
fish.cpp:44:15: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   44 |     for (auto [l,x]: types) {
      |               ^
# Verdict Execution time Memory Grader output
1 Correct 10 ms 16076 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 11 ms 16176 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 12 ms 16076 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 11 ms 16156 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 11 ms 16128 KB Output is correct
2 Correct 13 ms 16076 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 12 ms 16164 KB Output is correct
2 Correct 206 ms 22580 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 11 ms 16204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 12 ms 16200 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 81 ms 19084 KB Output is correct
2 Correct 114 ms 19656 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 12 ms 16204 KB Output is correct
2 Correct 15 ms 16248 KB Output is correct
3 Correct 13 ms 16312 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 135 ms 20492 KB Output is correct
2 Incorrect 237 ms 22448 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 192 ms 23280 KB Output is correct
2 Correct 248 ms 30384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 130 ms 20668 KB Output is correct
2 Correct 231 ms 29804 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 238 ms 22896 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 263 ms 23828 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 213 ms 22716 KB Output is correct
2 Correct 306 ms 26040 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 400 ms 27228 KB Output is correct
2 Correct 308 ms 30404 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 313 ms 28432 KB Output is correct
2 Correct 397 ms 34196 KB Output is correct
3 Incorrect 422 ms 37176 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 505 ms 29620 KB Output is correct
2 Correct 578 ms 50760 KB Output is correct
3 Correct 665 ms 49824 KB Output is correct
4 Correct 660 ms 46888 KB Output is correct