Submission #928045

# Submission time Handle Problem Language Result Execution time Memory
928045 2024-02-15T19:02:30 Z VMaksimoski008 Horses (IOI15_horses) C++14
17 / 100
75 ms 86656 KB
#include <bits/stdc++.h>
#include "horses.h"
 
#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
 
using namespace std;
 
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
 
const int mod = 1e9 + 7;
const int maxn = 1e5 + 5;
 
int n;
vector<ll> X(5*maxn), Y(maxn), PS(5*maxn);
vector<double> logX(5*maxn), logY(maxn), PL(5*maxn);

ll exp(ll a, ll b) {
    ll ans = 1;
    while(b) {
        if(b & 1) ans = (ans * a) % mod;
        a = (a * a) % mod;
        b /= 2;
    }
    return ans;
}

ll inv(ll x) { return exp(x, mod-2); }

struct Node {
    double lx, ly;
    int pos;
};

Node merge(Node a, Node b) {
    if(a.lx + a.ly > b.lx + b.ly) return a;
    return b;
}

struct SegTree {
    int N;
    vector<ll> prod;
    vector<Node> tree;

    void init() {
        N = n;
        prod.resize(4*N+5);
        tree.resize(4*N+5);
        build(1, 0, N-1);
    }

    void build(int u, int tl, int tr) {
        if(tl == tr) {
            tree[u].lx = PL[tl];
            tree[u].ly = logY[tl];
            tree[u].pos = tl;
            prod[u] = X[tl];
        } else {
            int tm = (tl + tr) / 2;
            build(2*u, tl, tm);
            build(2*u+1, tm+1, tr);
            prod[u] = (prod[2*u] * prod[2*u+1]) % mod;
            tree[u] = merge(tree[2*u], tree[2*u+1]);
        }
    }

    void updateProd(int u, int tl, int tr, int pos, int val) {
        if(tl == tr) {
            prod[u] = val;
        } else {
            int tm = (tl + tr) / 2;
            if(pos <= tm)
                updateProd(2*u, tl, tm, pos, val);
            else
                updateProd(2*u+1, tm+1, tr, pos, val);
            prod[u] = (prod[2*u] * prod[2*u+1]) % mod;
        }
    }

    ll getProd(int u, int tl, int tr, int l, int r) {
        if(tl > tr || l > tr || tl > r) return 1;
        if(l <= tl && tr <= r) return prod[u];
        int tm = (tl + tr) / 2;
        return (
            getProd(2*u, tl, tm, l, r) *
            getProd(2*u+1, tm+1, tr, l, r)
        ) % mod;
    }

    void updateProd(int pos, int val) { updateProd(1, 0, N-1, pos, val); }
    ll getProd(int p) { return getProd(1, 0, N-1, 0, p); } 
    int getPos() { return tree[1].pos; }
} tree;
 
int init(int N, int x[], int y[]) {
    n = N;
    for(int i=0; i<n; i++) {
        X[i] = x[i], Y[i] = y[i];
        PS[i] = X[i];
        if(i) PS[i] = (PS[i] * PS[i-1]) % mod;
        logX[i] = log10(X[i]), logY[i] = log10(y[i]);
        PL[i] = logX[i];
        if(i) PL[i] += PL[i-1];
    }

    tree.init();
    int pos = tree.getPos();
    ll ans = (tree.getProd(pos) * Y[pos]) % mod;

    return (int)ans;
}
 
int updateX(int p, int v) {
    return 1;
}
 
int updateY(int p, int v) {
    return 1;
}

// int main() {
//     int n;
//     cin >> n;
//     int x[n], y[n];
//     for(int i=0; i<n; i++) cin >> x[i];
//     for(int i=0; i<n; i++) cin >> y[i];
//     cout << init(n, x, y) << '\n';
//     cout << tree.prod[1] << '\n';
//     cout << tree.tree[1].pos << '\n';
//     return 0;
// }

Compilation message

