Submission #133603

# Submission time Handle Problem Language Result Execution time Memory
133603 2019-07-21T06:11:44 Z Mahdi_Jfri Horses (IOI15_horses) C++14
100 / 100
1385 ms 21496 KB
#include "horses.h"
#include<bits/stdc++.h>

using namespace std;

#define ll long long
#define pb push_back

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

int maxy[maxn * 4] , mulx[maxn * 4] , t[maxn * 4] , n;

int x[maxn];

void updx(int p , int val , int s = 0 , int e = n , int v = 1)
{
	if(e - s < 2)
	{
		mulx[v] = val;
		t[v] = val > 1;
		return;
	}

	int m = (s + e) / 2;
	if(p < m)
		updx(p , val , s , m , 2 * v);
	else
		updx(p , val , m , e , 2 * v + 1);

	mulx[v] = 1LL * mulx[2 * v] * mulx[2 * v + 1] % mod;
	t[v] = t[2 * v] + t[2 * v + 1];
}

void updy(int p , int val , int s = 0 , int e = n , int v = 1)
{
	if(e - s < 2)
	{
		maxy[v] = val;
		return;
	}

	int m = (s + e) / 2;
	if(p < m)
		updy(p , val , s , m , 2 * v);
	else
		updy(p , val , m , e , 2 * v + 1);

	maxy[v] = max(maxy[2 * v] , maxy[2 * v + 1]);
}

int getx(int l , int r , int s = 0 , int e = n , int v = 1)
{
	if(l <= s && e <= r)
		return mulx[v];
	else if(r <= s || e <= l)
		return 1;

	int m = (s + e) / 2;

	return 1LL * getx(l , r , s , m , 2 * v) * getx(l , r , m , e , 2 * v + 1) % mod;
}

int gety(int l , int r , int s = 0 , int e = n , int v = 1)
{
	if(l <= s && e <= r)
		return maxy[v];
	if(r <= s || e <= l)
		return 0;

	int m = (s + e) / 2;
	return max(gety(l , r , s , m , 2 * v) , gety(l , r , m , e , 2 * v + 1));
}

void ux(int p , int val)
{
	x[p] = val;
	updx(p , val);
}

vector<int> tmp;

void get(int k = 35 , int s = 0 , int e = n , int v = 1)
{
	if(k <= 0 || !t[v])
		return;

	if(e - s < 2)
	{
		tmp.pb(s);
		return;
	}
	
	int m = (s + e) / 2;
	get(k , m , e , 2 * v + 1);
	k -= t[2 * v + 1];
	get(k , s , m , 2 * v);
}

int solve()
{
	tmp.clear();
	get();
	
  	tmp.pb(0);
	reverse(tmp.begin() , tmp.end());
	int m = tmp.size();
	tmp.pb(n);

	vector<int> y;
	for(int i = 0; i < m; i++)
		y.pb(gety(tmp[i] , tmp[i + 1]));

	for(int i = 0; i < m; i++)
	{
		bool good = 1;

		ll mul = 1;
		for(int j = i + 1; j < m && good; j++)
		{
			mul = min((ll)2e9 , 1LL * mul * x[tmp[j]]);
			if(y[i] <= mul * y[j])
				good = 0;
		}

		if(good)
			return 1LL * getx(0 , tmp[i] + 1) * y[i] % mod;
	}

	return -1;
}

int init(int N, int X[], int Y[])
{
	n = N;
	for(int i = 0; i < n; i++)
	{
		ux(i , X[i]);
		updy(i , Y[i]);
	}

	return solve();
}

int updateX(int pos, int val)
{
	ux(pos , val);
	return solve();
}

int updateY(int pos, int val)
{
	updy(pos , val);
	return solve();
}





Compilation message

horses.cpp: In function 'void updx(int, int, int, int, int)':
horses.cpp:31:48: warning: conversion to 'int' from 'long long int' may alter its value [-Wconversion]
  mulx[v] = 1LL * mulx[2 * v] * mulx[2 * v + 1] % mod;
            ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~
horses.cpp: In function 'int getx(int, int, int, int, int)':
horses.cpp:61:77: warning: conversion to 'int' from 'long long int' may alter its value [-Wconversion]
  return 1LL * getx(l , r , s , m , 2 * v) * getx(l , r , m , e , 2 * v + 1) % mod;
         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~
horses.cpp: In function 'int solve()':
horses.cpp:107:18: warning: conversion to 'int' from 'std::vector<int>::size_type {aka long unsigned int}' may alter its value [-Wconversion]
  int m = tmp.size();
          ~~~~~~~~^~
