Submission #387393

# Submission time Handle Problem Language Result Execution time Memory
387393 2021-04-08T10:24:07 Z alishahali1382 Horses (IOI15_horses) C++14
100 / 100
353 ms 45420 KB
#include "horses.h"
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
#define debug(x) {cerr<<#x<<"="<<x<<"\n";}
#define debugp(p) {cerr<<#p<<"={"<<p.first<<", "<<p.second<<"}\n";}
#define debug2(x, y) {cerr<<#x<<", "<<#y<<" = "<<x<<", "<<y<<"\n";}
#define pb push_back
#define all(x) x.begin(), x.end()

const int mod=1000000007;
const int MAXN=500010, LOG=20;

int n, m, k;
ll X[MAXN], Y[MAXN], zarbx=1;
int seg[MAXN<<1];
set<int> st;

void Set(int pos, int val){
	for (seg[pos+=n]=val; pos>1; pos>>=1) seg[pos>>1]=max(seg[pos], seg[pos^1]);
}
int Get(int l, int r){
	int res=0;
	for (l+=n, r+=n; l<r; l>>=1, r>>=1){
		if (l&1) res=max(res, seg[l++]);
		if (r&1) res=max(res, seg[--r]);
	}
	return res;
}
ll powmod(ll a, ll b){
	ll res=1;
	for (; b; b>>=1, a=a*a%mod) if (b&1) res=res*a%mod;
	return res;
}
int Solve(){
	auto it=st.end();
	ll ansx=1, ansy=0, xx=1;
	while (it!=st.begin()){
		it--;
		int i=*it, y=Get(i, n);
		// debug2(i, y)
		if (xx*ansy<ansx*y){
			ansx=xx;
			ansy=y;
		}
		xx*=X[i];
		if (xx>=1000000000) break ;
	}
	return zarbx*powmod(ansx, mod-2)%mod*ansy%mod;
}

int init(int _n, int _X[], int _Y[]) {
	n=_n;
	for (int i=0; i<n; i++){
		X[i]=_X[i];
		Y[i]=_Y[i];
		if (X[i]>1 || !i){
			zarbx=zarbx*X[i]%mod;
			st.insert(i);
		}
		Set(i, Y[i]);
	}
	return Solve();
}
int updateX(int pos, int val) {	
	st.erase(pos);
	zarbx=zarbx*powmod(X[pos], mod-2)%mod;
	X[pos]=val;
	if (X[pos]>1 || !pos){
		zarbx=zarbx*X[pos]%mod;
		st.insert(pos);
	}
	return Solve();
}
int updateY(int pos, int val) {
	Y[pos]=val;
	Set(pos, val);
	return Solve();
}

Compilation message

horses.cpp: In function 'int Solve()':
horses.cpp:51:43: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
   51 |  return zarbx*powmod(ansx, mod-2)%mod*ansy%mod;
      |         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~
