Submission #24116

# Submission time Handle Problem Language Result Execution time Memory
24116 2017-05-31T09:17:04 Z Nirjhor Horses (IOI15_horses) C++14
100 / 100
579 ms 60724 KB
#include <bits/stdc++.h>
#include "horses.h"

using namespace std;

typedef long long ll;
typedef long double ld;

const ld EPS = 1e-9;
const int N = 5e5 + 10;
const int MOD = 1e9 + 7;

int n;
ll x[N], y[N];
int tree[4 * N];
ld xlog[N], ylog[N];
ll product[N + N];
ld logsum[N + N];

void init_product (void) {
	for (int i = 0; i < n; ++i) {
		product[n + i] = x[i] % MOD;
	}
	for (int i = n - 1; i; --i) {
		product[i] = (product[i << 1] * product[i << 1 | 1]) % MOD;
	}
}

void modify_product (int p, ll v) {
	for (product[p += n] = v; p > 1; p >>= 1) {
		product[p >> 1] = (product[p] * product[p ^ 1]) % MOD;
	}
}

ll find_product (int l, int r) {
	ll ret = 1LL;
	for (l += n, r += n; l < r; l >>= 1, r >>= 1) {
		if (l & 1) ret *= product[l++], ret %= MOD;
		if (r & 1) ret *= product[--r], ret %= MOD;
	}
	return ret;
}

void init_logsum (void) {
	for (int i = 0; i < n; ++i) {
		logsum[n + i] = xlog[i];
	}
	for (int i = n - 1; i; --i) {
		logsum[i] = logsum[i << 1] + logsum[i << 1 | 1];
	}
}

void modify_logsum (int p, ld v) {
	for (logsum[p += n] = v; p > 1; p >>= 1) {
		logsum[p >> 1] = logsum[p] + logsum[p ^ 1];
	}
}

ld find_logsum (int l, int r) {
	ld ret = 0.0;
	for (l += n, r += n; l < r; l >>= 1, r >>= 1) {
		if (l & 1) ret += logsum[l++];
		if (r & 1) ret += logsum[--r];
	}
	return ret;
}

int merged (int p, int q) {
	if (p > q) swap(p, q);
	return (find_logsum(p + 1, q + 1) - ylog[p] + ylog[q] > -EPS) ? q : p;
}

void init_tree (int u, int b, int e) {
	if (b == e) {
		tree[u] = b;
		return;
	}
	int l = u << 1, r = l | 1, m = b + e >> 1;
	init_tree(l, b, m), init_tree(r, m + 1, e);
	tree[u] = merged(tree[l], tree[r]);
}

void modify_tree (int u, int b, int e, int p) {
	if (b > p or e < p) return;
	if (b == e) return;
	int l = u << 1, r = l | 1, m = b + e >> 1;
	modify_tree(l, b, m, p), modify_tree(r, m + 1, e, p);
	tree[u] = merged(tree[l], tree[r]);
}

ll value (int index) {
	return (find_product(0, index + 1) * y[index]) % 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];
		xlog[i] = log(x[i]), ylog[i] = log(y[i]);
	}
	init_product();
	init_logsum();
	init_tree(1, 0, n - 1);
	return value(tree[1]);
}

int updateX (int pos, int val) {
	x[pos] = val, xlog[pos] = log(val);
	modify_product(pos, x[pos]);
	modify_logsum(pos, xlog[pos]);
	modify_tree(1, 0, n - 1, pos);
	return value(tree[1]);
}

int updateY (int pos, int val) {
	y[pos] = val, ylog[pos] = log(val);
	modify_tree(1, 0, n - 1, pos);
	return value(tree[1]);
}

Compilation message

horses.cpp: In function 'void init_tree(int, int, int)':
horses.cpp:78:35: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
  int l = u << 1, r = l | 1, m = b + e >> 1;
                                   ^
horses.cpp: In function 'void modify_tree(int, int, int, int)':
horses.cpp:86:35: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
  int l = u << 1, r = l | 1, m = b + e >> 1;
                                   ^
