# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
87755 |
2018-12-02T10:08:46 Z |
JustasZ |
Horses (IOI15_horses) |
C++14 |
|
551 ms |
121884 KB |
#include "horses.h"
#include <bits/stdc++.h>
#define pb push_back
#define all(a) a.begin(), a.end()
#define sz(a) (int)a.size()
#define x first
#define y second
#define debug(...) "["<<#__VA_ARGS__<<": "<<__VA_ARGS__<<"]"
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int>pii;
const int maxn=5e5+100;
const int mod=1e9+7;
const ld eps=1e-5;
mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
ll pwr(ll a, ll pw)
{
ll ret=1;
while(pw>0)
{
if(pw&1)ret=ret*a%mod;
a=a*a%mod;
pw>>=1;
}
return ret;
}
ll modinv(ll a)
{
return pwr(a, mod-2);
}
int N;
ll X[maxn], Y[maxn], prod[maxn];
ld Xpref[maxn];
pair<ld, ll> seg[maxn*4], lazy[maxn*4];
bool need[maxn*4];
void build(int id=1, int l=0, int r=N-1)
{
if(l == r)
{
seg[id].x=Xpref[l]+log((ld)Y[l]);
seg[id].y=prod[l]*Y[l]%mod;
return;
}
int mid=(l+r)/2;
build(id*2, l, mid);
build(id*2+1, mid+1, r);
seg[id]=max(seg[id*2], seg[id*2+1]);
}
void laz(int id, ld d, ll mul)
{
seg[id].x+=d;
lazy[id].x+=d;
seg[id].y=seg[id].y*mul%mod;
lazy[id].y=lazy[id].y*mul%mod;
need[id]=true;
}
void shift(int id)
{
if(need[id])
{
laz(id*2, lazy[id].x, lazy[id].y);
laz(id*2+1, lazy[id].x, lazy[id].y);
need[id]=false;
lazy[id]={0, 1};
}
}
void modify(int x, int y, ld d, ll mul, int id=1, int l=0, int r=N-1)
{
if(l > y || r < x)return;
if(l >= x && r <= y)
{
laz(id, d, mul);
return;
}
shift(id);
int mid=(l+r)/2;
modify(x, y, d, mul, id*2, l, mid);
modify(x, y, d, mul, id*2+1, mid+1, r);
seg[id]=max(seg[id*2], seg[id*2+1]);
}
pair<ld, ll> query(int x, int y, int id=1, int l=0, int r=N-1)
{
if(l > y || r < x)return {0, 0};
if(l >= x && r <= y)return seg[id];
shift(id);
int mid=(l+r)/2;
return max(query(x, y, id*2, l, mid), query(x, y, id*2+1, mid+1, r));
}
int getans()
{
return (int)(query(0, N-1).y);
}
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];
for(int i=0; i<N; i++)
{
Xpref[i]=log((ld)X[i]);
prod[i]=X[i];
if(i > 0)Xpref[i]+=Xpref[i-1];
if(i > 0)prod[i]=prod[i]*prod[i-1]%mod;
}
for(int i=0; i<maxn*4; i++)lazy[i].y=1;
build();
return getans();
}
int updateX(int p, int val)
{
ld d=log((ld)val)-log((ld)X[p]);
ll mul=modinv(X[p])*(ll)val%mod;
X[p]=val;
modify(p, N-1, d, mul);
return getans();
}
int updateY(int p, int val)
{
ld d=log((ld)val)-log((ld)Y[p]);
ll mul=modinv(Y[p])*(ll)val%mod;
Y[p]=val;
modify(p, p, d, mul);
return getans();
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
58 ms |
62968 KB |
Output is correct |
2 |
Correct |
56 ms |
63220 KB |
Output is correct |
3 |
Correct |
56 ms |
63220 KB |
Output is correct |
4 |
Correct |
49 ms |
63268 KB |
Output is correct |
5 |
Correct |
49 ms |
63268 KB |
Output is correct |
6 |
Correct |
48 ms |
63268 KB |
Output is correct |
7 |
Correct |
50 ms |
63284 KB |
Output is correct |
8 |
Correct |
49 ms |
63292 KB |
Output is correct |
9 |
Correct |
52 ms |
63292 KB |
Output is correct |
10 |
Correct |
49 ms |
63292 KB |
Output is correct |
11 |
Correct |
49 ms |
63292 KB |
Output is correct |
12 |
Correct |
54 ms |
63312 KB |
Output is correct |
13 |
Correct |
55 ms |
63312 KB |
Output is correct |
14 |
Correct |
57 ms |
63312 KB |
Output is correct |
15 |
Correct |
51 ms |
63360 KB |
Output is correct |
16 |
Correct |
53 ms |
63360 KB |
Output is correct |
17 |
Correct |
58 ms |
63360 KB |
Output is correct |
18 |
Correct |
58 ms |
63360 KB |
Output is correct |
19 |
Correct |
52 ms |
63360 KB |
Output is correct |
20 |
Correct |
49 ms |
63360 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
56 ms |
63360 KB |
Output is correct |
2 |
Correct |
57 ms |
63360 KB |
Output is correct |
3 |
Correct |
58 ms |
63360 KB |
Output is correct |
4 |
Correct |
58 ms |
63360 KB |
Output is correct |
5 |
Correct |
56 ms |
63360 KB |
Output is correct |
6 |
Correct |
57 ms |
63360 KB |
Output is correct |
7 |
Correct |
57 ms |
63360 KB |
Output is correct |
8 |
Correct |
57 ms |
63360 KB |
Output is correct |
9 |
Correct |
57 ms |
63360 KB |
Output is correct |
10 |
Correct |
59 ms |
63360 KB |
Output is correct |
11 |
Correct |
59 ms |
63360 KB |
Output is correct |
12 |
Correct |
58 ms |
63360 KB |
Output is correct |
13 |
Correct |
59 ms |
63360 KB |
Output is correct |
14 |
Correct |
58 ms |
63360 KB |
Output is correct |
15 |
Correct |
57 ms |
63360 KB |
Output is correct |
16 |
Correct |
57 ms |
63360 KB |
Output is correct |
17 |
Correct |
48 ms |
63360 KB |
Output is correct |
18 |
Correct |
49 ms |
63360 KB |
Output is correct |
19 |
Correct |
55 ms |
63360 KB |
Output is correct |
20 |
Correct |
49 ms |
63360 KB |
Output is correct |
21 |
Correct |
49 ms |
63360 KB |
Output is correct |
22 |
Correct |
48 ms |
63360 KB |
Output is correct |
23 |
Correct |
50 ms |
63360 KB |
Output is correct |
24 |
Correct |
49 ms |
63360 KB |
Output is correct |
25 |
Correct |
57 ms |
63372 KB |
Output is correct |
26 |
Correct |
60 ms |
63516 KB |
Output is correct |
27 |
Correct |
57 ms |
63532 KB |
Output is correct |
28 |
Correct |
59 ms |
63532 KB |
Output is correct |
29 |
Correct |
58 ms |
63532 KB |
Output is correct |
30 |
Correct |
58 ms |
63532 KB |
Output is correct |
31 |
Correct |
61 ms |
63532 KB |
Output is correct |
32 |
Correct |
57 ms |
63532 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
275 ms |
120764 KB |
Output is correct |
2 |
Correct |
549 ms |
121884 KB |
Output is correct |
3 |
Correct |
532 ms |
121884 KB |
Output is correct |
4 |
Correct |
540 ms |
121884 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
50 ms |
121884 KB |
Output is correct |
2 |
Correct |
57 ms |
121884 KB |
Output is correct |
3 |
Correct |
56 ms |
121884 KB |
Output is correct |
4 |
Correct |
57 ms |
121884 KB |
Output is correct |
5 |
Correct |
58 ms |
121884 KB |
Output is correct |
6 |
Correct |
59 ms |
121884 KB |
Output is correct |
7 |
Correct |
57 ms |
121884 KB |
Output is correct |
8 |
Correct |
58 ms |
121884 KB |
Output is correct |
9 |
Correct |
57 ms |
121884 KB |
Output is correct |
10 |
Correct |
56 ms |
121884 KB |
Output is correct |
11 |
Correct |
56 ms |
121884 KB |
Output is correct |
12 |
Correct |
59 ms |
121884 KB |
Output is correct |
13 |
Correct |
59 ms |
121884 KB |
Output is correct |
14 |
Correct |
53 ms |
121884 KB |
Output is correct |
15 |
Correct |
50 ms |
121884 KB |
Output is correct |
16 |
Correct |
50 ms |
121884 KB |
Output is correct |
17 |
Correct |
61 ms |
121884 KB |
Output is correct |
18 |
Correct |
53 ms |
121884 KB |
Output is correct |
19 |
Correct |
56 ms |
121884 KB |
Output is correct |
20 |
Correct |
59 ms |
121884 KB |
Output is correct |
21 |
Correct |
49 ms |
121884 KB |
Output is correct |
22 |
Correct |
49 ms |
121884 KB |
Output is correct |
23 |
Correct |
51 ms |
121884 KB |
Output is correct |
24 |
Correct |
52 ms |
121884 KB |
Output is correct |
25 |
Correct |
59 ms |
121884 KB |
Output is correct |
26 |
Correct |
59 ms |
121884 KB |
Output is correct |
27 |
Correct |
58 ms |
121884 KB |
Output is correct |
28 |
Correct |
59 ms |
121884 KB |
Output is correct |
29 |
Correct |
57 ms |
121884 KB |
Output is correct |
30 |
Correct |
60 ms |
121884 KB |
Output is correct |
31 |
Correct |
57 ms |
121884 KB |
Output is correct |
32 |
Correct |
58 ms |
121884 KB |
Output is correct |
33 |
Correct |
228 ms |
121884 KB |
Output is correct |
34 |
Correct |
212 ms |
121884 KB |
Output is correct |
35 |
Correct |
188 ms |
121884 KB |
Output is correct |
36 |
Correct |
203 ms |
121884 KB |
Output is correct |
37 |
Correct |
194 ms |
121884 KB |
Output is correct |
38 |
Correct |
182 ms |
121884 KB |
Output is correct |
39 |
Correct |
193 ms |
121884 KB |
Output is correct |
40 |
Correct |
190 ms |
121884 KB |
Output is correct |
41 |
Correct |
212 ms |
121884 KB |
Output is correct |
42 |
Correct |
197 ms |
121884 KB |
Output is correct |
43 |
Correct |
193 ms |
121884 KB |
Output is correct |
44 |
Correct |
210 ms |
121884 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
58 ms |
121884 KB |
Output is correct |
2 |
Correct |
56 ms |
121884 KB |
Output is correct |
3 |
Correct |
58 ms |
121884 KB |
Output is correct |
4 |
Correct |
61 ms |
121884 KB |
Output is correct |
5 |
Correct |
57 ms |
121884 KB |
Output is correct |
6 |
Correct |
57 ms |
121884 KB |
Output is correct |
7 |
Correct |
58 ms |
121884 KB |
Output is correct |
8 |
Correct |
55 ms |
121884 KB |
Output is correct |
9 |
Correct |
51 ms |
121884 KB |
Output is correct |
10 |
Correct |
58 ms |
121884 KB |
Output is correct |
11 |
Correct |
58 ms |
121884 KB |
Output is correct |
12 |
Correct |
50 ms |
121884 KB |
Output is correct |
13 |
Correct |
49 ms |
121884 KB |
Output is correct |
14 |
Correct |
48 ms |
121884 KB |
Output is correct |
15 |
Correct |
49 ms |
121884 KB |
Output is correct |
16 |
Correct |
48 ms |
121884 KB |
Output is correct |
17 |
Correct |
48 ms |
121884 KB |
Output is correct |
18 |
Correct |
49 ms |
121884 KB |
Output is correct |
19 |
Correct |
49 ms |
121884 KB |
Output is correct |
20 |
Correct |
49 ms |
121884 KB |
Output is correct |
21 |
Correct |
50 ms |
121884 KB |
Output is correct |
22 |
Correct |
48 ms |
121884 KB |
Output is correct |
23 |
Correct |
50 ms |
121884 KB |
Output is correct |
24 |
Correct |
51 ms |
121884 KB |
Output is correct |
25 |
Correct |
49 ms |
121884 KB |
Output is correct |
26 |
Correct |
47 ms |
121884 KB |
Output is correct |
27 |
Correct |
50 ms |
121884 KB |
Output is correct |
28 |
Correct |
53 ms |
121884 KB |
Output is correct |
29 |
Correct |
50 ms |
121884 KB |
Output is correct |
30 |
Correct |
58 ms |
121884 KB |
Output is correct |
31 |
Correct |
50 ms |
121884 KB |
Output is correct |
32 |
Correct |
48 ms |
121884 KB |
Output is correct |
33 |
Correct |
252 ms |
121884 KB |
Output is correct |
34 |
Correct |
493 ms |
121884 KB |
Output is correct |
35 |
Correct |
465 ms |
121884 KB |
Output is correct |
36 |
Correct |
429 ms |
121884 KB |
Output is correct |
37 |
Correct |
216 ms |
121884 KB |
Output is correct |
38 |
Correct |
202 ms |
121884 KB |
Output is correct |
39 |
Correct |
196 ms |
121884 KB |
Output is correct |
40 |
Correct |
190 ms |
121884 KB |
Output is correct |
41 |
Correct |
209 ms |
121884 KB |
Output is correct |
42 |
Correct |
177 ms |
121884 KB |
Output is correct |
43 |
Correct |
191 ms |
121884 KB |
Output is correct |
44 |
Correct |
209 ms |
121884 KB |
Output is correct |
45 |
Correct |
206 ms |
121884 KB |
Output is correct |
46 |
Correct |
200 ms |
121884 KB |
Output is correct |
47 |
Correct |
194 ms |
121884 KB |
Output is correct |
48 |
Correct |
198 ms |
121884 KB |
Output is correct |
49 |
Correct |
551 ms |
121884 KB |
Output is correct |
50 |
Correct |
537 ms |
121884 KB |
Output is correct |
51 |
Correct |
306 ms |
121884 KB |
Output is correct |
52 |
Correct |
310 ms |
121884 KB |
Output is correct |
53 |
Correct |
454 ms |
121884 KB |
Output is correct |
54 |
Correct |
302 ms |
121884 KB |
Output is correct |
55 |
Correct |
311 ms |
121884 KB |
Output is correct |
56 |
Correct |
315 ms |
121884 KB |
Output is correct |
57 |
Correct |
279 ms |
121884 KB |
Output is correct |
58 |
Correct |
271 ms |
121884 KB |
Output is correct |
59 |
Correct |
209 ms |
121884 KB |
Output is correct |