Submission #1018595

# Submission time Handle Problem Language Result Execution time Memory
1018595 2024-07-10T07:17:18 Z parsadox2 Horses (IOI15_horses) C++17
54 / 100
1500 ms 52432 KB
#include "horses.h"
#include <bits/stdc++.h>

using namespace std;

const long long N = 5e5 + 10 , mod = 1e9 + 7;

long long n , x[N] , y[N] , mulx;
set <long long> st;

long long tav(long long a , long long b)
{
	long long res = 1;
	while(b)
	{
		if(b & 1)
			res = 1LL * res * a % mod;
		b >>= 1;
		a = 1LL * a * a % mod;
	}
	return res;
}

struct SEG{
	long long mx[N << 4];
	void Build(long long node = 1 , long long nl = 0 , long long nr = n)
	{
		if(nr - nl == 1)
		{
			mx[node] = y[nl];
			return;
		}
		long long mid = (nl + nr) >> 1 , lc = node << 1 , rc = lc | 1;
		Build(lc , nl , mid);  Build(rc , mid , nr);
		mx[node] = max(mx[lc] , mx[rc]);
	}
	void Update(long long id , long long node = 1 , long long nl = 0 , long long nr = n)
	{
		if(nr - nl == 1)
		{
			mx[node] = y[nl];
			return;
		}
		long long mid = (nl + nr) >> 1 , lc = node << 1 , rc = lc | 1;
		if(id < mid)
			Update(id , lc , nl , mid);
		else
			Update(id , rc , mid , nr);
		mx[node] = max(mx[lc] , mx[rc]);
	}
	long long Get(long long l , long long r , long long node = 1 , long long nl = 0 , long long nr = n)
	{
		if(r <= nl || nr <= l)
			return 0;
		if(l <= nl && nr <= r)
			return mx[node];
		long long mid = (nl + nr) >> 1 , lc = node << 1 , rc = lc | 1;
		return max(Get(l , r , lc , nl , mid) , Get(l , r , rc , mid , nr));
	}
} seg;

long long Solve2()
{
	long long tmpx = 1 , res = 0 , las = n;
	for(int i = n - 1 ; i > -1 ; i--)
	{
		las = i;
		if(y[i] >= res)
		{
			res = 1LL * x[i] * y[i];
		}
		else
		{
			res = 1LL * res * x[i];
		}
		tmpx *= x[i];
		if(res > mod)
			break;
	}
	res %= mod;
	/*for(int i = 0 ; i < las ; i++)
		res = 1LL * res * x[i] % mod;
	return res;*/
	return 1LL * mulx * tav(tmpx % mod , mod - 2) % mod * res % mod;
}

long long Solve()
{
	long long tmpx = 1 , mx_x = 1 , mx_y = 1;
	for(auto asd : st)
	{
		auto u = abs(asd);
		long long Y = seg.Get(u , n);
		if(Y >= 1LL * mx_x * mx_y)
		{
			mx_y = Y;
			mx_x = x[u];
		}
		else
		{
			mx_x *= x[u];
		}
		tmpx *= x[u];
		if(1LL * mx_x * mx_y > mod)
			break;
	}
	long long res = 1LL * mx_x * mx_y % mod;
	if(seg.Get(0 , n) > 1LL * mx_x * mx_y)
		res = seg.Get(0 , n);
	return 1LL * mulx * tav(tmpx , mod - 2) % mod * res % mod;
}

int init(int nn, int X[], int Y[]) {
	mulx = 1;
	n = nn;
	for(long long i = 0 ; i < n ; i++)
	{
		x[i] = X[i];
		y[i] = Y[i];
		mulx = 1LL * mulx * x[i] % mod;
	}
	seg.Build();
	for(long long i = 0 ; i < n ; i++)  if(x[i] > 1)
		st.insert(-i);
	return Solve2();
}

int updateX(int pos, int val) {	
	if(x[pos] > 1)
		st.erase(-pos);
	mulx = 1LL * mulx * tav(x[pos] , mod - 2) % mod;
	x[pos] = val;
	if(x[pos] > 1)
		st.insert(-pos);
	mulx = 1LL * mulx * x[pos] % mod;
	return Solve2();
}