horses.cpp: In function 'int init(int, int*, int*)':
horses.cpp:95:34: warning: declaration of 'N' shadows a global declaration [-Wshadow]
 int init (int N, int X[], int Y[]) {
                                  ^
horses.cpp:10:11: note: shadowed declaration is here
 const int N = 5e5 + 10;
           ^
horses.cpp:104:22: warning: conversion to 'int' from 'll {aka long long int}' may alter its value [-Wconversion]
  return value(tree[1]);
                      ^
horses.cpp: In function 'int updateX(int, int)':
horses.cpp:112:22: warning: conversion to 'int' from 'll {aka long long int}' may alter its value [-Wconversion]
  return value(tree[1]);
                      ^
horses.cpp: In function 'int updateY(int, int)':
horses.cpp:118:22: warning: conversion to 'int' from 'll {aka long long int}' may alter its value [-Wconversion]
  return value(tree[1]);
                      ^
# Verdict Execution time Memory Grader output
1 Correct 0 ms 56812 KB Output is correct
2 Correct 0 ms 56812 KB Output is correct
3 Correct 0 ms 56812 KB Output is correct
4 Correct 0 ms 56812 KB Output is correct
5 Correct 0 ms 56812 KB Output is correct
6 Correct 0 ms 56812 KB Output is correct
7 Correct 0 ms 56812 KB Output is correct
8 Correct 0 ms 56812 KB Output is correct
9 Correct 0 ms 56812 KB Output is correct
10 Correct 0 ms 56812 KB Output is correct
11 Correct 0 ms 56812 KB Output is correct
12 Correct 0 ms 56812 KB Output is correct
13 Correct 0 ms 56812 KB Output is correct
14 Correct 0 ms 56812 KB Output is correct
15 Correct 0 ms 56812 KB Output is correct
16 Correct 0 ms 56812 KB Output is correct
17 Correct 0 ms 56812 KB Output is correct
18 Correct 0 ms 56812 KB Output is correct
19 Correct 0 ms 56812 KB Output is correct
20 Correct 0 ms 56812 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 56812 KB Output is correct
2 Correct 0 ms 56812 KB Output is correct
3 Correct 0 ms 56812 KB Output is correct
4 Correct 0 ms 56812 KB Output is correct
5 Correct 0 ms 56812 KB Output is correct
6 Correct 0 ms 56812 KB Output is correct
7 Correct 0 ms 56812 KB Output is correct
8 Correct 0 ms 56812 KB Output is correct
9 Correct 0 ms 56812 KB Output is correct
10 Correct 0 ms 56812 KB Output is correct
11 Correct 0 ms 56812 KB Output is correct
12 Correct 0 ms 56812 KB Output is correct
13 Correct 0 ms 56812 KB Output is correct
14 Correct 0 ms 56812 KB Output is correct
15 Correct 0 ms 56812 KB Output is correct
16 Correct 0 ms 56812 KB Output is correct
17 Correct 0 ms 56812 KB Output is correct
18 Correct 0 ms 56812 KB Output is correct
19 Correct 0 ms 56812 KB Output is correct
20 Correct 0 ms 56812 KB Output is correct
21 Correct 0 ms 56812 KB Output is correct
22 Correct 0 ms 56812 KB Output is correct
23 Correct 0 ms 56812 KB Output is correct
24 Correct 0 ms 56812 KB Output is correct
25 Correct 0 ms 56812 KB Output is correct
26 Correct 0 ms 56812 KB Output is correct
27 Correct 0 ms 56812 KB Output is correct
28 Correct 0 ms 56812 KB Output is correct
29 Correct 0 ms 56812 KB Output is correct
30 Correct 0 ms 56812 KB Output is correct
31 Correct 0 ms 56812 KB Output is correct
32 Correct 0 ms 56812 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 153 ms 60724 KB Output is correct
2 Correct 416 ms 60724 KB Output is correct
3 Correct 413 ms 60724 KB Output is correct
4 Correct 499 ms 60724 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 56812 KB Output is correct
2 Correct 0 ms 56812 KB Output is correct
3 Correct 0 ms 56812 KB Output is correct
4 Correct 0 ms 56812 KB Output is correct
5 Correct 0 ms 56812 KB Output is correct
6 Correct 0 ms 56812 KB Output is correct
7 Correct 0 ms 56812 KB Output is correct
8 Correct 0 ms 56812 KB Output is correct
9 Correct 0 ms 56812 KB Output is correct
10 Correct 0 ms 56812 KB Output is correct
11 Correct 0 ms 56812 KB Output is correct
12 Correct 0 ms 56812 KB Output is correct
13 Correct 0 ms 56812 KB Output is correct
14 Correct 0 ms 56812 KB Output is correct
15 Correct 0 ms 56812 KB Output is correct
16 Correct 0 ms 56812 KB Output is correct
17 Correct 0 ms 56812 KB Output is correct
18 Correct 0 ms 56812 KB Output is correct
19 Correct 0 ms 56812 KB Output is correct
20 Correct 0 ms 56812 KB Output is correct
21 Correct 0 ms 56812 KB Output is correct
22 Correct 0 ms 56812 KB Output is correct
23 Correct 0 ms 56812 KB Output is correct
24 Correct 0 ms 56812 KB Output is correct
25 Correct 0 ms 56812 KB Output is correct
26 Correct 0 ms 56812 KB Output is correct
27 Correct 0 ms 56812 KB Output is correct
28 Correct 0 ms 56812 KB Output is correct
29 Correct 0 ms 56812 KB Output is correct
30 Correct 0 ms 56812 KB Output is correct
31 Correct 0 ms 56812 KB Output is correct
32 Correct 0 ms 56812 KB Output is correct
33 Correct 119 ms 60724 KB Output is correct
34 Correct 123 ms 60724 KB Output is correct
35 Correct 106 ms 60724 KB Output is correct
36 Correct 99 ms 60724 KB Output is correct
37 Correct 99 ms 60724 KB Output is correct
38 Correct 106 ms 60724 KB Output is correct
39 Correct 46 ms 60724 KB Output is correct
40 Correct 73 ms 60724 KB Output is correct
41 Correct 53 ms 60724 KB Output is correct
42 Correct 59 ms 60724 KB Output is correct
43 Correct 76 ms 60724 KB Output is correct
44 Correct 89 ms 60724 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 56812 KB Output is correct
2 Correct 0 ms 56812 KB Output is correct
3 Correct 0 ms 56812 KB Output is correct
4 Correct 0 ms 56812 KB Output is correct
5 Correct 0 ms 56812 KB Output is correct
6 Correct 0 ms 56812 KB Output is correct
7 Correct 0 ms 56812 KB Output is correct
8 Correct 0 ms 56812 KB Output is correct
9 Correct 0 ms 56812 KB Output is correct
10 Correct 0 ms 56812 KB Output is correct
11 Correct 0 ms 56812 KB Output is correct
12 Correct 0 ms 56812 KB Output is correct
13 Correct 0 ms 56812 KB Output is correct
14 Correct 0 ms 56812 KB Output is correct
15 Correct 0 ms 56812 KB Output is correct
16 Correct 0 ms 56812 KB Output is correct
17 Correct 0 ms 56812 KB Output is correct
18 Correct 0 ms 56812 KB Output is correct
19 Correct 0 ms 56812 KB Output is correct
20 Correct 0 ms 56812 KB Output is correct
21 Correct 0 ms 56812 KB Output is correct
22 Correct 0 ms 56812 KB Output is correct
23 Correct 0 ms 56812 KB Output is correct
24 Correct 0 ms 56812 KB Output is correct
25 Correct 0 ms 56812 KB Output is correct
26 Correct 0 ms 56812 KB Output is correct
27 Correct 0 ms 56812 KB Output is correct
28 Correct 0 ms 56812 KB Output is correct
29 Correct 0 ms 56812 KB Output is correct
30 Correct 0 ms 56812 KB Output is correct
31 Correct 0 ms 56812 KB Output is correct
32 Correct 0 ms 56812 KB Output is correct
33 Correct 153 ms 60724 KB Output is correct
34 Correct 496 ms 60724 KB Output is correct
35 Correct 449 ms 60724 KB Output is correct
36 Correct 579 ms 60724 KB Output is correct
37 Correct 109 ms 60724 KB Output is correct
38 Correct 113 ms 60724 KB Output is correct
39 Correct 96 ms 60724 KB Output is correct
40 Correct 103 ms 60724 KB Output is correct
41 Correct 83 ms 60724 KB Output is correct
42 Correct 103 ms 60724 KB Output is correct
43 Correct 46 ms 60724 KB Output is correct
44 Correct 73 ms 60724 KB Output is correct
45 Correct 56 ms 60724 KB Output is correct
46 Correct 39 ms 60724 KB Output is correct
47 Correct 66 ms 60724 KB Output is correct
48 Correct 69 ms 60724 KB Output is correct
49 Correct 453 ms 60724 KB Output is correct
50 Correct 486 ms 60724 KB Output is correct
51 Correct 239 ms 60724 KB Output is correct
52 Correct 226 ms 60724 KB Output is correct
53 Correct 516 ms 60724 KB Output is correct
54 Correct 233 ms 60724 KB Output is correct
55 Correct 183 ms 60724 KB Output is correct
56 Correct 199 ms 60724 KB Output is correct
57 Correct 179 ms 60724 KB Output is correct
58 Correct 166 ms 60724 KB Output is correct
59 Correct 53 ms 60724 KB Output is correct