Submission #132525

# Submission time Handle Problem Language Result Execution time Memory
132525 2019-07-19T05:51:51 Z antimirage Horses (IOI15_horses) C++14
100 / 100
719 ms 126840 KB
#include "horses.h"
#include <bits/stdc++.h>

#define fr first
#define sc second
#define mk make_pair
#define pb push_back
#define all(s) s.begin(), s.end()

using namespace std;

const int N = 5e5 + 5, mod = 1e9 + 7;

int a[N], b[N], n;
long long pr[N];

long double pref[N], eps = 1e-13;

struct asd {
	long long val, must;
	long double mx, add;
	
	asd() {
		must = 1;
	}
};

asd t[N * 4];

void build (int v = 1, int tl = 0, int tr = n - 1) {
	if (tl == tr) {
		t[v].val = pr[tl] * 1ll * b[tl] % mod;
		t[v].mx = pref[tl] + log10(b[tl] + eps);
	} else {
		int tm = (tl + tr) >> 1;
		build(v + v, tl, tm);
		build(v + v + 1, tm + 1, tr);
		
		if (t[v + v].mx - t[v + v + 1].mx > eps) {
			t[v].val = t[v + v].val;
			t[v].mx = t[v + v].mx;
		} else {
			t[v].val = t[v + v + 1].val;
			t[v].mx = t[v + v + 1].mx;
		}
	}
}

int init(int N, int X[], int Y[]) {
	n = N;
	
	for (int i = 0; i < n; i++) {
		a[i] = X[i]; b[i] = Y[i];
		pref[i] = (i == 0 ? 0 : pref[i - 1]) + log10(a[i] + eps);
		pr[i] = (i == 0 ? 1 : pr[i - 1]) * 1ll * a[i] % mod;
	}
	build();
	
	return t[1].val;
}
int binpow (int a, int b) {
	if (b == 0)
		return 1;
	if (b & 1)
		return binpow(a, b - 1) * 1ll * a % mod;
		
	int res = binpow(a, b >> 1);
	return res * 1ll * res % mod;
}
void push (int v, int tl, int tr) {
	t[v].mx += t[v].add;
	t[v].val = t[v].val * 1ll * t[v].must % mod;
	if (tl != tr) {
		t[v + v].add += t[v].add;
		t[v + v + 1].add += t[v].add;
		
		t[v + v].must = t[v + v].must * 1ll * t[v].must % mod;
		t[v + v + 1].must = t[v + v + 1].must * 1ll * t[v].must % mod;
	}
	t[v].must = 1;
	t[v].add = 0;
}
void update (int l, int r, long double val, int mult, int v = 1, int tl = 0, int tr = n - 1) {
	push(v, tl, tr);
	if (l > tr || tl > r)
		return;
	if (l <= tl && tr <= r) {
		t[v].add += val;
		t[v].must = t[v].must * 1ll * mult % mod;
		push(v, tl, tr);
		return;
	}
	int tm = (tl + tr) >> 1;
	
	update(l, r, val, mult, v + v, tl, tm);
	update(l, r, val, mult, v + v + 1, tm + 1, tr);
	
	if (t[v + v].mx - t[v + v + 1].mx > eps) {
		t[v].val = t[v + v].val;
		t[v].mx = t[v + v].mx;
	} else {
		t[v].val = t[v + v + 1].val;
		t[v].mx = t[v + v + 1].mx;
	}
}
int updateX(int pos, int val) {
	update(pos, n - 1, -log10(a[pos] + eps), binpow(a[pos], mod - 2) );
	a[pos] = val;
	update(pos, n - 1, log10(a[pos] + eps), a[pos]);
	return t[1].val;
}

int updateY(int pos, int val) {
	update(pos, pos, -log10(b[pos] + eps), binpow(b[pos], mod - 2));
	b[pos] = val;
	update(pos, pos, log10(b[pos] + eps), b[pos]);
	return t[1].val;
}

Compilation message