horses.cpp: In function 'int updateX(int, int)':
horses.cpp:116:17: warning: unused parameter 'p' [-Wunused-parameter]
  116 | int updateX(int p, int v) {
      |             ~~~~^
horses.cpp:116:24: warning: unused parameter 'v' [-Wunused-parameter]
  116 | int updateX(int p, int v) {
      |                    ~~~~^
horses.cpp: In function 'int updateY(int, int)':
horses.cpp:120:17: warning: unused parameter 'p' [-Wunused-parameter]
  120 | int updateY(int p, int v) {
      |             ~~~~^
horses.cpp:120:24: warning: unused parameter 'v' [-Wunused-parameter]
  120 | int updateY(int p, int v) {
      |                    ~~~~^
# Verdict Execution time Memory Grader output
1 Correct 5 ms 17496 KB Output is correct
2 Correct 5 ms 17496 KB Output is correct
3 Correct 5 ms 17500 KB Output is correct
4 Correct 5 ms 17500 KB Output is correct
5 Correct 5 ms 17500 KB Output is correct
6 Correct 5 ms 17496 KB Output is correct
7 Correct 5 ms 17496 KB Output is correct
8 Correct 5 ms 17500 KB Output is correct
9 Correct 8 ms 17500 KB Output is correct
10 Correct 5 ms 17500 KB Output is correct
11 Correct 5 ms 17436 KB Output is correct
12 Correct 5 ms 17596 KB Output is correct
13 Correct 5 ms 17496 KB Output is correct
14 Correct 5 ms 17500 KB Output is correct
15 Correct 5 ms 17468 KB Output is correct
16 Correct 5 ms 17500 KB Output is correct
17 Correct 5 ms 17500 KB Output is correct
18 Correct 6 ms 17500 KB Output is correct
19 Correct 6 ms 17496 KB Output is correct
20 Correct 5 ms 17500 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 17500 KB Output is correct
2 Correct 5 ms 17496 KB Output is correct
3 Correct 5 ms 17500 KB Output is correct
4 Correct 5 ms 17500 KB Output is correct
5 Correct 5 ms 17500 KB Output is correct
6 Correct 6 ms 17500 KB Output is correct
7 Correct 5 ms 17500 KB Output is correct
8 Correct 5 ms 17500 KB Output is correct
9 Correct 5 ms 17496 KB Output is correct
10 Correct 5 ms 17500 KB Output is correct
11 Correct 5 ms 17676 KB Output is correct
12 Correct 5 ms 17500 KB Output is correct
13 Correct 5 ms 17496 KB Output is correct
14 Correct 6 ms 17752 KB Output is correct
15 Correct 5 ms 17500 KB Output is correct
16 Correct 5 ms 17500 KB Output is correct
17 Correct 6 ms 17500 KB Output is correct
18 Correct 5 ms 17500 KB Output is correct
19 Correct 5 ms 17500 KB Output is correct
20 Correct 5 ms 17568 KB Output is correct
21 Incorrect 5 ms 17500 KB Output isn't correct
22 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 75 ms 86656 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 5 ms 17496 KB Output is correct
2 Correct 5 ms 17500 KB Output is correct
3 Correct 5 ms 17500 KB Output is correct
4 Correct 5 ms 17664 KB Output is correct
5 Correct 5 ms 17500 KB Output is correct
6 Correct 5 ms 17680 KB Output is correct
7 Correct 6 ms 17500 KB Output is correct
8 Correct 6 ms 17500 KB Output is correct
9 Correct 6 ms 17484 KB Output is correct
10 Correct 5 ms 17692 KB Output is correct
11 Correct 5 ms 17660 KB Output is correct
12 Correct 6 ms 17500 KB Output is correct
13 Correct 5 ms 17500 KB Output is correct
14 Correct 5 ms 17500 KB Output is correct
15 Correct 5 ms 17500 KB Output is correct
16 Correct 5 ms 17496 KB Output is correct
17 Correct 5 ms 17500 KB Output is correct
18 Correct 5 ms 17688 KB Output is correct
19 Correct 7 ms 17500 KB Output is correct
20 Correct 5 ms 17500 KB Output is correct
21 Incorrect 5 ms 17500 KB Output isn't correct
22 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 5 ms 17500 KB Output is correct
2 Correct 5 ms 17500 KB Output is correct
3 Correct 5 ms 17500 KB Output is correct
4 Correct 5 ms 17500 KB Output is correct
5 Correct 5 ms 17500 KB Output is correct
6 Correct 5 ms 17500 KB Output is correct
7 Correct 6 ms 17500 KB Output is correct
8 Correct 6 ms 17496 KB Output is correct
9 Correct 6 ms 17500 KB Output is correct
10 Correct 5 ms 17496 KB Output is correct
11 Correct 5 ms 17500 KB Output is correct
12 Correct 5 ms 17688 KB Output is correct
13 Correct 5 ms 17480 KB Output is correct
14 Correct 5 ms 17500 KB Output is correct
15 Correct 5 ms 17500 KB Output is correct
16 Correct 6 ms 17500 KB Output is correct
17 Correct 5 ms 17496 KB Output is correct
18 Correct 6 ms 17496 KB Output is correct
19 Correct 6 ms 17500 KB Output is correct
20 Correct 5 ms 17684 KB Output is correct
21 Incorrect 5 ms 17500 KB Output isn't correct
22 Halted 0 ms 0 KB -