답안 #740049

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
740049 2023-05-12T03:17:11 Z fractlpaca 말 (IOI15_horses) C++17
77 / 100
1500 ms 64908 KB
#include "horses.h"
#include <vector>
#include <algorithm>
#include <set>
// #include <iostream>

#define v vector
#define ll long long
#define fi first
#define se second

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

using namespace std;

int *x;
int *y;
int n;


// Editorial Subtask 5

v<ll> xs_mod;
// v<ll> xs_trunc;
v<int> ys_max;
set<pair<int, int>> ranges;

ll query_xs_mod(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_mod[index];
	int mid = (l+r)/2;
	ll subl = query_xs_mod(L, R, l, mid, index*2);
	ll subr = query_xs_mod(L, R, mid+1, r, index*2+1);
	return (subl*subr)%MOD;
}

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

int query_ys_max(int L, int R, int l, int r, int index) {
	if (r<L || l>R) return -1;
	if (l>=L and r<=R) return ys_max[index];
	int mid = (l+r)/2;
	int subl = query_ys_max(L, R, l, mid, index*2);
	int subr = query_ys_max(L, R, mid+1, r, index*2+1);
	if (subl == -1) return subr;
	if (subr == -1) return subl;
	if (y[subl] > y[subr]) return subl;
	return subr;
}

void update_ys_max(int pos, int value, int l, int r, int index) {
	if (l==r) {
		y[pos] = value;
		ys_max[index] = pos;
		return;
	}
	int mid = (l+r)/2;
	if (pos <= mid){
		update_ys_max(pos, value, l, mid, index*2);
	} else {
		update_ys_max(pos, value, mid+1, r, index*2+1);
	}
	int subl = ys_max[index*2];
	int subr = ys_max[index*2+1];
	int ans = 0;
	if (subl == -1) ans = subr;
	else if (subr == -1) ans = subl;
	else if (y[subl] > y[subr]) ans = subl;
	else ans = subr;
	ys_max[index] = ans;
}