horses.cpp: In function 'int init(int, int*, int*)':
horses.cpp:49:33: warning: declaration of 'N' shadows a global declaration [-Wshadow]
 int init(int N, int X[], int Y[]) {
                                 ^
horses.cpp:12:11: note: shadowed declaration is here
 const int N = 5e5 + 5, mod = 1e9 + 7;
           ^
horses.cpp:59:14: warning: conversion to 'int' from 'long long int' may alter its value [-Wconversion]
  return t[1].val;
         ~~~~~^~~
horses.cpp: In function 'int binpow(int, int)':
horses.cpp:61:25: warning: declaration of 'b' shadows a global declaration [-Wshadow]
 int binpow (int a, int b) {
                         ^
horses.cpp:14:11: note: shadowed declaration is here
 int a[N], b[N], n;
           ^
horses.cpp:61:25: warning: declaration of 'a' shadows a global declaration [-Wshadow]
 int binpow (int a, int b) {
                         ^
horses.cpp:14:5: note: shadowed declaration is here
 int a[N], b[N], n;
     ^
horses.cpp:65:37: warning: conversion to 'int' from 'long long int' may alter its value [-Wconversion]
   return binpow(a, b - 1) * 1ll * a % mod;
          ~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~
horses.cpp:68:25: warning: conversion to 'int' from 'long long int' may alter its value [-Wconversion]
  return res * 1ll * res % mod;
         ~~~~~~~~~~~~~~~~^~~~~
horses.cpp: In function 'int updateX(int, int)':
horses.cpp:110:14: warning: conversion to 'int' from 'long long int' may alter its value [-Wconversion]
  return t[1].val;
         ~~~~~^~~
horses.cpp: In function 'int updateY(int, int)':
horses.cpp:117:14: warning: conversion to 'int' from 'long long int' may alter its value [-Wconversion]
  return t[1].val;
         ~~~~~^~~
# Verdict Execution time Memory Grader output
1 Correct 73 ms 94328 KB Output is correct
2 Correct 72 ms 94324 KB Output is correct
3 Correct 72 ms 94200 KB Output is correct
4 Correct 73 ms 94300 KB Output is correct
5 Correct 73 ms 94436 KB Output is correct
6 Correct 74 ms 94328 KB Output is correct
7 Correct 74 ms 94328 KB Output is correct
8 Correct 73 ms 94328 KB Output is correct
9 Correct 74 ms 94332 KB Output is correct
10 Correct 73 ms 94328 KB Output is correct
11 Correct 74 ms 94456 KB Output is correct
12 Correct 73 ms 94328 KB Output is correct
13 Correct 73 ms 94328 KB Output is correct
14 Correct 72 ms 94328 KB Output is correct
15 Correct 73 ms 94328 KB Output is correct
16 Correct 79 ms 94348 KB Output is correct
17 Correct 73 ms 94328 KB Output is correct
18 Correct 74 ms 94332 KB Output is correct
19 Correct 72 ms 94328 KB Output is correct
20 Correct 72 ms 94204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 73 ms 94204 KB Output is correct
2 Correct 73 ms 94328 KB Output is correct
3 Correct 73 ms 94304 KB Output is correct
4 Correct 72 ms 94328 KB Output is correct
5 Correct 77 ms 94408 KB Output is correct
6 Correct 72 ms 94328 KB Output is correct
7 Correct 73 ms 94312 KB Output is correct
8 Correct 76 ms 94200 KB Output is correct
9 Correct 73 ms 94328 KB Output is correct
10 Correct 72 ms 94328 KB Output is correct
11 Correct 73 ms 94272 KB Output is correct
12 Correct 73 ms 94328 KB Output is correct
13 Correct 73 ms 94204 KB Output is correct
14 Correct 73 ms 94224 KB Output is correct
15 Correct 72 ms 94328 KB Output is correct
16 Correct 72 ms 94228 KB Output is correct
17 Correct 73 ms 94328 KB Output is correct
18 Correct 72 ms 94328 KB Output is correct
19 Correct 73 ms 94328 KB Output is correct
20 Correct 72 ms 94200 KB Output is correct
21 Correct 73 ms 94204 KB Output is correct
22 Correct 74 ms 94200 KB Output is correct
23 Correct 87 ms 94328 KB Output is correct
24 Correct 80 ms 94428 KB Output is correct
25 Correct 75 ms 94372 KB Output is correct
26 Correct 75 ms 94328 KB Output is correct
27 Correct 76 ms 94480 KB Output is correct
28 Correct 75 ms 94328 KB Output is correct
29 Correct 75 ms 94328 KB Output is correct
30 Correct 75 ms 94328 KB Output is correct
31 Correct 74 ms 94328 KB Output is correct
32 Correct 75 ms 94328 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 493 ms 115024 KB Output is correct
2 Correct 621 ms 114936 KB Output is correct
3 Correct 598 ms 115052 KB Output is correct
4 Correct 613 ms 115000 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 72 ms 94200 KB Output is correct
2 Correct 74 ms 94332 KB Output is correct
3 Correct 72 ms 94200 KB Output is correct
4 Correct 72 ms 94364 KB Output is correct
5 Correct 72 ms 94252 KB Output is correct
6 Correct 72 ms 94308 KB Output is correct
7 Correct 73 ms 94328 KB Output is correct
8 Correct 72 ms 94328 KB Output is correct
9 Correct 73 ms 94328 KB Output is correct
10 Correct 73 ms 94328 KB Output is correct
11 Correct 73 ms 94340 KB Output is correct
12 Correct 72 ms 94328 KB Output is correct
13 Correct 73 ms 94272 KB Output is correct
14 Correct 73 ms 94228 KB Output is correct
15 Correct 79 ms 94328 KB Output is correct
16 Correct 72 ms 94332 KB Output is correct
17 Correct 72 ms 94328 KB Output is correct
18 Correct 72 ms 94328 KB Output is correct
19 Correct 72 ms 94200 KB Output is correct
20 Correct 73 ms 94328 KB Output is correct
21 Correct 72 ms 94456 KB Output is correct
22 Correct 72 ms 94328 KB Output is correct
23 Correct 75 ms 94376 KB Output is correct
24 Correct 76 ms 94300 KB Output is correct
25 Correct 74 ms 94428 KB Output is correct
26 Correct 74 ms 94328 KB Output is correct
27 Correct 75 ms 94332 KB Output is correct
28 Correct 75 ms 94328 KB Output is correct
29 Correct 75 ms 94328 KB Output is correct
30 Correct 74 ms 94328 KB Output is correct
31 Correct 74 ms 94328 KB Output is correct
32 Correct 76 ms 94328 KB Output is correct
33 Correct 207 ms 113980 KB Output is correct
34 Correct 230 ms 113912 KB Output is correct
35 Correct 209 ms 113912 KB Output is correct
36 Correct 213 ms 113908 KB Output is correct
37 Correct 201 ms 114004 KB Output is correct
38 Correct 188 ms 113944 KB Output is correct
39 Correct 196 ms 113816 KB Output is correct
40 Correct 213 ms 113984 KB Output is correct
41 Correct 188 ms 113912 KB Output is correct
42 Correct 188 ms 113912 KB Output is correct
43 Correct 170 ms 113840 KB Output is correct
44 Correct 168 ms 113816 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 72 ms 94260 KB Output is correct
2 Correct 73 ms 94316 KB Output is correct
3 Correct 72 ms 94260 KB Output is correct
4 Correct 73 ms 94456 KB Output is correct
5 Correct 73 ms 94220 KB Output is correct
6 Correct 72 ms 94204 KB Output is correct
7 Correct 72 ms 94300 KB Output is correct
8 Correct 73 ms 94300 KB Output is correct
9 Correct 73 ms 94204 KB Output is correct
10 Correct 73 ms 94328 KB Output is correct
11 Correct 72 ms 94328 KB Output is correct
12 Correct 73 ms 94328 KB Output is correct
13 Correct 74 ms 94204 KB Output is correct
14 Correct 73 ms 94216 KB Output is correct
15 Correct 72 ms 94328 KB Output is correct
16 Correct 73 ms 94284 KB Output is correct
17 Correct 73 ms 94328 KB Output is correct
18 Correct 72 ms 94328 KB Output is correct
19 Correct 73 ms 94328 KB Output is correct
20 Correct 72 ms 94328 KB Output is correct
21 Correct 75 ms 94332 KB Output is correct
22 Correct 72 ms 94332 KB Output is correct
23 Correct 68 ms 94328 KB Output is correct
24 Correct 75 ms 94260 KB Output is correct
25 Correct 75 ms 94328 KB Output is correct
26 Correct 75 ms 94328 KB Output is correct
27 Correct 75 ms 94328 KB Output is correct
28 Correct 75 ms 94328 KB Output is correct
29 Correct 74 ms 94288 KB Output is correct
30 Correct 75 ms 94328 KB Output is correct
31 Correct 75 ms 94456 KB Output is correct
32 Correct 74 ms 94328 KB Output is correct
33 Correct 471 ms 114820 KB Output is correct
34 Correct 619 ms 114984 KB Output is correct
35 Correct 597 ms 115100 KB Output is correct
36 Correct 611 ms 114808 KB Output is correct
37 Correct 209 ms 114040 KB Output is correct
38 Correct 208 ms 113888 KB Output is correct
39 Correct 208 ms 114004 KB Output is correct
40 Correct 213 ms 113912 KB Output is correct
41 Correct 210 ms 114028 KB Output is correct
42 Correct 188 ms 113912 KB Output is correct
43 Correct 183 ms 114040 KB Output is correct
44 Correct 211 ms 113996 KB Output is correct
45 Correct 187 ms 113968 KB Output is correct
46 Correct 214 ms 113928 KB Output is correct
47 Correct 192 ms 113884 KB Output is correct
48 Correct 172 ms 113804 KB Output is correct
49 Correct 719 ms 120056 KB Output is correct
50 Correct 660 ms 119804 KB Output is correct
51 Correct 496 ms 126840 KB Output is correct
52 Correct 522 ms 126324 KB Output is correct
53 Correct 607 ms 118276 KB Output is correct
54 Correct 506 ms 118916 KB Output is correct
55 Correct 459 ms 117016 KB Output is correct
56 Correct 520 ms 121720 KB Output is correct
57 Correct 477 ms 117728 KB Output is correct
58 Correct 487 ms 118248 KB Output is correct
59 Correct 170 ms 120312 KB Output is correct