Submission #739250

# Submission time Handle Problem Language Result Execution time Memory
739250 2023-05-10T09:04:33 Z fractlpaca Horses (IOI15_horses) C++17
0 / 100
200 ms 17844 KB
#include "horses.h"
#include <vector>
#include <algorithm>
#include <cassert>

#define v vector
#define ll long long

#define MOD ((ll) 1000000007)
#define INF ((ll) 1000000001)

using namespace std;

int *x;
int *y;
int n;


// Subtask 1

// int solve() {
// 	int ma = 0;
// 	int pop = 1;
// 	for(int i=0; i<n; i++) {
// 		pop*=x[i];
// 		ma = max(ma, pop*y[i]);
// 	}
// 	return ma%MOD;
// }

// int init(int N, int X[], int Y[]) {
// 	n = N;
// 	x = X;
//  	y = Y;
// 	return solve();
// }

// int updateX(int pos, int val) {
// 	x[pos] = val;
// 	return solve();
// }

// int updateY(int pos, int val) {
// 	y[pos] = val;
// 	return solve();
// }


//Subtask 2

// int solve() {
// 	int max_i = n-1;
// 	ll pop = x[n-1];
// 	for(int i=n-2; i>=0; i--) {
// 		if (y[i] > y[max_i]*pop) {
// 			max_i = i;
// 			pop=1;
// 		}
// 		pop = min(pop*x[i], INF);
// 	}
 
// 	pop=1;
// 	for(int i=0; i<=max_i; i++){
// 		pop = (pop*x[i])%MOD;
// 	}
// 	return (int) (pop*y[max_i])%MOD;
// }
 
// int init(int N, int X[], int Y[]) {
// 	n = N;
// 	x = X;
// 	y = Y;

// 	return solve();
// }
 
// int updateX(int pos, int val) {
// 	x[pos] = val;
// 	return solve();
// }
 
// int updateY(int pos, int val) {
// 	y[pos] = val;
// 	return solve();
// }


// Subtask 3

v<ll> xs_mults;

ll query_xs(int L, int R, int l, int r, int index) {
	if (r<L || l>R) return 1;
	if (l>=L and r<=R) return xs_mults[index];
	int mid = (l+r)/2;
	ll subl = query_xs(L, R, l, mid, index*2);
	ll subr = query_xs(L, R, mid+1, r, index*2+1);
	return (subl*subr)%MOD;
}

void update_xs(int pos, int value, int l, int r, int index) {
	int mid = (l+r)/2;
	if (l==r){
		xs_mults[index] = value;
		return;
	}
	if (pos <= mid){
		update_xs(pos, value, l, mid, index*2);
	} else {
		update_xs(pos, value, mid+1, r, index*2+1);
	}
	xs_mults[index] = (xs_mults[index*2]*xs_mults[index*2+1])%MOD;
}

int solve() {
	int max_i = n-1;
	ll pop = x[n-1];
	for(int i=n-2; i>=0 && i>=n-30; i--) {
		if (y[i] > y[max_i]*pop) {
			max_i = i;
			pop=1;
		}
		pop = min(pop*x[i], INF);
	}
	ll mult = query_xs(0, max_i, 0, n-1, 1);
	return (int) ((mult*y[max_i])%MOD);
}

int init(int N, int X[], int Y[]) {
	n = N;
	x = X;
	y = Y;
	xs_mults = v<ll> (2*n, 1);
	for(int i=0; i<n; i++) {
		update_xs(i, x[i], 0, n-1, 1);
	}
	return solve();
}

int updateX(int pos, int val) {
	x[pos] = val;
	update_xs(pos, val, 0, n-1, 1);
	return solve();
}

int updateY(int pos, int val) {
	y[pos] = val;
	return solve();
}

// Subtask 5

// ll query_xs(int L, int R, int l, int r, int index) {
// 	if (r<L || l>R) return 1;
// 	if (l>=L and r<=R) return xs[index];
// 	int mid = (l+r)/2;
// 	ll subl = query_xs(L, R, l, mid, index*2);
// 	ll subr = query_xs(L, R, mid+1, r, index*2+1);
// 	return min(MOD, subl*subr);
// }

// void update_xs(int pos, int value, int l, int r, int index) {
// 	int mid = (l+r)/2;
// 	if (l==r) xs[index] = value;
// 	if (pos <= mid){
// 		update_xs(pos, value, l, mid, index*2);
// 	} else {
// 		update_xs(pos, value, mid+1, r, index*2+1);
// 	}
// 	xs[index] = min(MOD, xs[index*2]*xs[index*2+1]);
// }

// ll query_ys(int L, int R, int l, int r, int index) {
// 	if (r<L || l>R) return 0;
// 	if (l>=L and r<=R) return ys[index];
// 	int mid = (l+r)/2;
// 	ll subl = query_ys(L, R, l, mid, index*2);
// 	ll subr = query_ys(L, R, mid+1, r, index*2+1);
// 	return max(subl, subr);
// }

// void update_ys(int pos, int value, int l, int r, int index) {
// 	int mid = (l+r)/2;
// 	if (l==r) ys[index] = value;
// 	if (pos <= mid){
// 		update_ys(pos, value, l, mid, index*2);
// 	} else {
// 		update_ys(pos, value, mid+1, r, index*2+1);
// 	}
// 	ys[index] = max(ys[index*2], ys[index*2+1]);
// }

// int solve() {
// 	int max_i = n-1;
// 	ll pop = xs[n-1];
// 	for(int i=n-2; i>=0; i--) {
// 		if (ys[i] > ys[max_i]*pop) {
// 			max_i = i;
// 			pop=1;
// 		}
// 		pop = min(pop*xs[i], (ll)MOD);
// 	}

// 	pop=1;
// 	for(int i=0; i<=max_i; i++){
// 		pop = (pop*xs[i])%MOD;
// 	}
// 	return (int) ((pop*ys[max_i])%MOD);
// }

// int init(int N, int X[], int Y[]) {
// 	n = N;
// 	xs = v<ll> (2*n, 1);
// 	ys = v<ll> (2*n, 0);

// 	for (int i=0; i<n; i++) {
// 		update_xs(i, X[i], 0, n-1, 1);
// 		update_ys(i, Y[i], 0, n-1, 1);
// 	}
// 	return solve();
// }

// int updateX(int pos, int val) {
// 	update_xs(pos, val, 0, n-1, 1);
// 	return solve();
// }

// int updateY(int pos, int val) {
// 	update_ys(pos, val, 0, n-1, 1);
// 	return solve();
// }
# Verdict Execution time Memory Grader output
1 Correct 1 ms 288 KB Output is correct
2 Correct 1 ms 288 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 284 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Runtime error 1 ms 288 KB Execution killed with signal 6
18 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 284 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 284 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 284 KB Output is correct
8 Correct 0 ms 288 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Runtime error 1 ms 340 KB Execution killed with signal 6
18 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 161 ms 16348 KB Output is correct
2 Incorrect 200 ms 17844 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 292 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 216 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 1 ms 288 KB Output is correct
17 Runtime error 1 ms 340 KB Execution killed with signal 6
18 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 0 ms 288 KB Output is correct
3 Correct 1 ms 288 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 292 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 0 ms 284 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 1 ms 288 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 284 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Runtime error 1 ms 340 KB Execution killed with signal 6
18 Halted 0 ms 0 KB -