Submission #757882

# Submission time Handle Problem Language Result Execution time Memory
757882 2023-06-13T21:20:51 Z APROHACK Horses (IOI15_horses) C++14
100 / 100
323 ms 37920 KB
#include <bits/stdc++.h>
#include "horses.h"
#define ll long long
#define pb push_back
const ll mod = 1e9+7;
using namespace std;
int n;
ll maxV = 0;
ll acum[500005];
vector<ll>x, y;
set<int>doses;

int maximos[500000*4], posiciones[500000*4];


void merge(int node){
	if(maximos[node*2] > maximos[node*2+1]){
		maximos[node] = maximos[node*2];
		posiciones[node] = posiciones[node*2];
	}else{
		maximos[node] = maximos[node*2+1];
		posiciones[node] = posiciones[node*2+1];
	}
}
void updateVal(int node, int l, int r, int pos, int value){
	int temp = (l+r)/2;
	if(l == r){
		maximos[node] = value;
		posiciones[node] = pos;
	}else if(pos <= temp){
		updateVal(node*2, l, temp, pos, value);
		merge(node);
	}else{
		updateVal(node*2+1, temp+1, r, pos, value);
		merge(node);
	}
}
int queryMaximo(int node, int l, int r, int dd, int ht){
	if(dd == l and ht == r)return posiciones[node];
	int temp = (l + r ) /2;
	if(ht <= temp)return queryMaximo(node*2, l, temp, dd, ht);
	else if(dd > temp)return queryMaximo(node*2+1, temp+1, r, dd, ht);
	else{
		int m1 = queryMaximo(node*2, l, temp, dd, temp), m2 = queryMaximo(node*2+1, temp+1, r, temp+1, ht);
		if(y[m1] > y[m2]){
			return m1;
		}else return m2;
	}
}
int qq(int node, int l, int r, int dd , int ht){
	if(dd > ht)return -1;
	if ( dd == ht )return dd;
	return queryMaximo(node, l, r, dd, ht);
}


ll fastExp(ll base, int pot){
	if(pot == 0)return 1;
	ll temp = fastExp(base, pot/2);
	temp = temp * temp % mod;
	if(pot % 2 == 1)temp = (temp * base) % mod;
	return temp;
}

ll query(int pos){
	ll ans = 1;
	for(; pos>= 1 ; pos -= (pos&-pos)){
		ans *= acum[pos];
		ans %= mod;
	}
	return ans;
}
void multiplicar(int pos , int value){
	for(; pos<= n ; pos += pos&(-pos)){
		acum[pos] *= value;
		acum[pos] %= mod;
	}
}

void updateRet(){
	ll ans = query(n) * y[n-1] % mod;
	ll current = x[n-1]* y[n-1];
	int curpos = n-1;
	int realI;
	for(auto i : doses){
		realI = -i;
		if(realI == n-1)continue;
		int mm = qq(1, 0, n-1, realI+1, curpos-1);
		if(mm != -1){
			if(y[mm] > current){
				ans = query(mm+1) * y[mm] % mod;
				current = x[mm]*y[mm];
			}
		}
		if(current > 1e9){
			maxV = ans;
			return ;
		}
		if(current < y[realI]){
			ans = query(realI+1) * y[realI] % mod;
			current = x[realI]*y[realI];
		}else{
			current = current * x[realI];
		}
		curpos = 	realI;
		if(current > 1e9){
			maxV = ans;
			return ;
		}
	}
	int mm = qq(1, 0, n-1, 0, curpos-1);
	if(mm != -1){
		if(y[mm] > current){
			ans = query(mm+1) * y[mm] % mod;
			current = x[mm]*y[mm];
		}
	}
	/*
	for(int i = n-2 ; i >= 0 ; i --){
		if(current > 1e9){
			maxV = ans;
			return ;
		}
		if(current < y[i]){
			ans = query(i+1) * y[i] % mod;
			current = x[i]*y[i];
		}else{
			current = current * x[i];
		}
	}
	*/
	maxV = ans;
}
int init(int N, int X[], int Y[]) {
	n = N;
	for(int i = 0 ; i <= n ; i ++)acum[i] = 1;
	for(int i = 0 ; i < N ; i++){
		x.pb(X[i]);
		y.pb(Y[i]);
		multiplicar(i+1, X[i]);
		updateVal(1, 0, N-1, i, Y[i]);
	}
	for(int i = n-1 ; i >=0 and doses.size() < 100 ; i --){
		if(x[i] > 1)doses.insert(-i);
	}
	updateRet();
	return maxV%mod;
}

int updateX(int pos, int val) {	
	multiplicar(pos + 1, fastExp(x[pos], mod-2));
	if(x[pos] > 1 and val == 1 and doses.find(-pos) != doses.end())doses.erase(-pos);
	else if(x[pos] == 1 and val > 1)doses.insert(-pos);
	if(doses.size()==100)doses.erase(prev(doses.end()));
	x[pos] = val;
	multiplicar(pos + 1, x[pos]);
	updateRet();
	return maxV%mod;
}

int updateY(int pos, int val) {
	y[pos] = val;
	updateVal(1, 0, n-1, pos, val);
	updateRet();
	return maxV%mod;
}

Compilation message

