Submission #62316

# Submission time Handle Problem Language Result Execution time Memory
62316 2018-07-28T04:53:09 Z nvmdava Horses (IOI15_horses) C++17
100 / 100
516 ms 62652 KB
#include "horses.h"
#include <bits/stdc++.h>

#define SIZE 500100
#define INF 1<<30
#define MOD 1000000007

using namespace std;

long long mult[SIZE * 3];
int maxLoc[SIZE * 3];
long double lazy[SIZE * 3], A[SIZE], maxValue[SIZE * 3];
int X[SIZE], Y[SIZE], N;

void update(int id, int l, int r, int k){
	if(l == k && r == k){
		mult[id] = X[k];
		return;
	}
	int m = (l + r) >> 1;
	if(m >=	k){
		update(id << 1, l, m, k);
	} else {
		update(id << 1 | 1,  m + 1, r, k);
	}
	
	mult[id] = mult[id << 1] * mult[id << 1 | 1] % MOD;
}

void add(int id,int l, int r,int L,int R, long double diff){
	if(l == L && r == R){
		maxValue[id] += diff;
		lazy[id] += diff;
		return;
	}
	if(lazy[id] != 0){
		lazy[id << 1] +=lazy[id];
		lazy[id << 1 | 1] +=lazy[id];
		maxValue[id << 1] +=lazy[id];
		maxValue[id << 1 | 1] +=lazy[id];
		lazy[id] = 0;
	}
	int m = (l + r) >> 1;
	if(R <= m){
		add(id << 1, l, m, L, R, diff);
	} else if(L > m){
		add(id << 1 | 1,m + 1, r, L, R, diff);
	} else {
		add(id << 1, l, m, L, m, diff);
		add(id << 1 | 1, m + 1, r, m + 1, R, diff);
	}
	if(maxValue[id << 1] > maxValue[id << 1 | 1]){
		maxValue[id] = maxValue[id << 1];
		maxLoc[id] = maxLoc[id << 1];
	} else { 
		maxValue[id] = maxValue[id << 1 | 1];
		maxLoc[id] = maxLoc[id << 1 | 1];
	}
}

long long solve(int id, int l, int r,int L,int R){
	if(L == l && r == R){
		return mult[id];
	}
	int m = (l + r) >> 1;
	if(R <= m){
		return solve( id << 1, l, m, L , R);
	} else if(L > m){
		return solve( id << 1 | 1, m + 1, r, L, R);
	}
	return solve( id << 1, l, m, L , m) * solve( id << 1 | 1, m + 1, r, m + 1, R) % MOD;
}

void build(int id, int l, int r){
	if(l == r){
		maxLoc[id] = l;
		mult[id] = X[l];
		maxValue[id] = A[l];
		return;
	}
	int m = (l + r) >> 1;
	build(id << 1, l, m);
	build(id << 1 | 1, m + 1, r);
	
	if(maxValue[id << 1] > maxValue[id << 1 | 1]){
		maxLoc[id] = maxLoc[id << 1];
		maxValue[id] = maxValue[id << 1];
	} else {
		maxLoc[id] = maxLoc[id << 1 | 1];
		maxValue[id] = maxValue[id << 1 | 1];
	}
	mult[id] = mult[id << 1] * mult[id << 1 | 1] % MOD;
}

int init(int n, int XX[], int YY[]) {
	N = n;
	for(int i = 1; i <= N ; i++){
		X[i] = XX[i - 1];
		Y[i] = YY[i - 1];
	}
	
	for(int i = 1; i <= N; i++){
		A[i] = A[i - 1] + log(X[i]);
	}
	
	for(int i = 1; i <= N; i++){
		A[i] += log(Y[i]);
	}
	
	build(1,1,N);
	return solve(1, 1, N , 1, maxLoc[1]) * Y[maxLoc[1]] % MOD;
}

int updateX(int pos, int val) {
	pos++;
    long double diff = log(val) - log(X[pos]);
    X[pos] = val;
    add(1, 1, N, pos, N, diff);
    update(1, 1, N, pos);
 
    return solve(1, 1, N, 1, maxLoc[1]) * Y[maxLoc[1]] % MOD;
}

int updateY(int pos, int val) {
	pos++;
	long double diff = log(val) - log(Y[pos]);
	Y[pos] = val;
	add(1,1,N,pos,pos,diff);
	
	return solve(1,1,N,1,maxLoc[1]) * Y[maxLoc[1]] % MOD;
}

Compilation message

