Submission #137970

# Submission time Handle Problem Language Result Execution time Memory
137970 2019-07-28T16:16:45 Z arthurconmy Horses (IOI15_horses) C++14
54 / 100
1500 ms 16100 KB
#include <bits/stdc++.h>
using namespace std;

using ll=long long;

const int p = 1000000007;
const int pLL = 1000000007LL;
const int MAXN = 500001; // 1-index that shit
const ll MAXP = 1000000000;

int n;
ll X[MAXN];
ll Y[MAXN];
ll x_prod=1;

int gcd(int a, int b, int &x, int &y)
{
	if(a%b == 1) // uh ... plug a = p in the real thing I guess then
	{
		x = 1;
		y = -int(a/b);

		return 1;
	}

	int d = gcd(b,a%b,x,y); 
	int old_x = x;

	x = y;
	y = old_x - int(a/b)*y;

	return d;
}

ll mod_inv(ll x_raw)
{
	x_raw %= pLL;
	int x = int(x_raw);

	if(x==1) return 1; // thonking

	int x1=-1; 
	int y1=-1;
	
	gcd(p,x,x1,y1); // EDITING THIS DAMN FUNCTION !!!

	while(y1<0) y1+=p;

	return ll(y1);
}

pair<ll,ll> mexico(pair<ll,ll> a, pair<ll,ll> b)
{
	if(a.first*b.second >= a.second*b.first) return a;
	return b;
}

int init(int N, int x[], int y[])
{
	n=N;

	for(int i=0; i<n; i++)
	{
		X[i+1]=ll(x[i]);

		x_prod *= ll(x[i]);
		x_prod %= pLL;
	}

	for(int i=0; i<n; i++)
	{
		Y[i+1]=ll(y[i]);
	}	

	pair<ll,ll> GL = {ll(Y[n]),1LL}; // gain and loss

	ll cur_loss = 1LL;

	for(int i=n-1; i>=1; i--)
	{
		cur_loss *= X[i+1];
		if(cur_loss>MAXP) break;

		GL = mexico(GL, make_pair(ll(Y[i]),cur_loss));
	}

	// return x_prod * GL.first * mod_inv(GL.second)

	ll ans = x_prod * GL.first;
	ans %= pLL;
	ans *= mod_inv(int(GL.second)%p);
	ans %= pLL;

	return int(ans); 
}

int updateX(int pos, int val)
{
	pos++;

	x_prod *= ll(mod_inv(X[pos]));
	x_prod %= pLL;
	x_prod *= val;
	x_prod %= pLL;

	X[pos]=val;

	pair<ll,ll> GL = {ll(Y[n]),1LL}; // gain and loss

	ll cur_loss = 1LL;

	for(int i=n-1; i>=1; i--)
	{
		cur_loss *= X[i+1];
		if(cur_loss>MAXP) break;

		GL = mexico(GL, make_pair(ll(Y[i]),cur_loss));
	}

	// return x_prod * GL.first * mod_inv(GL.second)

	ll ans = x_prod * GL.first;
	ans %= pLL;
	ans *= mod_inv(int(GL.second)%p);
	ans %= pLL;

	return int(ans);
}

int updateY(int pos, int val)
{
	Y[++pos]=val;

	pair<ll,ll> GL = {ll(Y[n]),1LL}; // gain and loss

	ll cur_loss = 1LL;

	for(int i=n-1; i>=1; i--)
	{
		cur_loss *= X[i+1];
		if(cur_loss>MAXP) break;

		GL = mexico(GL, make_pair(ll(Y[i]),cur_loss));
	}

	// return x_prod * GL.first * mod_inv(GL.second)

	ll ans = x_prod * GL.first;
	ans %= pLL;
	ans *= mod_inv(int(GL.second)%p);
	ans %= pLL;

	return int(ans); 
}

#ifdef ARTHUR_LOCAL

	int X_raw[MAXN-1];
	int Y_raw[MAXN-1];

	int main()
	{
		X_raw[0]=2;
		X_raw[1]=1;
		X_raw[2]=3;
		Y_raw[0]=3;
		Y_raw[1]=4;
		Y_raw[2]=1;

		cout << init(3,X_raw,Y_raw) << endl;
		cout << updateY(1,2) << endl;
	}
