답안 #614000

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
614000 2022-07-30T16:10:07 Z Lucpp 말 (IOI15_horses) C++17
100 / 100
730 ms 65608 KB
#include "horses.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD = 1e9+7;

template<typename T>
struct SegTree{
	virtual T combine(T t1, T t2) = 0;
	virtual T id() = 0;

	int cap;
	vector<T> seg;
	void build(const vector<T>& v){
		int n = (int)v.size();
		for(cap=1; cap < n; cap*=2);
		seg.assign(2*cap, id());
		for(int i = 0; i < n; i++) seg[i+cap] = v[i];
		for(int i = cap-1; i >= 1; i--) seg[i] = combine(seg[2*i], seg[2*i+1]);
	}
	void upd(int i, T v){
		i += cap;
		seg[i] = v;
		while(i > 1){
			i /= 2;
			seg[i] = combine(seg[2*i], seg[2*i+1]);
		}
	}
	T qry(int l, int r, int a, int b, int i){
		if(l <= a && b <= r) return seg[i];
		if(b < l || r < a) return id();
		int m = (a+b)/2;
		return combine(qry(l, r, a, m, 2*i), qry(l, r, m+1, b, 2*i+1));
	}
	T qry(int l, int r){return qry(l, r, 1, cap, 1);}
};

struct ProdTree : SegTree<ll> {
	ll combine(ll t1, ll t2) override {return (t1*t2)%MOD;}
	ll id() override {return 1;}
};
struct MaxTree : SegTree<ll> {
	ll combine(ll t1, ll t2) override {return max(t1, t2);}
	ll id() override {return 0;}
};

vector<ll> x, y;
set<int> non1;
int n;
ProdTree p;
MaxTree m;

int calc(){
	ll prod = 1;
	auto it = non1.rbegin();
	for(; it != non1.rend() && prod < MOD; it++){
		prod *= x[*it];
	}
	int last = -1;
	if(prod >= MOD) last = *(--it);
	ll pref = p.qry(1, last+1);
	prod = 1;
	ll best = 0;
	while(it != non1.rbegin()){
		it--;
		best = max(best, prod*m.qry(last+1, *it));
		prod *= x[*it];
		last = *it;
	}
	best = max(best, prod*m.qry(last+1, n));
	return int(((best%MOD)*pref)%MOD);
}

int init(int N, int X[], int Y[]){
	n = N;
	x.resize(n);
	y.resize(n);
	for(int i = 0; i < n; i++){
		x[i] = X[i], y[i] = Y[i];
		if(x[i] != 1) non1.insert(i);
	}
	p.build(x);
	m.build(y);
	return calc();
}

int updateX(int pos, int val) {
	x[pos] = val;
	p.upd(pos, val);
	if(val == 1) non1.erase(pos);
	else non1.insert(pos);
	return calc();
}

int updateY(int pos, int val) {
	y[pos] = val;
	m.upd(pos, val);
	return calc();
}
# 결과 실행 시간 메모리 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 1 ms 212 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 1 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 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 0 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 0 ms 212 KB Output is correct
20 Correct 0 ms 212 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 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 1 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 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 1 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 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 2 ms 316 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 2 ms 340 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 4 ms 340 KB Output is correct
28 Correct 2 ms 340 KB Output is correct
29 Correct 1 ms 340 KB Output is correct
30 Correct 1 ms 340 KB Output is correct
31 Correct 3 ms 340 KB Output is correct
32 Correct 3 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 719 ms 53016 KB Output is correct
2 Correct 319 ms 52848 KB Output is correct
3 Correct 348 ms 56700 KB Output is correct
4 Correct 423 ms 60464 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 1 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 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 0 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 Correct 1 ms 212 KB Output is correct
18 Correct 0 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 0 ms 212 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 2 ms 444 KB Output is correct
26 Correct 2 ms 440 KB Output is correct
27 Correct 5 ms 340 KB Output is correct
28 Correct 2 ms 320 KB Output is correct
29 Correct 1 ms 340 KB Output is correct
30 Correct 2 ms 316 KB Output is correct
31 Correct 3 ms 340 KB Output is correct
32 Correct 3 ms 312 KB Output is correct
33 Correct 47 ms 32516 KB Output is correct
34 Correct 48 ms 32564 KB Output is correct
35 Correct 182 ms 62808 KB Output is correct
36 Correct 188 ms 62804 KB Output is correct
37 Correct 104 ms 30844 KB Output is correct
38 Correct 106 ms 43508 KB Output is correct
39 Correct 31 ms 30460 KB Output is correct
40 Correct 168 ms 57952 KB Output is correct
41 Correct 63 ms 30540 KB Output is correct
42 Correct 76 ms 30564 KB Output is correct
43 Correct 153 ms 58268 KB Output is correct
44 Correct 163 ms 58316 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 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 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 0 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 0 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 0 ms 212 KB Output is correct
21 Correct 0 ms 212 KB Output is correct
22 Correct 0 ms 212 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 4 ms 340 KB Output is correct
28 Correct 2 ms 340 KB Output is correct
29 Correct 1 ms 340 KB Output is correct
30 Correct 1 ms 340 KB Output is correct
31 Correct 3 ms 340 KB Output is correct
32 Correct 4 ms 312 KB Output is correct
33 Correct 701 ms 56692 KB Output is correct
34 Correct 318 ms 65608 KB Output is correct
35 Correct 335 ms 56780 KB Output is correct
36 Correct 415 ms 60564 KB Output is correct
37 Correct 46 ms 32592 KB Output is correct
38 Correct 45 ms 32500 KB Output is correct
39 Correct 202 ms 62784 KB Output is correct
40 Correct 189 ms 62856 KB Output is correct
41 Correct 100 ms 30716 KB Output is correct
42 Correct 102 ms 43488 KB Output is correct
43 Correct 37 ms 30460 KB Output is correct
44 Correct 163 ms 57872 KB Output is correct
45 Correct 61 ms 30564 KB Output is correct
46 Correct 82 ms 30656 KB Output is correct
47 Correct 168 ms 58340 KB Output is correct
48 Correct 164 ms 58432 KB Output is correct
49 Correct 179 ms 35576 KB Output is correct
50 Correct 135 ms 35588 KB Output is correct
51 Correct 338 ms 64660 KB Output is correct
52 Correct 303 ms 64184 KB Output is correct
53 Correct 730 ms 33912 KB Output is correct
54 Correct 312 ms 47524 KB Output is correct
55 Correct 106 ms 31640 KB Output is correct
56 Correct 281 ms 59700 KB Output is correct
57 Correct 386 ms 32212 KB Output is correct
58 Correct 555 ms 32720 KB Output is correct
59 Correct 157 ms 58244 KB Output is correct