horses.cpp: In function 'void updateRet()':
horses.cpp:95:6: warning: conversion from 'long long int' to 'double' may change value [-Wconversion]
   95 |   if(current > 1e9){
      |      ^~~~~~~
horses.cpp:106:6: warning: conversion from 'long long int' to 'double' may change value [-Wconversion]
  106 |   if(current > 1e9){
      |      ^~~~~~~
horses.cpp: In function 'int init(int, int*, int*)':
horses.cpp:147:13: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
  147 |  return maxV%mod;
      |         ~~~~^~~~
horses.cpp: In function 'int updateX(int, int)':
horses.cpp:151:30: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
  151 |  multiplicar(pos + 1, fastExp(x[pos], mod-2));
      |                       ~~~~~~~^~~~~~~~~~~~~~~
horses.cpp:156:29: warning: conversion from '__gnu_cxx::__alloc_traits<std::allocator<long long int>, long long int>::value_type' {aka 'long long int'} to 'int' may change value [-Wconversion]
  156 |  multiplicar(pos + 1, x[pos]);
      |                             ^
horses.cpp:158:13: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
  158 |  return maxV%mod;
      |         ~~~~^~~~
horses.cpp: In function 'int updateY(int, int)':
horses.cpp:165:13: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
  165 |  return maxV%mod;
      |         ~~~~^~~~
# Verdict Execution time Memory Grader output
1 Correct 1 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 0 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 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
# Verdict Execution time Memory Grader output
1 Correct 1 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 1 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 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 1 ms 340 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 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 1 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 348 KB Output is correct
26 Correct 1 ms 324 KB Output is correct
27 Correct 2 ms 340 KB Output is correct
28 Correct 1 ms 340 KB Output is correct
29 Correct 2 ms 340 KB Output is correct
30 Correct 1 ms 340 KB Output is correct
31 Correct 1 ms 328 KB Output is correct
32 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 137 ms 25412 KB Output is correct
2 Correct 182 ms 37920 KB Output is correct
3 Correct 143 ms 29140 KB Output is correct
4 Correct 164 ms 32932 KB Output is correct
# Verdict Execution time Memory 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 0 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 1 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 0 ms 336 KB Output is correct
21 Correct 0 ms 212 KB Output is correct
22 Correct 1 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 2 ms 340 KB Output is correct
28 Correct 2 ms 340 KB Output is correct
29 Correct 2 ms 340 KB Output is correct
30 Correct 1 ms 340 KB Output is correct
31 Correct 1 ms 340 KB Output is correct
32 Correct 1 ms 340 KB Output is correct
33 Correct 108 ms 28320 KB Output is correct
34 Correct 103 ms 28464 KB Output is correct
35 Correct 122 ms 35264 KB Output is correct
36 Correct 122 ms 35188 KB Output is correct
37 Correct 117 ms 26568 KB Output is correct
38 Correct 101 ms 27452 KB Output is correct
39 Correct 93 ms 26468 KB Output is correct
40 Correct 105 ms 30452 KB Output is correct
41 Correct 89 ms 26444 KB Output is correct
42 Correct 101 ms 26508 KB Output is correct
43 Correct 100 ms 30756 KB Output is correct
44 Correct 108 ms 30760 KB Output is correct
# Verdict Execution time Memory 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 1 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 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 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 1 ms 212 KB Output is correct
23 Correct 1 ms 324 KB Output is correct
24 Correct 1 ms 328 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 324 KB Output is correct
27 Correct 2 ms 324 KB Output is correct
28 Correct 1 ms 340 KB Output is correct
29 Correct 2 ms 340 KB Output is correct
30 Correct 2 ms 316 KB Output is correct
31 Correct 1 ms 340 KB Output is correct
32 Correct 1 ms 340 KB Output is correct
33 Correct 134 ms 29168 KB Output is correct
34 Correct 182 ms 37892 KB Output is correct
35 Correct 150 ms 29148 KB Output is correct
36 Correct 170 ms 32924 KB Output is correct
37 Correct 114 ms 28408 KB Output is correct
38 Correct 103 ms 28360 KB Output is correct
39 Correct 122 ms 35236 KB Output is correct
40 Correct 124 ms 35336 KB Output is correct
41 Correct 118 ms 26532 KB Output is correct
42 Correct 100 ms 27452 KB Output is correct
43 Correct 95 ms 26472 KB Output is correct
44 Correct 105 ms 30312 KB Output is correct
45 Correct 90 ms 26528 KB Output is correct
46 Correct 90 ms 26476 KB Output is correct
47 Correct 101 ms 30732 KB Output is correct
48 Correct 99 ms 30776 KB Output is correct
49 Correct 172 ms 30428 KB Output is correct
50 Correct 157 ms 30372 KB Output is correct
51 Correct 172 ms 37280 KB Output is correct
52 Correct 155 ms 36640 KB Output is correct
53 Correct 323 ms 28772 KB Output is correct
54 Correct 147 ms 29220 KB Output is correct
55 Correct 182 ms 27488 KB Output is correct
56 Correct 152 ms 32104 KB Output is correct
57 Correct 136 ms 28064 KB Output is correct
58 Correct 143 ms 28652 KB Output is correct
59 Correct 98 ms 30712 KB Output is correct