답안 #292346

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
292346 2020-09-06T20:55:30 Z VodkaInTheJar 말 (IOI15_horses) C++14
100 / 100
907 ms 53496 KB
#include <bits/stdc++.h>
 
using namespace std;

const int maxn = 5e5 + 3; 
const int mod = 1e9 + 7; 

int n, x[maxn], y[maxn];
set <int> s;

pair <int, int> tr[maxn * 4];
void merge(int v)
{
	tr[v].first = max(tr[v * 2].first, tr[v * 2 + 1].first);
	tr[v].second = 1ll * tr[v * 2].second * tr[v * 2 + 1].second % mod;
}

void build(int v, int l, int r)
{
	if (l == r)
	{
		tr[v] = {y[l], x[l]};
		return;
	}
	
	int mid = (l + r) / 2;
	build(v * 2, l, mid);
	build(v * 2 + 1, mid + 1, r);
	
	merge(v);
}

int get1(int v, int l, int r, int ll, int rr)
{
	if (l > rr || r < ll)
	return -1;
	
	if (l >= ll && r <= rr)
	return tr[v].first;
	
	int mid = (l + r) / 2;
	return max(get1(v * 2, l, mid, ll, rr), get1(v * 2 + 1, mid + 1, r, ll, rr));
}

int get2(int v, int l, int r, int ll, int rr)
{
	if (l > rr || r < ll)
	return 1;
	
	if (l >= ll && r <= rr)
	return tr[v].second;
	
	int mid = (l + r) / 2;
	return 1ll * get2(v * 2, l, mid, ll, rr) * get2(v * 2 + 1, mid + 1, r, ll, rr) % mod;
}

void update1(int v, int l, int r, int pos, int val)
{
	if (l == r)
	{
		tr[v].first = val;
		return;
	}
	
	int mid = (l + r) / 2;
	if (pos <= mid)
	update1(v * 2, l, mid, pos, val);
	
	else
	update1(v * 2 + 1, mid + 1, r, pos, val);
	
	merge(v);
}

void update2(int v, int l, int r, int pos, int val)
{
	if (l == r)
	{
		tr[v].second = val;
		return;
	}
	
	int mid = (l + r) / 2;
	if (pos <= mid)
	update2(v * 2, l, mid, pos, val);
	
	else
	update2(v * 2 + 1, mid + 1, r, pos, val);
	
	merge(v);
}

int get()
{
	if (s.empty())
	return get1(1, 1, n, 1, n);
	
	else 
	{
		long long pr = 1; 
		auto it = prev(s.end());
		
		while (it != s.begin() && pr <= 1000000000)
		{
			pr *= x[*it];
			it--;
		}
		
		if (it != s.begin() || pr >= 1000000000)
		it++;
		
		int to_mult = get2(1, 1, n, 1, *it);
		auto it1 = it;
		
		pr = 1; 
		long long ans = -1;
		while (it != s.end())
		{
			ans = max(ans, pr * y[*it]);
			
			int l = *it + 1, r;
			if (it != prev(s.end()))
			r = *next(it) - 1;
			
			else 
			r = n; 
			
			if (l <= r) 
				ans = max(ans, pr * get1(1, 1, n, l, r));
			
			it++;
			if (it != s.end())
			pr *= x[*it];
		}
		
		if (it1 == s.begin() && *it1 != 1)
		{
			if (pr * x[*it1] <= 1000000000)
			{
				auto curr = get1(1, 1, n, 1, *it1 - 1);
				if (curr / x[*it1] >= ans)
				return curr; 
			}
		}
		
		return 1ll * (ans % mod) * to_mult % mod; 
	}
}

int init(int _n, int _x[], int _y[])
{
	n = _n;
	for (int i = 1; i <= n; i++)
	x[i] = _x[i-1], y[i] = _y[i-1];
	
	build(1, 1, n);
	for (int i = 1; i <= n; i++)
	if (x[i] != 1)
	s.insert(i);
	
	return get();
}

int updateX(int pos, int val)
{
	pos++;
	
	if (x[pos] == val)
	return get();
	 
	update2(1, 1, n, pos, val); 
	
	if (val == 1)
	s.erase(pos);
	
	else 
	if (x[pos] == 1)
	s.insert(pos);
	
	x[pos] = val;
	
	return get();
}

int updateY(int pos, int val)
{
	pos++;
	
	y[pos] = val; 
	update1(1, 1, n, pos, val);
	
	return get();
}

/*
int n2, q, x2[maxn], y2[maxn]; 
int main()
{
	cin >> n2;
	for (int i = 0; i < n2; i++)
	cin >> x2[i];
	
	for (int i = 0; i < n2; i++)
	cin >> y2[i];
	 
	cout << init(n2, x2, y2) << endl;

	cin >> q;
	while (q--)
	{
		int type, pos, val;
		cin >> type >> pos >> val;
		
		if (type == 1)
		cout << updateX(pos, val) << endl;
		
		else 
		cout << updateY(pos, val) << endl;
	}
}
*/

Compilation message

horses.cpp: In function 'void merge(int)':
horses.cpp:15:63: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
   15 |  tr[v].second = 1ll * tr[v * 2].second * tr[v * 2 + 1].second % mod;
      |                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~
horses.cpp: In function 'int get2(int, int, int, int, int)':
horses.cpp:54:81: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
   54 |  return 1ll * get2(v * 2, l, mid, ll, rr) * get2(v * 2 + 1, mid + 1, r, ll, rr) % mod;
      |         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~
horses.cpp: In function 'int get()':
horses.cpp:146:38: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
  146 |   return 1ll * (ans % mod) * to_mult % mod;
      |          ~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 1 ms 512 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 0 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 0 ms 384 KB Output is correct
