Submission #401384

# Submission time Handle Problem Language Result Execution time Memory
401384 2021-05-10T05:53:01 Z ja_kingy Fish (IOI08_fish) C++14
37 / 100
526 ms 27372 KB
#include <bits/stdc++.h>
using namespace std;

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

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

int qry(int l, int r) {
    int res = 1;
    for (l += SZ, r += SZ; 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);
    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:43:15: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   43 |     for (auto [l,x]: types) {
      |               ^
# Verdict Execution time Memory Grader output
1 Incorrect 8 ms 12108 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 12108 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 8 ms 12108 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Incorrect 8 ms 12108 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Correct 10 ms 12076 KB Output is correct
2 Correct 10 ms 12108 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 12064 KB Output is correct
2 Correct 228 ms 18680 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 8 ms 12108 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Correct 10 ms 12164 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 95 ms 15168 KB Output is correct
2 Correct 130 ms 15788 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 10 ms 12236 KB Output is correct
2 Incorrect 11 ms 12236 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 157 ms 16644 KB Output is correct
2 Correct 260 ms 18672 KB Output is correct
3 Correct 256 ms 25196 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 230 ms 19448 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 139 ms 16900 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 228 ms 18932 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 254 ms 20036 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Correct 214 ms 19276 KB Output is correct
2 Incorrect 303 ms 22104 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Incorrect 403 ms 24488 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 322 ms 25668 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 526 ms 27372 KB Output isn't correct
2 Halted 0 ms 0 KB -