제출 #1302265

#제출 시각아이디문제언어결과실행 시간메모리
1302265nicolo_010말 (IOI15_horses)C++20
34 / 100
1597 ms29436 KiB
#include <bits/stdc++.h>
#include "horses.h"
using namespace std;
using ll = long long;
using pii = pair<int, int>;
const int MOD = 1e9+7;

const ll INF = 1e18;

vector<ll> x;
vector<ll> y;
int n;

ll compute(vector<ll> a, vector<ll> b) {
	int idx=0;
	ll prod=1;
	bool moduled = false;
	for (int i=1; i<(int)a.size(); i++) {
		ll y0 = b[idx];
		ll y1 = b[i];
		prod *= x[i];
		if (prod >= MOD) {
			moduled = true;
			prod %= MOD;
		}
		if (moduled) {
			//Se que y[i] <= y[j]*prod
			//Conviene j
			idx = i;
			moduled = 0;
			prod = 1;
		}
		else {
			if (prod*y1 >= y0) {
				idx = i;
				prod = 1;
				moduled = false;
			}
		}
	}
	prod=a[0];
	for (int i=1; i<n; i++) {
		if (i > idx) break;
		prod *= a[i];
		prod %= MOD;
	}
	return (prod*b[idx]) % MOD;
}

int init(int N, int* a, int* b) {
	n = N;
	x.assign(n, 0);
	y.assign(n, 0);
	for (int i=0; i<n; i++) {
		x[i] = a[i];
		y[i] = b[i];
	}
	n = N;
	vector<ll> xx, yy;
	xx.push_back(x[0]);
	yy.push_back(y[0]);
	for (int i=1; i<n; i++) {
		if (x[i] == 1) {
			yy.back() = max(yy.back(), (ll)y[i]);
		}
		else {
			xx.push_back(x[i]);
			yy.push_back(y[i]);
		}
	}
	return compute(x, y);
}

int updateX(int pos, int val) {
	x[pos] = val;
	vector<ll> xx, yy;
	xx.push_back(x[0]);
	yy.push_back(y[0]);
	for (int i=1; i<n; i++) {
		if (x[i] == 1) {
			yy.back() = max(yy.back(), (ll)y[i]);
		}
		else {
			xx.push_back(x[i]);
			yy.push_back(y[i]);
		}
	}
	return compute(x, y);
}

int updateY(int pos, int val) {
	y[pos] = val;
	vector<ll> xx, yy;
	xx.push_back(x[0]);
	yy.push_back(y[0]);
	for (int i=1; i<n; i++) {
		if (x[i] == 1) {
			yy.back() = max(yy.back(), (ll)y[i]);
		}
		else {
			xx.push_back(x[i]);
			yy.push_back(y[i]);
		}
	}
	return compute(x, y);
}
#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...