horses.cpp:127:45: warning: conversion to 'int' from 'long long int' may alter its value [-Wconversion]
    return 1LL * getx(0 , tmp[i] + 1) * y[i] % mod;
           ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~
# 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 376 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 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 376 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 452 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 3 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 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 380 KB Output is correct
16 Correct 2 ms 376 KB Output is correct
17 Correct 2 ms 348 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 376 KB Output is correct
22 Correct 2 ms 376 KB Output is correct
23 Correct 8 ms 380 KB Output is correct
24 Correct 7 ms 376 KB Output is correct
25 Correct 6 ms 376 KB Output is correct
26 Correct 6 ms 376 KB Output is correct
27 Correct 7 ms 376 KB Output is correct
28 Correct 6 ms 376 KB Output is correct
29 Correct 3 ms 376 KB Output is correct
30 Correct 7 ms 376 KB Output is correct
31 Correct 5 ms 376 KB Output is correct
32 Correct 6 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1129 ms 19620 KB Output is correct
2 Correct 1161 ms 19656 KB Output is correct
3 Correct 1139 ms 19780 KB Output is correct
4 Correct 1185 ms 19624 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 380 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 388 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 380 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 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 8 ms 376 KB Output is correct
24 Correct 6 ms 376 KB Output is correct
25 Correct 6 ms 376 KB Output is correct
26 Correct 6 ms 376 KB Output is correct
27 Correct 7 ms 376 KB Output is correct
28 Correct 6 ms 376 KB Output is correct
29 Correct 3 ms 376 KB Output is correct
30 Correct 7 ms 376 KB Output is correct
31 Correct 5 ms 376 KB Output is correct
32 Correct 6 ms 376 KB Output is correct
33 Correct 363 ms 18680 KB Output is correct
34 Correct 324 ms 18696 KB Output is correct
35 Correct 347 ms 18696 KB Output is correct
36 Correct 339 ms 18808 KB Output is correct
37 Correct 345 ms 18808 KB Output is correct
38 Correct 313 ms 18680 KB Output is correct
39 Correct 237 ms 18680 KB Output is correct
40 Correct 330 ms 20344 KB Output is correct
41 Correct 274 ms 20372 KB Output is correct
42 Correct 300 ms 20472 KB Output is correct
43 Correct 244 ms 20244 KB Output is correct
44 Correct 244 ms 20216 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 504 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 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 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 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 8 ms 376 KB Output is correct
24 Correct 6 ms 376 KB Output is correct
25 Correct 7 ms 376 KB Output is correct
26 Correct 6 ms 376 KB Output is correct
27 Correct 7 ms 376 KB Output is correct
28 Correct 6 ms 380 KB Output is correct
29 Correct 3 ms 376 KB Output is correct
30 Correct 7 ms 376 KB Output is correct
31 Correct 5 ms 380 KB Output is correct
32 Correct 6 ms 376 KB Output is correct
33 Correct 1109 ms 19704 KB Output is correct
34 Correct 1165 ms 19712 KB Output is correct
35 Correct 1130 ms 19548 KB Output is correct
36 Correct 1154 ms 19556 KB Output is correct
37 Correct 353 ms 18688 KB Output is correct
38 Correct 318 ms 18828 KB Output is correct
39 Correct 343 ms 18748 KB Output is correct
40 Correct 339 ms 18844 KB Output is correct
41 Correct 345 ms 18680 KB Output is correct
42 Correct 316 ms 18720 KB Output is correct
43 Correct 239 ms 18676 KB Output is correct
44 Correct 331 ms 20408 KB Output is correct
45 Correct 274 ms 20328 KB Output is correct
46 Correct 301 ms 20448 KB Output is correct
47 Correct 251 ms 20328 KB Output is correct
48 Correct 248 ms 20328 KB Output is correct
49 Correct 1385 ms 21416 KB Output is correct
50 Correct 1164 ms 21496 KB Output is correct
51 Correct 1189 ms 21292 KB Output is correct
52 Correct 1150 ms 21240 KB Output is correct
53 Correct 1349 ms 21368 KB Output is correct
54 Correct 1142 ms 21064 KB Output is correct
55 Correct 407 ms 20340 KB Output is correct
56 Correct 1200 ms 21240 KB Output is correct
57 Correct 759 ms 21232 KB Output is correct
58 Correct 1024 ms 21112 KB Output is correct
59 Correct 245 ms 20088 KB Output is correct