int solve() {
	// cerr<<"Ranges: ";
	// for(auto it=ranges.begin(); it!=ranges.end(); it++) {
	// 	cerr<<"("<<it->fi<<", "<<it->se<<"), ";
	// } cerr<<endl;

	
	auto it = ranges.end();
	it--;
	int max_i = query_ys_max(it->fi, it->se, 0, n-1, 1);
	ll pop = x[max_i];
	it--;
	for(int counter=0; counter<60; counter++) {
		int i = query_ys_max(it->fi, it->se, 0, n-1, 1);
		if (y[i] > y[max_i]*pop) {
			max_i = i;
			pop=1;
		}
		pop = min(pop*x[i], INF);
		if (it==ranges.begin()) break;
		it--;
	}
	ll mult = query_xs_mod(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_mod = v<ll> (4*n, 1);
	//xs_trunc = v<ll> (4*n, 1);
	ys_max = v<int> (4*n, 1);

	for (int i=0; i<n; i++) {
		update_xs_mod(i, X[i], 0, n-1, 1);
		//update_xs_trunc(i, X[i], 0, n-1, 1);
		update_ys_max(i, Y[i], 0, n-1, 1);
		ranges.insert({i, i});
	}

	for(auto it = ranges.begin(); it!=ranges.end(); it++) {
		if (x[it->fi] == 1 && it!=ranges.begin()) {
			auto prev = it;
			prev--;
			if (x[prev->fi] == 1) {
				int new_start = prev->fi, new_end=it->se;
				ranges.erase(prev);
				ranges.erase(it);
				ranges.insert({new_start, new_end});
			}
		}
	}
	return solve();
}

int updateX(int pos, int val) {
	if (val == 1 && x[pos] != 1){
		auto it = ranges.find({pos, pos});
		int new_start = pos, new_end = pos;
		if (it!=ranges.begin()) {
			auto prev = it;
			prev--;
			if (x[prev->fi] == 1) {
				new_start = prev->fi;
				ranges.erase(prev);
			}
		}
		auto next = it;
		next++;
		if (next!=ranges.end()) {
			if (x[next->fi] == 1) {
				new_end = next->se;
				ranges.erase(next);
			}
		}
		ranges.erase(it);
		ranges.insert({new_start, new_end});

	} else if (val!=1 && x[pos] == 1) {
		auto it = ranges.upper_bound({pos, n});
		it--;
		int start = it->fi, end = it->se;
		if (pos > start) ranges.insert({start, pos-1});
		if (pos < end) ranges.insert({pos+1, end});
		ranges.erase(it);
		ranges.insert({pos, pos});
	}

	x[pos] = val;
	update_xs_mod(pos, val, 0, n-1, 1);
	//update_xs_trunc(pos, val, 0, n-1, 1);
	return solve();
}

int updateY(int pos, int val) {
	update_ys_max(pos, val, 0, n-1, 1);
	return solve();
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 292 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 288 KB Output is correct
5 Correct 1 ms 284 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 1 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 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 0 ms 288 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 1 ms 296 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 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 212 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 0 ms 280 KB Output is correct
12 Correct 0 ms 288 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 0 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 Correct 0 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 1 ms 292 KB Output is correct
23 Correct 9 ms 340 KB Output is correct
24 Correct 7 ms 404 KB Output is correct
25 Correct 9 ms 340 KB Output is correct
26 Correct 7 ms 340 KB Output is correct
27 Correct 7 ms 340 KB Output is correct
28 Correct 10 ms 408 KB Output is correct
29 Correct 2 ms 340 KB Output is correct
30 Correct 7 ms 340 KB Output is correct
31 Correct 3 ms 340 KB Output is correct
32 Correct 10 ms 296 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1220 ms 53788 KB Output is correct
2 Correct 1288 ms 53072 KB Output is correct
3 Correct 1288 ms 53724 KB Output is correct
4 Correct 1363 ms 52992 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 288 KB Output is correct
4 Correct 0 ms 292 KB Output is correct
5 Correct 0 ms 288 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 0 ms 288 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 1 ms 284 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 7 ms 340 KB Output is correct
24 Correct 9 ms 404 KB Output is correct
25 Correct 7 ms 424 KB Output is correct
26 Correct 7 ms 340 KB Output is correct
27 Correct 7 ms 340 KB Output is correct
28 Correct 7 ms 340 KB Output is correct
29 Correct 2 ms 340 KB Output is correct
30 Correct 7 ms 340 KB Output is correct
31 Correct 3 ms 340 KB Output is correct
32 Correct 10 ms 300 KB Output is correct
33 Correct 535 ms 55128 KB Output is correct
34 Correct 458 ms 55172 KB Output is correct
35 Correct 449 ms 62080 KB Output is correct
36 Correct 522 ms 62160 KB Output is correct
37 Correct 492 ms 53332 KB Output is correct
38 Correct 436 ms 54236 KB Output is correct
39 Correct 371 ms 53228 KB Output is correct
40 Correct 430 ms 57120 KB Output is correct
41 Correct 402 ms 53172 KB Output is correct
42 Correct 458 ms 53328 KB Output is correct
43 Correct 329 ms 57540 KB Output is correct
44 Correct 331 ms 57452 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 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 1 ms 212 KB Output is correct
8 Correct 0 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 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 0 ms 212 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 7 ms 408 KB Output is correct
24 Correct 7 ms 396 KB Output is correct
25 Correct 7 ms 428 KB Output is correct
26 Correct 7 ms 320 KB Output is correct
27 Correct 7 ms 340 KB Output is correct
28 Correct 7 ms 340 KB Output is correct
29 Correct 2 ms 340 KB Output is correct
30 Correct 7 ms 340 KB Output is correct
31 Correct 3 ms 340 KB Output is correct
32 Correct 10 ms 340 KB Output is correct
33 Correct 1268 ms 55880 KB Output is correct
34 Correct 1284 ms 64908 KB Output is correct
35 Correct 1243 ms 55932 KB Output is correct
36 Correct 1322 ms 59784 KB Output is correct
37 Correct 521 ms 55160 KB Output is correct
38 Correct 471 ms 55244 KB Output is correct
39 Correct 447 ms 62164 KB Output is correct
40 Correct 452 ms 61984 KB Output is correct
41 Correct 465 ms 53272 KB Output is correct
42 Correct 430 ms 54220 KB Output is correct
43 Correct 393 ms 53228 KB Output is correct
44 Correct 442 ms 57172 KB Output is correct
45 Correct 402 ms 53236 KB Output is correct
46 Correct 448 ms 53344 KB Output is correct
47 Correct 338 ms 57532 KB Output is correct
48 Correct 334 ms 57480 KB Output is correct
49 Execution timed out 1539 ms 57296 KB Time limit exceeded
50 Halted 0 ms 0 KB -