horses.cpp: In function 'int init(int, int*, int*)':
horses.cpp:63:13: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
   63 |   Set(i, Y[i]);
      |          ~~~^
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
17 Correct 1 ms 364 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
19 Correct 1 ms 364 KB Output is correct
20 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 2 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
17 Correct 1 ms 364 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
19 Correct 1 ms 364 KB Output is correct
20 Correct 1 ms 364 KB Output is correct
21 Correct 1 ms 364 KB Output is correct
22 Correct 1 ms 364 KB Output is correct
23 Correct 2 ms 364 KB Output is correct
24 Correct 2 ms 364 KB Output is correct
25 Correct 2 ms 492 KB Output is correct
26 Correct 2 ms 492 KB Output is correct
27 Correct 2 ms 384 KB Output is correct
28 Correct 2 ms 492 KB Output is correct
29 Correct 2 ms 364 KB Output is correct
30 Correct 2 ms 492 KB Output is correct
31 Correct 2 ms 364 KB Output is correct
32 Correct 2 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 227 ms 40428 KB Output is correct
2 Correct 304 ms 40556 KB Output is correct
3 Correct 283 ms 40596 KB Output is correct
4 Correct 352 ms 40428 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 2 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 2 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 2 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
17 Correct 1 ms 364 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
19 Correct 1 ms 364 KB Output is correct
20 Correct 1 ms 364 KB Output is correct
21 Correct 1 ms 364 KB Output is correct
22 Correct 1 ms 364 KB Output is correct
23 Correct 2 ms 364 KB Output is correct
24 Correct 2 ms 364 KB Output is correct
25 Correct 2 ms 492 KB Output is correct
26 Correct 2 ms 492 KB Output is correct
27 Correct 2 ms 384 KB Output is correct
28 Correct 2 ms 492 KB Output is correct
29 Correct 2 ms 364 KB Output is correct
30 Correct 2 ms 492 KB Output is correct
31 Correct 2 ms 364 KB Output is correct
32 Correct 2 ms 364 KB Output is correct
33 Correct 47 ms 16492 KB Output is correct
34 Correct 48 ms 16492 KB Output is correct
35 Correct 185 ms 39916 KB Output is correct
36 Correct 181 ms 39916 KB Output is correct
37 Correct 49 ms 16364 KB Output is correct
38 Correct 100 ms 28268 KB Output is correct
39 Correct 38 ms 16108 KB Output is correct
40 Correct 165 ms 42476 KB Output is correct
41 Correct 39 ms 18156 KB Output is correct
42 Correct 43 ms 18284 KB Output is correct
43 Correct 160 ms 42348 KB Output is correct
44 Correct 162 ms 42348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 492 KB Output is correct
8 Correct 1 ms 492 KB Output is correct
9 Correct 1 ms 512 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
17 Correct 1 ms 384 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
19 Correct 1 ms 364 KB Output is correct
20 Correct 1 ms 364 KB Output is correct
21 Correct 1 ms 364 KB Output is correct
22 Correct 2 ms 364 KB Output is correct
23 Correct 3 ms 364 KB Output is correct
24 Correct 2 ms 364 KB Output is correct
25 Correct 2 ms 492 KB Output is correct
26 Correct 2 ms 492 KB Output is correct
27 Correct 2 ms 364 KB Output is correct
28 Correct 2 ms 492 KB Output is correct
29 Correct 2 ms 364 KB Output is correct
30 Correct 2 ms 492 KB Output is correct
31 Correct 2 ms 364 KB Output is correct
32 Correct 2 ms 364 KB Output is correct
33 Correct 229 ms 40764 KB Output is correct
34 Correct 307 ms 40812 KB Output is correct
35 Correct 277 ms 40812 KB Output is correct
36 Correct 353 ms 40684 KB Output is correct
37 Correct 48 ms 16492 KB Output is correct
38 Correct 48 ms 16620 KB Output is correct
39 Correct 183 ms 40044 KB Output is correct
40 Correct 187 ms 39916 KB Output is correct
41 Correct 55 ms 16264 KB Output is correct
42 Correct 104 ms 28396 KB Output is correct
43 Correct 38 ms 16108 KB Output is correct
44 Correct 170 ms 42348 KB Output is correct
45 Correct 39 ms 18156 KB Output is correct
46 Correct 43 ms 18284 KB Output is correct
47 Correct 160 ms 42316 KB Output is correct
48 Correct 162 ms 42348 KB Output is correct
49 Correct 115 ms 20972 KB Output is correct
50 Correct 111 ms 20972 KB Output is correct
51 Correct 246 ms 45420 KB Output is correct
52 Correct 229 ms 45420 KB Output is correct
53 Correct 185 ms 20844 KB Output is correct
54 Correct 190 ms 33876 KB Output is correct
55 Correct 104 ms 19052 KB Output is correct
56 Correct 235 ms 43244 KB Output is correct
57 Correct 101 ms 19820 KB Output is correct
58 Correct 134 ms 19820 KB Output is correct
59 Correct 159 ms 42348 KB Output is correct