Submission #529216

#TimeUsernameProblemLanguageResultExecution timeMemory
529216Cyanmond말 (IOI15_horses)C++17
34 / 100
1576 ms15908 KiB
// clang-format off
#include <bits/stdc++.h>

using i64 = int64_t;

template <typename T> bool setmax(T &v, const T a) {
    if (v < a) {
        v = a;
        return true;
    } else {
        return false;
    }
}

namespace mycode {
    int N;
    std::vector<int> X, Y;

    constexpr i64 mod = 1000000007;
    constexpr int max_v = 1000000000;

    void mul(i64 &v, i64 d) {
        v = v * d % mod;
    }

    int calc() {
        i64 v = 1;
        double best = (double)(Y[N - 1]);
        int best_pos = N - 1;
        for (int i = N - 2; i >= 0; --i) {
            v *= X[i + 1];
            if (setmax(best, (double)Y[i] / (double)v)) {
                best_pos = i;
            }
            if (v > max_v) break;
        }

        i64 ret = 1;
        for (int i = 0; i <= best_pos; ++i) {
            mul(ret, X[i]);
        }
        mul(ret, Y[best_pos]);
        return (int)ret;
    }

    int init(int n, std::vector<int> x, std::vector<int> y) {
        N = n;
        X = std::move(x);
        Y = std::move(y);
        return calc();
    }

    int updateX(int pos, int val) {
        X[pos] = val;
        return calc();
    }

    int updateY(int pos, int val) {
        Y[pos] = val;
        return calc();
    }
}

int init(int N, int X[], int Y[]) {
    std::vector<int> x(N), y(N);
    for (int i = 0; i < N; ++i) {
        x[i] = X[i];
        y[i] = Y[i];
    }
	return mycode::init(N, x, y);
}

int updateX(int pos, int val) {	
	return mycode::updateX(pos, val);
}

int updateY(int pos, int val) {
	return mycode::updateY(pos, val);
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...