horses.cpp: In function 'int init(int, int*, int*)':
horses.cpp:111:54: warning: conversion to 'int' from 'long long int' may alter its value [-Wconversion]
  return solve(1, 1, N , 1, maxLoc[1]) * Y[maxLoc[1]] % MOD;
                                                      ^
horses.cpp: In function 'int updateX(int, int)':
horses.cpp:121:56: warning: conversion to 'int' from 'long long int' may alter its value [-Wconversion]
     return solve(1, 1, N, 1, maxLoc[1]) * Y[maxLoc[1]] % MOD;
                                                        ^
horses.cpp: In function 'int updateY(int, int)':
horses.cpp:130:49: warning: conversion to 'int' from 'long long int' may alter its value [-Wconversion]
  return solve(1,1,N,1,maxLoc[1]) * Y[maxLoc[1]] % 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 3 ms 444 KB Output is correct
4 Correct 3 ms 600 KB Output is correct
5 Correct 2 ms 600 KB Output is correct
6 Correct 3 ms 600 KB Output is correct
7 Correct 3 ms 600 KB Output is correct
8 Correct 3 ms 620 KB Output is correct
9 Correct 2 ms 620 KB Output is correct
10 Correct 2 ms 620 KB Output is correct
11 Correct 3 ms 620 KB Output is correct
12 Correct 2 ms 620 KB Output is correct
13 Correct 3 ms 636 KB Output is correct
14 Correct 3 ms 764 KB Output is correct
15 Correct 2 ms 764 KB Output is correct
16 Correct 3 ms 764 KB Output is correct
17 Correct 2 ms 764 KB Output is correct
18 Correct 2 ms 764 KB Output is correct
19 Correct 3 ms 764 KB Output is correct
20 Correct 3 ms 764 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 764 KB Output is correct
2 Correct 2 ms 764 KB Output is correct
3 Correct 2 ms 764 KB Output is correct
4 Correct 2 ms 764 KB Output is correct
5 Correct 2 ms 764 KB Output is correct
6 Correct 3 ms 764 KB Output is correct
7 Correct 2 ms 764 KB Output is correct
8 Correct 2 ms 764 KB Output is correct
9 Correct 3 ms 764 KB Output is correct
10 Correct 2 ms 764 KB Output is correct
11 Correct 4 ms 764 KB Output is correct
12 Correct 3 ms 764 KB Output is correct
13 Correct 3 ms 764 KB Output is correct
14 Correct 3 ms 764 KB Output is correct
15 Correct 3 ms 764 KB Output is correct
16 Correct 3 ms 764 KB Output is correct
17 Correct 2 ms 764 KB Output is correct
18 Correct 3 ms 764 KB Output is correct
19 Correct 3 ms 764 KB Output is correct
20 Correct 3 ms 764 KB Output is correct
21 Correct 3 ms 764 KB Output is correct
22 Correct 2 ms 764 KB Output is correct
23 Correct 3 ms 764 KB Output is correct
24 Correct 4 ms 764 KB Output is correct
25 Correct 4 ms 780 KB Output is correct
26 Correct 3 ms 780 KB Output is correct
27 Correct 3 ms 796 KB Output is correct
28 Correct 4 ms 796 KB Output is correct
29 Correct 4 ms 796 KB Output is correct
30 Correct 5 ms 796 KB Output is correct
31 Correct 4 ms 812 KB Output is correct
32 Correct 4 ms 816 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 199 ms 46124 KB Output is correct
2 Correct 450 ms 62480 KB Output is correct
3 Correct 364 ms 62500 KB Output is correct
4 Correct 407 ms 62652 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 62652 KB Output is correct
2 Correct 3 ms 62652 KB Output is correct
3 Correct 3 ms 62652 KB Output is correct
4 Correct 2 ms 62652 KB Output is correct
5 Correct 2 ms 62652 KB Output is correct
6 Correct 3 ms 62652 KB Output is correct
7 Correct 3 ms 62652 KB Output is correct
8 Correct 3 ms 62652 KB Output is correct
9 Correct 2 ms 62652 KB Output is correct
10 Correct 2 ms 62652 KB Output is correct
11 Correct 3 ms 62652 KB Output is correct
12 Correct 3 ms 62652 KB Output is correct
13 Correct 4 ms 62652 KB Output is correct
14 Correct 2 ms 62652 KB Output is correct
15 Correct 3 ms 62652 KB Output is correct
16 Correct 3 ms 62652 KB Output is correct
17 Correct 3 ms 62652 KB Output is correct
18 Correct 2 ms 62652 KB Output is correct
19 Correct 2 ms 62652 KB Output is correct
20 Correct 3 ms 62652 KB Output is correct
21 Correct 3 ms 62652 KB Output is correct
22 Correct 2 ms 62652 KB Output is correct
23 Correct 4 ms 62652 KB Output is correct
24 Correct 4 ms 62652 KB Output is correct
25 Correct 4 ms 62652 KB Output is correct
26 Correct 3 ms 62652 KB Output is correct
27 Correct 4 ms 62652 KB Output is correct
28 Correct 4 ms 62652 KB Output is correct
29 Correct 3 ms 62652 KB Output is correct
30 Correct 3 ms 62652 KB Output is correct
31 Correct 3 ms 62652 KB Output is correct
32 Correct 3 ms 62652 KB Output is correct
33 Correct 165 ms 62652 KB Output is correct
34 Correct 179 ms 62652 KB Output is correct
35 Correct 129 ms 62652 KB Output is correct
36 Correct 136 ms 62652 KB Output is correct
37 Correct 123 ms 62652 KB Output is correct
38 Correct 119 ms 62652 KB Output is correct
39 Correct 81 ms 62652 KB Output is correct
40 Correct 125 ms 62652 KB Output is correct
41 Correct 80 ms 62652 KB Output is correct
42 Correct 80 ms 62652 KB Output is correct
43 Correct 125 ms 62652 KB Output is correct
44 Correct 94 ms 62652 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 62652 KB Output is correct
2 Correct 2 ms 62652 KB Output is correct
3 Correct 3 ms 62652 KB Output is correct
4 Correct 3 ms 62652 KB Output is correct
5 Correct 2 ms 62652 KB Output is correct
6 Correct 2 ms 62652 KB Output is correct
7 Correct 3 ms 62652 KB Output is correct
8 Correct 2 ms 62652 KB Output is correct
9 Correct 3 ms 62652 KB Output is correct
10 Correct 3 ms 62652 KB Output is correct
11 Correct 3 ms 62652 KB Output is correct
12 Correct 3 ms 62652 KB Output is correct
13 Correct 3 ms 62652 KB Output is correct
14 Correct 3 ms 62652 KB Output is correct
15 Correct 2 ms 62652 KB Output is correct
16 Correct 2 ms 62652 KB Output is correct
17 Correct 3 ms 62652 KB Output is correct
18 Correct 2 ms 62652 KB Output is correct
19 Correct 2 ms 62652 KB Output is correct
20 Correct 3 ms 62652 KB Output is correct
21 Correct 4 ms 62652 KB Output is correct
22 Correct 3 ms 62652 KB Output is correct
23 Correct 5 ms 62652 KB Output is correct
24 Correct 4 ms 62652 KB Output is correct
25 Correct 4 ms 62652 KB Output is correct
26 Correct 4 ms 62652 KB Output is correct
27 Correct 5 ms 62652 KB Output is correct
28 Correct 3 ms 62652 KB Output is correct
29 Correct 4 ms 62652 KB Output is correct
30 Correct 5 ms 62652 KB Output is correct
31 Correct 4 ms 62652 KB Output is correct
32 Correct 4 ms 62652 KB Output is correct
33 Correct 183 ms 62652 KB Output is correct
34 Correct 411 ms 62652 KB Output is correct
35 Correct 371 ms 62652 KB Output is correct
36 Correct 516 ms 62652 KB Output is correct
37 Correct 175 ms 62652 KB Output is correct
38 Correct 137 ms 62652 KB Output is correct
39 Correct 162 ms 62652 KB Output is correct
40 Correct 150 ms 62652 KB Output is correct
41 Correct 114 ms 62652 KB Output is correct
42 Correct 118 ms 62652 KB Output is correct
43 Correct 79 ms 62652 KB Output is correct
44 Correct 126 ms 62652 KB Output is correct
45 Correct 84 ms 62652 KB Output is correct
46 Correct 82 ms 62652 KB Output is correct
47 Correct 117 ms 62652 KB Output is correct
48 Correct 115 ms 62652 KB Output is correct
49 Correct 456 ms 62652 KB Output is correct
50 Correct 347 ms 62652 KB Output is correct
51 Correct 211 ms 62652 KB Output is correct
52 Correct 205 ms 62652 KB Output is correct
53 Correct 317 ms 62652 KB Output is correct
54 Correct 273 ms 62652 KB Output is correct
55 Correct 182 ms 62652 KB Output is correct
56 Correct 261 ms 62652 KB Output is correct
57 Correct 141 ms 62652 KB Output is correct
58 Correct 153 ms 62652 KB Output is correct
59 Correct 116 ms 62652 KB Output is correct