int updateY(int pos, int val) {
	y[pos] = val;
	seg.Update(pos);
	return Solve2();
}

Compilation message

horses.cpp: In function 'long long int Solve2()':
horses.cpp:65:16: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
   65 |  for(int i = n - 1 ; i > -1 ; i--)
      |              ~~^~~
horses.cpp:64:33: warning: variable 'las' set but not used [-Wunused-but-set-variable]
   64 |  long long tmpx = 1 , res = 0 , las = n;
      |                                 ^~~
horses.cpp: In function 'int init(int, int*, int*)':
horses.cpp:125:15: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
  125 |  return Solve2();
      |         ~~~~~~^~
horses.cpp: In function 'int updateX(int, int)':
horses.cpp:136:15: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
  136 |  return Solve2();
      |         ~~~~~~^~
horses.cpp: In function 'int updateY(int, int)':
horses.cpp:142:15: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
  142 |  return Solve2();
      |         ~~~~~~^~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4440 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 1 ms 4440 KB Output is correct
4 Correct 1 ms 4444 KB Output is correct
5 Correct 1 ms 4444 KB Output is correct
6 Correct 1 ms 4444 KB Output is correct
7 Correct 1 ms 4444 KB Output is correct
8 Correct 1 ms 4444 KB Output is correct
9 Correct 1 ms 4444 KB Output is correct
10 Correct 1 ms 4444 KB Output is correct
11 Correct 0 ms 4444 KB Output is correct
12 Correct 1 ms 4444 KB Output is correct
13 Correct 1 ms 4444 KB Output is correct
14 Correct 0 ms 4444 KB Output is correct
15 Correct 1 ms 4444 KB Output is correct
16 Correct 1 ms 4444 KB Output is correct
17 Correct 0 ms 4444 KB Output is correct
18 Correct 0 ms 4444 KB Output is correct
19 Correct 1 ms 4444 KB Output is correct
20 Correct 1 ms 4444 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4440 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 1 ms 4444 KB Output is correct
5 Correct 1 ms 4444 KB Output is correct
6 Correct 1 ms 4444 KB Output is correct
7 Correct 0 ms 4444 KB Output is correct
8 Correct 1 ms 4444 KB Output is correct
9 Correct 1 ms 4444 KB Output is correct
10 Correct 1 ms 4444 KB Output is correct
11 Correct 0 ms 4444 KB Output is correct
12 Correct 1 ms 4444 KB Output is correct
13 Correct 1 ms 4444 KB Output is correct
14 Correct 1 ms 4444 KB Output is correct
15 Correct 1 ms 4444 KB Output is correct
16 Correct 1 ms 4444 KB Output is correct
17 Correct 0 ms 4444 KB Output is correct
18 Correct 1 ms 4440 KB Output is correct
19 Correct 1 ms 4440 KB Output is correct
20 Correct 1 ms 4444 KB Output is correct
21 Correct 1 ms 4444 KB Output is correct
22 Correct 1 ms 4444 KB Output is correct
23 Correct 1 ms 4444 KB Output is correct
24 Correct 1 ms 4444 KB Output is correct
25 Correct 1 ms 4444 KB Output is correct
26 Correct 1 ms 4560 KB Output is correct
27 Correct 2 ms 4444 KB Output is correct
28 Correct 1 ms 4444 KB Output is correct
29 Correct 2 ms 4468 KB Output is correct
30 Correct 1 ms 4444 KB Output is correct
31 Correct 2 ms 4440 KB Output is correct
32 Correct 1 ms 4444 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 144 ms 45912 KB Output is correct
2 Correct 213 ms 45912 KB Output is correct
3 Correct 185 ms 45828 KB Output is correct
4 Correct 225 ms 49848 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4440 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 0 ms 4444 KB Output is correct
4 Correct 0 ms 4444 KB Output is correct
5 Correct 0 ms 4444 KB Output is correct
6 Correct 1 ms 4444 KB Output is correct
7 Correct 1 ms 4444 KB Output is correct
8 Correct 1 ms 4444 KB Output is correct
9 Correct 1 ms 4444 KB Output is correct
10 Correct 1 ms 4444 KB Output is correct
11 Correct 0 ms 4444 KB Output is correct
12 Correct 1 ms 4440 KB Output is correct
13 Correct 1 ms 4444 KB Output is correct
14 Correct 1 ms 4444 KB Output is correct
15 Correct 1 ms 4444 KB Output is correct
16 Correct 1 ms 4444 KB Output is correct
17 Correct 1 ms 4444 KB Output is correct
18 Correct 1 ms 4444 KB Output is correct
19 Correct 1 ms 4444 KB Output is correct
20 Correct 1 ms 4444 KB Output is correct
21 Correct 1 ms 4444 KB Output is correct
22 Correct 1 ms 4440 KB Output is correct
23 Correct 1 ms 4560 KB Output is correct
24 Correct 1 ms 4556 KB Output is correct
25 Correct 1 ms 4444 KB Output is correct
26 Correct 1 ms 4444 KB Output is correct
27 Correct 1 ms 4444 KB Output is correct
28 Correct 1 ms 4616 KB Output is correct
29 Correct 2 ms 4444 KB Output is correct
30 Correct 1 ms 4644 KB Output is correct
31 Correct 2 ms 4444 KB Output is correct
32 Correct 2 ms 4440 KB Output is correct
33 Correct 44 ms 23848 KB Output is correct
34 Correct 27 ms 23892 KB Output is correct
35 Correct 143 ms 50512 KB Output is correct
36 Correct 138 ms 50436 KB Output is correct
37 Correct 220 ms 22908 KB Output is correct
38 Correct 65 ms 35152 KB Output is correct
39 Execution timed out 1504 ms 22620 KB Time limit exceeded
40 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 0 ms 4444 KB Output is correct
4 Correct 1 ms 4444 KB Output is correct
5 Correct 1 ms 4444 KB Output is correct
6 Correct 1 ms 4444 KB Output is correct
7 Correct 1 ms 4444 KB Output is correct
8 Correct 0 ms 4444 KB Output is correct
9 Correct 1 ms 4444 KB Output is correct
10 Correct 1 ms 4440 KB Output is correct
11 Correct 1 ms 4444 KB Output is correct
12 Correct 1 ms 4444 KB Output is correct
13 Correct 0 ms 4444 KB Output is correct
14 Correct 1 ms 4444 KB Output is correct
15 Correct 1 ms 4444 KB Output is correct
16 Correct 1 ms 4444 KB Output is correct
17 Correct 1 ms 4444 KB Output is correct
18 Correct 1 ms 4444 KB Output is correct
19 Correct 1 ms 4444 KB Output is correct
20 Correct 1 ms 4444 KB Output is correct
21 Correct 0 ms 4444 KB Output is correct
22 Correct 1 ms 4444 KB Output is correct
23 Correct 1 ms 4696 KB Output is correct
24 Correct 1 ms 4444 KB Output is correct
25 Correct 1 ms 4584 KB Output is correct
26 Correct 1 ms 4564 KB Output is correct
27 Correct 1 ms 4444 KB Output is correct
28 Correct 1 ms 4444 KB Output is correct
29 Correct 2 ms 4588 KB Output is correct
30 Correct 1 ms 4444 KB Output is correct
31 Correct 2 ms 4560 KB Output is correct
32 Correct 2 ms 4444 KB Output is correct
33 Correct 145 ms 47784 KB Output is correct
34 Correct 238 ms 52432 KB Output is correct
35 Correct 182 ms 47956 KB Output is correct
36 Correct 263 ms 50000 KB Output is correct
37 Correct 42 ms 24148 KB Output is correct
38 Correct 28 ms 23896 KB Output is correct
39 Correct 146 ms 50604 KB Output is correct
40 Correct 141 ms 50488 KB Output is correct
41 Correct 227 ms 22936 KB Output is correct
42 Correct 64 ms 35156 KB Output is correct
43 Execution timed out 1546 ms 22724 KB Time limit exceeded
44 Halted 0 ms 0 KB -