#endif
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 348 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 380 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 2 ms 376 KB Output is correct
17 Correct 2 ms 376 KB Output is correct
18 Correct 2 ms 376 KB Output is correct
19 Correct 2 ms 376 KB Output is correct
20 Correct 2 ms 256 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 256 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 348 KB Output is correct
9 Correct 2 ms 256 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 2 ms 376 KB Output is correct
17 Correct 2 ms 256 KB Output is correct
18 Correct 2 ms 376 KB Output is correct
19 Correct 2 ms 376 KB Output is correct
20 Correct 2 ms 376 KB Output is correct
21 Correct 2 ms 256 KB Output is correct
22 Correct 2 ms 376 KB Output is correct
23 Correct 3 ms 376 KB Output is correct
24 Correct 2 ms 376 KB Output is correct
25 Correct 2 ms 376 KB Output is correct
26 Correct 2 ms 376 KB Output is correct
27 Correct 3 ms 376 KB Output is correct
28 Correct 3 ms 376 KB Output is correct
29 Correct 5 ms 376 KB Output is correct
30 Correct 3 ms 376 KB Output is correct
31 Correct 5 ms 376 KB Output is correct
32 Correct 4 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 72 ms 13124 KB Output is correct
2 Correct 88 ms 13048 KB Output is correct
3 Correct 55 ms 16100 KB Output is correct
4 Correct 71 ms 15352 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 504 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 380 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 256 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 2 ms 256 KB Output is correct
16 Correct 2 ms 376 KB Output is correct
17 Correct 2 ms 256 KB Output is correct
18 Correct 2 ms 376 KB Output is correct
19 Correct 2 ms 372 KB Output is correct
20 Correct 3 ms 256 KB Output is correct
21 Correct 2 ms 376 KB Output is correct
22 Correct 2 ms 376 KB Output is correct
23 Correct 2 ms 376 KB Output is correct
24 Correct 2 ms 376 KB Output is correct
25 Correct 2 ms 376 KB Output is correct
26 Correct 2 ms 376 KB Output is correct
27 Correct 3 ms 376 KB Output is correct
28 Correct 2 ms 376 KB Output is correct
29 Correct 5 ms 376 KB Output is correct
30 Correct 3 ms 376 KB Output is correct
31 Correct 6 ms 376 KB Output is correct
32 Correct 4 ms 376 KB Output is correct
33 Correct 108 ms 14540 KB Output is correct
34 Correct 34 ms 14584 KB Output is correct
35 Correct 60 ms 14200 KB Output is correct
36 Correct 58 ms 14180 KB Output is correct
37 Correct 566 ms 14456 KB Output is correct
38 Correct 32 ms 14584 KB Output is correct
39 Execution timed out 1566 ms 14200 KB Time limit exceeded
40 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 252 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 256 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 0 ms 376 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 2 ms 376 KB Output is correct
17 Correct 2 ms 376 KB Output is correct
18 Correct 2 ms 380 KB Output is correct
19 Correct 2 ms 376 KB Output is correct
20 Correct 2 ms 376 KB Output is correct
21 Correct 2 ms 376 KB Output is correct
22 Correct 2 ms 376 KB Output is correct
23 Correct 3 ms 376 KB Output is correct
24 Correct 2 ms 376 KB Output is correct
25 Correct 2 ms 376 KB Output is correct
26 Correct 2 ms 376 KB Output is correct
27 Correct 3 ms 376 KB Output is correct
28 Correct 2 ms 376 KB Output is correct
29 Correct 5 ms 376 KB Output is correct
30 Correct 4 ms 504 KB Output is correct
31 Correct 5 ms 376 KB Output is correct
32 Correct 4 ms 424 KB Output is correct
33 Correct 74 ms 15620 KB Output is correct
34 Correct 89 ms 15228 KB Output is correct
35 Correct 71 ms 15608 KB Output is correct
36 Correct 76 ms 15340 KB Output is correct
37 Correct 119 ms 14584 KB Output is correct
38 Correct 38 ms 14600 KB Output is correct
39 Correct 65 ms 14200 KB Output is correct
40 Correct 65 ms 14216 KB Output is correct
41 Correct 577 ms 14476 KB Output is correct
42 Correct 29 ms 14556 KB Output is correct
43 Execution timed out 1552 ms 14076 KB Time limit exceeded
44 Halted 0 ms 0 KB -