11 Correct 0 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 0 ms 384 KB Output is correct
16 Correct 1 ms 384 KB Output is correct
17 Correct 0 ms 384 KB Output is correct
18 Correct 0 ms 384 KB Output is correct
19 Correct 1 ms 384 KB Output is correct
20 Correct 0 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 0 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 0 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 0 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 0 ms 384 KB Output is correct
15 Correct 0 ms 384 KB Output is correct
16 Correct 0 ms 384 KB Output is correct
17 Correct 0 ms 384 KB Output is correct
18 Correct 0 ms 384 KB Output is correct
19 Correct 1 ms 384 KB Output is correct
20 Correct 0 ms 384 KB Output is correct
21 Correct 0 ms 384 KB Output is correct
22 Correct 1 ms 384 KB Output is correct
23 Correct 1 ms 384 KB Output is correct
24 Correct 1 ms 384 KB Output is correct
25 Correct 2 ms 512 KB Output is correct
26 Correct 1 ms 512 KB Output is correct
27 Correct 4 ms 384 KB Output is correct
28 Correct 2 ms 512 KB Output is correct
29 Correct 2 ms 384 KB Output is correct
30 Correct 2 ms 512 KB Output is correct
31 Correct 1 ms 384 KB Output is correct
32 Correct 4 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 277 ms 44668 KB Output is correct
2 Correct 299 ms 53496 KB Output is correct
3 Correct 258 ms 44664 KB Output is correct
4 Correct 275 ms 48504 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 0 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 0 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 0 ms 384 KB Output is correct
12 Correct 0 ms 384 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 0 ms 384 KB Output is correct
15 Correct 1 ms 512 KB Output is correct
16 Correct 0 ms 384 KB Output is correct
17 Correct 1 ms 384 KB Output is correct
18 Correct 0 ms 384 KB Output is correct
19 Correct 0 ms 384 KB Output is correct
20 Correct 1 ms 384 KB Output is correct
21 Correct 0 ms 384 KB Output is correct
22 Correct 1 ms 384 KB Output is correct
23 Correct 1 ms 384 KB Output is correct
24 Correct 1 ms 384 KB Output is correct
25 Correct 2 ms 512 KB Output is correct
26 Correct 1 ms 512 KB Output is correct
27 Correct 4 ms 512 KB Output is correct
28 Correct 2 ms 512 KB Output is correct
29 Correct 1 ms 384 KB Output is correct
30 Correct 1 ms 512 KB Output is correct
31 Correct 1 ms 384 KB Output is correct
32 Correct 4 ms 384 KB Output is correct
33 Correct 49 ms 20472 KB Output is correct
34 Correct 44 ms 20472 KB Output is correct
35 Correct 190 ms 50808 KB Output is correct
36 Correct 192 ms 50808 KB Output is correct
37 Correct 125 ms 18680 KB Output is correct
38 Correct 104 ms 31480 KB Output is correct
39 Correct 38 ms 18432 KB Output is correct
40 Correct 169 ms 45820 KB Output is correct
41 Correct 36 ms 18552 KB Output is correct
42 Correct 98 ms 18548 KB Output is correct
43 Correct 158 ms 46320 KB Output is correct
44 Correct 159 ms 46200 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 0 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 0 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 0 ms 384 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 0 ms 384 KB Output is correct
15 Correct 0 ms 384 KB Output is correct
16 Correct 1 ms 384 KB Output is correct
17 Correct 0 ms 384 KB Output is correct
18 Correct 1 ms 384 KB Output is correct
19 Correct 0 ms 384 KB Output is correct
20 Correct 1 ms 384 KB Output is correct
21 Correct 1 ms 384 KB Output is correct
22 Correct 1 ms 384 KB Output is correct
23 Correct 2 ms 384 KB Output is correct
24 Correct 1 ms 384 KB Output is correct
25 Correct 1 ms 512 KB Output is correct
26 Correct 1 ms 512 KB Output is correct
27 Correct 4 ms 384 KB Output is correct
28 Correct 2 ms 512 KB Output is correct
29 Correct 1 ms 384 KB Output is correct
30 Correct 1 ms 512 KB Output is correct
31 Correct 1 ms 384 KB Output is correct
32 Correct 5 ms 384 KB Output is correct
33 Correct 275 ms 44668 KB Output is correct
34 Correct 289 ms 53496 KB Output is correct
35 Correct 262 ms 44664 KB Output is correct
36 Correct 269 ms 48632 KB Output is correct
37 Correct 50 ms 20472 KB Output is correct
38 Correct 43 ms 20472 KB Output is correct
39 Correct 190 ms 50808 KB Output is correct
40 Correct 186 ms 50808 KB Output is correct
41 Correct 127 ms 18764 KB Output is correct
42 Correct 105 ms 31480 KB Output is correct
43 Correct 39 ms 18432 KB Output is correct
44 Correct 164 ms 45944 KB Output is correct
45 Correct 36 ms 18552 KB Output is correct
46 Correct 99 ms 18552 KB Output is correct
47 Correct 156 ms 46200 KB Output is correct
48 Correct 155 ms 46200 KB Output is correct
49 Correct 202 ms 23540 KB Output is correct
50 Correct 131 ms 23544 KB Output is correct
51 Correct 344 ms 52728 KB Output is correct
52 Correct 286 ms 52212 KB Output is correct
53 Correct 907 ms 21880 KB Output is correct
54 Correct 322 ms 35320 KB Output is correct
55 Correct 178 ms 19576 KB Output is correct
56 Correct 270 ms 47608 KB Output is correct
57 Correct 143 ms 20088 KB Output is correct
58 Correct 743 ms 20856 KB Output is correct
59 Correct 158 ms 46200 KB Output is correct