# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
66221 |
2018-08-10T05:04:39 Z |
daniel_02 |
Horses (IOI15_horses) |
C++17 |
|
686 ms |
210796 KB |
#include "horses.h"
#include "bits/stdc++.h"
#define ll long long
#define fr first
#define sc second
//#define double long double
using namespace std;
const int MOD = 1e9 + 7;
const int sz = 5e6 + 7;
ll n, x[sz], y[sz];
pair<double, ll> t[sz * 2], ad[sz * 2], an[sz];
pair<double, ll> maxp(pair<double, ll> a, pair<double, ll> b)
{
if (a.fr > b.fr)
{
return a;
}
else
{
return b;
}
}
ll bin_pow(ll a, ll k)
{
if (k == 1)return a;
if (k & 1)
return ((a * 1LL * bin_pow(a, k - 1)) % MOD);
else
{
ll b = bin_pow(a, k / 2);
return ((b * b) % MOD);
}
}
void build(int v, int tl, int tr)
{
if (tl == tr)
{
t[v].fr = an[tl].fr;
t[v].sc = an[tl].sc;
}
else
{
int mid = (tl + tr) >> 1;
build(v + v, tl, mid);
build(v + v + 1, mid + 1, tr);
t[v] = maxp(t[v + v], t[v + v + 1]);
}
}
void push(int v, int tl, int tr)
{
if (ad[v].sc == -1)return;
t[v].fr += ad[v].fr;
t[v].sc = (ad[v].sc * t[v].sc) % MOD;
ad[v + v].fr += ad[v].fr;
ad[v + v + 1].fr += ad[v].fr;
if (ad[v + v].sc == -1)ad[v + v].sc = 1;
if (ad[v + v + 1].sc == -1)ad[v + v + 1].sc = 1;
ad[v + v].sc = (ad[v].sc * ad[v + v].sc) % MOD;
ad[v + v + 1].sc = (ad[v].sc * ad[v + v + 1].sc) % MOD;
if (t[v].sc < -1)
t[v].sc *= -1;
ad[v].fr = 0;
ad[v].sc = -1;
}
void updy(int v, int tl, int tr, int pos, double val, ll val1)
{
push(v, tl, tr);
push(v + v, tl, tr);
push(v + v + 1, tl, tr);
if (t[v].sc < -1)
t[v].sc *= -1;
if (tl == tr)
{
t[v].fr += val;
t[v].sc = (t[v].sc * val1) % MOD;
}
else
{
int mid = (tl + tr) >> 1;
if (mid >= pos)
updy(v + v, tl, mid, pos, val, val1);
else
updy(v + v + 1, mid + 1, tr, pos, val, val1);
push(v, tl, tr);
push(v + v, tl, tr);
push(v + v + 1, tl, tr);
t[v] = maxp(t[v + v], t[v + v + 1]);
}
}
void updx(int v, int tl, int tr, int l, int r, double val, ll val1)
{
push(v, tl, tr);
push(v + v, tl, tr);
push(v + v + 1, tl, tr);
if (t[v].sc < -1)
t[v].sc *= -1;
if (tl > r || l > tr)return;
if (l <= tl && tr <= r)
{
ad[v].fr += val;
if (ad[v].sc == -1)ad[v].sc = 1;
ad[v].sc = (val1 * 1LL * ad[v].sc) % MOD;
push(v, tl, tr);
push(v + v, tl, tr);
push(v + v + 1, tl, tr);
}
else
{
int mid = (tl + tr) >> 1;
updx(v + v, tl, mid, l, r, val, val1);
updx(v + v + 1, mid + 1, tr, l, r, val, val1);
push(v, tl, tr);
push(v + v, tl, tr);
push(v + v + 1, tl, tr);
t[v] = maxp(t[v + v], t[v + v + 1]);
}
}
int init(int N, int X[], int Y[]) {
double h = 0;
ll cur = 1;
double ans = 0;
ll ans1 = 1;
n = N;
for (int i = 0; i < sz * 2 - 1; i++)
{
ad[i].sc = -1;
}
for (int i = 0; i < N; i++)
{
x[i + 1] = X[i];
y[i + 1] = Y[i];
}
for (int i = 0; i < N; i++)
{
h += log10(X[i]);
cur = (cur * 1LL * X[i]) % MOD;
an[i + 1] = {h + log10(Y[i]), (cur * 1LL * Y[i]) % MOD};
if (ans * 1.0 < h + log10(Y[i]))
{
ans = log10(Y[i]) + h;
ans1 = (Y[i] * 1LL * cur) % MOD;
}
}
build(1, 1, n);
return (ans1 % MOD);
}
int updateX(int pos, int val) {
pos++;
double a = (log10(val) - log10(x[pos]));
ll b = (val * 1LL * bin_pow(x[pos], MOD - 2)) % MOD;
updx(1, 1, n, pos, n, a, b);
x[pos] = val;
return (t[1].sc % MOD);
}
int updateY(int pos, int val) {
pos++;
double a = (log10(val) - log10(y[pos]));
ll b = (val * 1LL * bin_pow(y[pos], MOD - 2)) % MOD;
updy(1, 1, n, pos, a, b);
y[pos] = val;
return (t[1].sc % MOD);
}
Compilation message
horses.cpp: In function 'void push(int, int, int)':
horses.cpp:58:22: warning: unused parameter 'tl' [-Wunused-parameter]
void push(int v, int tl, int tr)
^~
horses.cpp:58:30: warning: unused parameter 'tr' [-Wunused-parameter]
void push(int v, int tl, int tr)
^~
horses.cpp: In function 'int init(int, int*, int*)':
horses.cpp:178:18: warning: conversion to 'int' from 'long long int' may alter its value [-Wconversion]
build(1, 1, n);
^
horses.cpp:180:18: warning: conversion to 'int' from 'long long int' may alter its value [-Wconversion]
return (ans1 % MOD);
~~~~~~^~~~~~
horses.cpp: In function 'int updateX(int, int)':
horses.cpp:187:31: warning: conversion to 'int' from 'long long int' may alter its value [-Wconversion]
updx(1, 1, n, pos, n, a, b);
^
horses.cpp:187:31: warning: conversion to 'int' from 'long long int' may alter its value [-Wconversion]
horses.cpp:189:21: warning: conversion to 'int' from 'long long int' may alter its value [-Wconversion]
return (t[1].sc % MOD);
~~~~~~~~~^~~~~~
horses.cpp: In function 'int updateY(int, int)':
horses.cpp:198:28: warning: conversion to 'int' from 'long long int' may alter its value [-Wconversion]
updy(1, 1, n, pos, a, b);
^
horses.cpp:202:21: warning: conversion to 'int' from 'long long int' may alter its value [-Wconversion]
return (t[1].sc % MOD);
~~~~~~~~~^~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
105 ms |
156920 KB |
Output is correct |
2 |
Correct |
120 ms |
157028 KB |
Output is correct |
3 |
Correct |
118 ms |
157080 KB |
Output is correct |
4 |
Correct |
108 ms |
157080 KB |
Output is correct |
5 |
Correct |
128 ms |
157080 KB |
Output is correct |
6 |
Correct |
108 ms |
157228 KB |
Output is correct |
7 |
Correct |
122 ms |
157228 KB |
Output is correct |
8 |
Correct |
117 ms |
157256 KB |
Output is correct |
9 |
Correct |
107 ms |
157256 KB |
Output is correct |
10 |
Correct |
109 ms |
157256 KB |
Output is correct |
11 |
Correct |
120 ms |
157256 KB |
Output is correct |
12 |
Correct |
120 ms |
157256 KB |
Output is correct |
13 |
Correct |
118 ms |
157256 KB |
Output is correct |
14 |
Correct |
122 ms |
157256 KB |
Output is correct |
15 |
Correct |
126 ms |
157256 KB |
Output is correct |
16 |
Correct |
126 ms |
157256 KB |
Output is correct |
17 |
Correct |
126 ms |
157256 KB |
Output is correct |
18 |
Correct |
112 ms |
157260 KB |
Output is correct |
19 |
Correct |
110 ms |
157264 KB |
Output is correct |
20 |
Correct |
133 ms |
157264 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
126 ms |
157264 KB |
Output is correct |
2 |
Correct |
109 ms |
157264 KB |
Output is correct |
3 |
Correct |
108 ms |
157264 KB |
Output is correct |
4 |
Correct |
124 ms |
157264 KB |
Output is correct |
5 |
Correct |
118 ms |
157264 KB |
Output is correct |
6 |
Correct |
111 ms |
157264 KB |
Output is correct |
7 |
Correct |
115 ms |
157264 KB |
Output is correct |
8 |
Correct |
121 ms |
157264 KB |
Output is correct |
9 |
Correct |
116 ms |
157264 KB |
Output is correct |
10 |
Correct |
125 ms |
157264 KB |
Output is correct |
11 |
Correct |
112 ms |
157264 KB |
Output is correct |
12 |
Correct |
120 ms |
157264 KB |
Output is correct |
13 |
Correct |
121 ms |
157264 KB |
Output is correct |
14 |
Correct |
110 ms |
157264 KB |
Output is correct |
15 |
Correct |
122 ms |
157308 KB |
Output is correct |
16 |
Correct |
123 ms |
157308 KB |
Output is correct |
17 |
Correct |
115 ms |
157308 KB |
Output is correct |
18 |
Correct |
133 ms |
157308 KB |
Output is correct |
19 |
Correct |
124 ms |
157308 KB |
Output is correct |
20 |
Correct |
124 ms |
157308 KB |
Output is correct |
21 |
Correct |
108 ms |
157308 KB |
Output is correct |
22 |
Correct |
114 ms |
157308 KB |
Output is correct |
23 |
Correct |
115 ms |
157308 KB |
Output is correct |
24 |
Correct |
130 ms |
157308 KB |
Output is correct |
25 |
Correct |
110 ms |
157308 KB |
Output is correct |
26 |
Correct |
136 ms |
157308 KB |
Output is correct |
27 |
Correct |
125 ms |
157308 KB |
Output is correct |
28 |
Correct |
144 ms |
157308 KB |
Output is correct |
29 |
Correct |
120 ms |
157324 KB |
Output is correct |
30 |
Correct |
108 ms |
157356 KB |
Output is correct |
31 |
Correct |
145 ms |
157356 KB |
Output is correct |
32 |
Correct |
131 ms |
157356 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
290 ms |
194216 KB |
Output is correct |
2 |
Correct |
686 ms |
210748 KB |
Output is correct |
3 |
Correct |
594 ms |
210780 KB |
Output is correct |
4 |
Correct |
667 ms |
210780 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
133 ms |
210780 KB |
Output is correct |
2 |
Correct |
121 ms |
210780 KB |
Output is correct |
3 |
Correct |
126 ms |
210780 KB |
Output is correct |
4 |
Correct |
129 ms |
210780 KB |
Output is correct |
5 |
Correct |
114 ms |
210780 KB |
Output is correct |
6 |
Correct |
120 ms |
210780 KB |
Output is correct |
7 |
Correct |
120 ms |
210780 KB |
Output is correct |
8 |
Correct |
117 ms |
210780 KB |
Output is correct |
9 |
Correct |
125 ms |
210780 KB |
Output is correct |
10 |
Correct |
123 ms |
210780 KB |
Output is correct |
11 |
Correct |
112 ms |
210780 KB |
Output is correct |
12 |
Correct |
107 ms |
210780 KB |
Output is correct |
13 |
Correct |
122 ms |
210780 KB |
Output is correct |
14 |
Correct |
121 ms |
210780 KB |
Output is correct |
15 |
Correct |
109 ms |
210780 KB |
Output is correct |
16 |
Correct |
116 ms |
210780 KB |
Output is correct |
17 |
Correct |
115 ms |
210780 KB |
Output is correct |
18 |
Correct |
138 ms |
210780 KB |
Output is correct |
19 |
Correct |
107 ms |
210780 KB |
Output is correct |
20 |
Correct |
121 ms |
210780 KB |
Output is correct |
21 |
Correct |
121 ms |
210780 KB |
Output is correct |
22 |
Correct |
129 ms |
210780 KB |
Output is correct |
23 |
Correct |
129 ms |
210780 KB |
Output is correct |
24 |
Correct |
121 ms |
210780 KB |
Output is correct |
25 |
Correct |
119 ms |
210780 KB |
Output is correct |
26 |
Correct |
132 ms |
210780 KB |
Output is correct |
27 |
Correct |
120 ms |
210780 KB |
Output is correct |
28 |
Correct |
138 ms |
210780 KB |
Output is correct |
29 |
Correct |
127 ms |
210780 KB |
Output is correct |
30 |
Correct |
125 ms |
210780 KB |
Output is correct |
31 |
Correct |
112 ms |
210780 KB |
Output is correct |
32 |
Correct |
118 ms |
210780 KB |
Output is correct |
33 |
Correct |
259 ms |
210780 KB |
Output is correct |
34 |
Correct |
268 ms |
210780 KB |
Output is correct |
35 |
Correct |
286 ms |
210780 KB |
Output is correct |
36 |
Correct |
315 ms |
210780 KB |
Output is correct |
37 |
Correct |
242 ms |
210780 KB |
Output is correct |
38 |
Correct |
274 ms |
210780 KB |
Output is correct |
39 |
Correct |
185 ms |
210780 KB |
Output is correct |
40 |
Correct |
255 ms |
210780 KB |
Output is correct |
41 |
Correct |
182 ms |
210780 KB |
Output is correct |
42 |
Correct |
178 ms |
210780 KB |
Output is correct |
43 |
Incorrect |
213 ms |
210780 KB |
Output isn't correct |
44 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
112 ms |
210780 KB |
Output is correct |
2 |
Correct |
109 ms |
210780 KB |
Output is correct |
3 |
Correct |
108 ms |
210780 KB |
Output is correct |
4 |
Correct |
105 ms |
210780 KB |
Output is correct |
5 |
Correct |
107 ms |
210780 KB |
Output is correct |
6 |
Correct |
117 ms |
210780 KB |
Output is correct |
7 |
Correct |
107 ms |
210780 KB |
Output is correct |
8 |
Correct |
114 ms |
210780 KB |
Output is correct |
9 |
Correct |
116 ms |
210780 KB |
Output is correct |
10 |
Correct |
127 ms |
210780 KB |
Output is correct |
11 |
Correct |
112 ms |
210780 KB |
Output is correct |
12 |
Correct |
114 ms |
210780 KB |
Output is correct |
13 |
Correct |
122 ms |
210780 KB |
Output is correct |
14 |
Correct |
113 ms |
210780 KB |
Output is correct |
15 |
Correct |
125 ms |
210780 KB |
Output is correct |
16 |
Correct |
125 ms |
210780 KB |
Output is correct |
17 |
Correct |
112 ms |
210780 KB |
Output is correct |
18 |
Correct |
105 ms |
210780 KB |
Output is correct |
19 |
Correct |
109 ms |
210780 KB |
Output is correct |
20 |
Correct |
103 ms |
210780 KB |
Output is correct |
21 |
Correct |
122 ms |
210780 KB |
Output is correct |
22 |
Correct |
107 ms |
210780 KB |
Output is correct |
23 |
Correct |
107 ms |
210780 KB |
Output is correct |
24 |
Correct |
132 ms |
210780 KB |
Output is correct |
25 |
Correct |
108 ms |
210780 KB |
Output is correct |
26 |
Correct |
110 ms |
210780 KB |
Output is correct |
27 |
Correct |
124 ms |
210780 KB |
Output is correct |
28 |
Correct |
113 ms |
210780 KB |
Output is correct |
29 |
Correct |
107 ms |
210780 KB |
Output is correct |
30 |
Correct |
122 ms |
210780 KB |
Output is correct |
31 |
Correct |
124 ms |
210780 KB |
Output is correct |
32 |
Correct |
132 ms |
210780 KB |
Output is correct |
33 |
Correct |
266 ms |
210780 KB |
Output is correct |
34 |
Correct |
637 ms |
210780 KB |
Output is correct |
35 |
Correct |
552 ms |
210780 KB |
Output is correct |
36 |
Correct |
639 ms |
210796 KB |
Output is correct |
37 |
Correct |
249 ms |
210796 KB |
Output is correct |
38 |
Correct |
251 ms |
210796 KB |
Output is correct |
39 |
Correct |
273 ms |
210796 KB |
Output is correct |
40 |
Correct |
288 ms |
210796 KB |
Output is correct |
41 |
Correct |
211 ms |
210796 KB |
Output is correct |
42 |
Correct |
231 ms |
210796 KB |
Output is correct |
43 |
Correct |
202 ms |
210796 KB |
Output is correct |
44 |
Correct |
240 ms |
210796 KB |
Output is correct |
45 |
Correct |
178 ms |
210796 KB |
Output is correct |
46 |
Correct |
242 ms |
210796 KB |
Output is correct |
47 |
Incorrect |
197 ms |
210796 KB |
Output isn't correct |
48 |
Halted |
0 ms |
0 KB |
- |