# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
833901 |
2023-08-22T09:25:05 Z |
Victor |
Horses (IOI15_horses) |
C++17 |
|
451 ms |
182208 KB |
#include "horses.h"
#include <bits/stdc++.h>
using namespace std;
#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define per(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define trav(a, x) for (auto &a : x)
#define all(x) x.begin(), x.end()
#define sz(x) x.size()
#define pb push_back
typedef long long ll;
typedef vector<ll> vll;
typedef pair<ll, ll> pll;
typedef vector<pll> vpll;
const ll INF = 1'000'000'007;
struct Node {
ll lo,hi,id;
long double log_sum=0,val,madd=0;
Node *l,*r;
Node(const vll&x, const vll&y, long double add, ll L,ll R) : lo(L), hi(R) {
if(hi-lo==1) {
log_sum=logf64(x[lo])+add;
val=log_sum+logf64(y[lo]);
id=lo;
} else {
ll mid=(lo+hi)/2;
l=new Node(x,y,add,lo,mid);
r=new Node(x,y,l->log_sum,mid,hi);
log_sum=r->log_sum;
tie(val,id)=max(pair<long double,ll>(l->val,l->id),pair<long double,ll>(r->val,r->id));
}
//cout<<"lo = "<<lo<<" hi = "<<hi<<" log_sum = "<<log_sum<<" add = "<<add<<" val = "<<val<<endl;
}
void updateX(ll pos, long double v) { // v is new logx[pos] - prev logx[pos]
if(hi<=pos) return;
if(pos<=lo) {
madd+=v;
log_sum+=v;
val+=v;
return;
}
push();
l->updateX(pos,v);
r->updateX(pos,v);
tie(val,id)=max(pair<long double,ll>(l->val,l->id),pair<long double,ll>(r->val,r->id));
}
void updateY(ll pos, ll v) { // v is new y[pos]
if(pos<lo||hi<=pos) return;
if(hi-lo==1) {
val=log_sum+logf64(v);
return;
}
push();
l->updateY(pos,v);
r->updateY(pos,v);
tie(val,id)=max(pair<long double,ll>(l->val,l->id),pair<long double,ll>(r->val,r->id));
}
void push() {
if(madd!=0) {
l->updateX(0,madd);
r->updateX(0,madd);
madd=0;
}
}
};
struct Prod {
ll lo,hi,prod;
Prod *l,*r;
Prod(const vll&x,ll L,ll R) : lo(L), hi(R) {
if(hi-lo==1) {
prod=x[lo];
} else {
ll mid=(lo+hi)/2;
l=new Prod(x,lo,mid);
r=new Prod(x,mid,hi);
prod=l->prod*r->prod%INF;
}
}
ll query(ll R) {
if(R<=lo) return 1;
if(hi<=R) return prod;
return l->query(R)*r->query(R)%INF;
}
void updateX(ll pos,ll v) { // v is new x[pos]
if(pos<lo||hi<=pos) return;
if(hi-lo==1) {
prod=v;
return;
}
l->updateX(pos,v);
r->updateX(pos,v);
prod=l->prod*r->prod%INF;
}
};
vll x,y;
Node *segtree;
Prod *prodseg;
int init(int N, int X[], int Y[]) {
rep(i,0,N) {
assert(X[i]&&Y[i]);
x.pb(X[i]);
y.pb(Y[i]);
}
segtree=new Node(x,y,0,0,N);
prodseg=new Prod(x,0,N);
ll id=segtree->id;
return prodseg->query(id+1)*y[id]%INF;
}
int updateX(int pos, int val) {
assert(val);
double diff=logf64(val)-logf64(x[pos]);
x[pos]=val;
segtree->updateX(pos,diff);
prodseg->updateX(pos,val);
ll id=segtree->id;
return prodseg->query(id+1)*y[id]%INF;
}
int updateY(int pos, int val) {
assert(val);
y[pos]=val;
segtree->updateY(pos,val);
ll id=segtree->id;
return prodseg->query(id+1)*y[id]%INF;
}
Compilation message
horses.cpp: In constructor 'Node::Node(const vll&, const vll&, long double, ll, ll)':
horses.cpp:27:33: warning: conversion from '__gnu_cxx::__alloc_traits<std::allocator<long long int>, long long int>::value_type' {aka 'long long int'} to '_Float64' {aka 'double'} may change value [-Wconversion]
27 | log_sum=logf64(x[lo])+add;
| ^
horses.cpp:28:37: warning: conversion from '__gnu_cxx::__alloc_traits<std::allocator<long long int>, long long int>::value_type' {aka 'long long int'} to '_Float64' {aka 'double'} may change value [-Wconversion]
28 | val=log_sum+logf64(y[lo]);
| ^
horses.cpp: In member function 'void Node::updateY(ll, ll)':
horses.cpp:60:32: warning: conversion from 'll' {aka 'long long int'} to '_Float64' {aka 'double'} may change value [-Wconversion]
60 | val=log_sum+logf64(v);
| ^
horses.cpp: In function 'int init(int, int*, int*)':
horses.cpp:128:38: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
128 | return prodseg->query(id+1)*y[id]%INF;
| ~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~
horses.cpp: In function 'int updateX(int, int)':
horses.cpp:133:42: warning: conversion from '__gnu_cxx::__alloc_traits<std::allocator<long long int>, long long int>::value_type' {aka 'long long int'} to '_Float64' {aka 'double'} may change value [-Wconversion]
133 | double diff=logf64(val)-logf64(x[pos]);
| ^
horses.cpp:138:38: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
138 | return prodseg->query(id+1)*y[id]%INF;
| ~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~
horses.cpp: In function 'int updateY(int, int)':
horses.cpp:146:38: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
146 | return prodseg->query(id+1)*y[id]%INF;
| ~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
0 ms |
212 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
1 ms |
212 KB |
Output is correct |
17 |
Correct |
0 ms |
212 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
212 KB |
Output is correct |
20 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
0 ms |
212 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
0 ms |
212 KB |
Output is correct |
17 |
Correct |
0 ms |
212 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
212 KB |
Output is correct |
20 |
Correct |
0 ms |
212 KB |
Output is correct |
21 |
Correct |
0 ms |
212 KB |
Output is correct |
22 |
Correct |
1 ms |
296 KB |
Output is correct |
23 |
Correct |
1 ms |
596 KB |
Output is correct |
24 |
Correct |
1 ms |
596 KB |
Output is correct |
25 |
Correct |
1 ms |
596 KB |
Output is correct |
26 |
Correct |
1 ms |
596 KB |
Output is correct |
27 |
Correct |
1 ms |
596 KB |
Output is correct |
28 |
Correct |
1 ms |
596 KB |
Output is correct |
29 |
Correct |
1 ms |
596 KB |
Output is correct |
30 |
Correct |
1 ms |
596 KB |
Output is correct |
31 |
Correct |
1 ms |
596 KB |
Output is correct |
32 |
Correct |
1 ms |
596 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
175 ms |
173368 KB |
Output is correct |
2 |
Correct |
371 ms |
182068 KB |
Output is correct |
3 |
Correct |
347 ms |
173276 KB |
Output is correct |
4 |
Correct |
399 ms |
177136 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
0 ms |
212 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
1 ms |
212 KB |
Output is correct |
17 |
Correct |
0 ms |
212 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
212 KB |
Output is correct |
20 |
Correct |
0 ms |
212 KB |
Output is correct |
21 |
Correct |
0 ms |
212 KB |
Output is correct |
22 |
Correct |
0 ms |
212 KB |
Output is correct |
23 |
Correct |
2 ms |
564 KB |
Output is correct |
24 |
Correct |
1 ms |
596 KB |
Output is correct |
25 |
Correct |
1 ms |
596 KB |
Output is correct |
26 |
Correct |
1 ms |
596 KB |
Output is correct |
27 |
Correct |
1 ms |
596 KB |
Output is correct |
28 |
Correct |
1 ms |
596 KB |
Output is correct |
29 |
Correct |
1 ms |
596 KB |
Output is correct |
30 |
Correct |
1 ms |
596 KB |
Output is correct |
31 |
Correct |
1 ms |
596 KB |
Output is correct |
32 |
Correct |
1 ms |
596 KB |
Output is correct |
33 |
Correct |
155 ms |
171628 KB |
Output is correct |
34 |
Correct |
148 ms |
172512 KB |
Output is correct |
35 |
Correct |
167 ms |
179548 KB |
Output is correct |
36 |
Correct |
155 ms |
179484 KB |
Output is correct |
37 |
Correct |
129 ms |
170800 KB |
Output is correct |
38 |
Correct |
132 ms |
171680 KB |
Output is correct |
39 |
Correct |
120 ms |
170572 KB |
Output is correct |
40 |
Correct |
142 ms |
174488 KB |
Output is correct |
41 |
Correct |
119 ms |
170720 KB |
Output is correct |
42 |
Correct |
118 ms |
170668 KB |
Output is correct |
43 |
Correct |
131 ms |
174856 KB |
Output is correct |
44 |
Correct |
140 ms |
174872 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
256 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
0 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
0 ms |
212 KB |
Output is correct |
17 |
Correct |
0 ms |
212 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
212 KB |
Output is correct |
20 |
Correct |
0 ms |
212 KB |
Output is correct |
21 |
Correct |
0 ms |
212 KB |
Output is correct |
22 |
Correct |
0 ms |
300 KB |
Output is correct |
23 |
Correct |
1 ms |
596 KB |
Output is correct |
24 |
Correct |
1 ms |
580 KB |
Output is correct |
25 |
Correct |
1 ms |
596 KB |
Output is correct |
26 |
Correct |
1 ms |
568 KB |
Output is correct |
27 |
Correct |
1 ms |
596 KB |
Output is correct |
28 |
Correct |
1 ms |
568 KB |
Output is correct |
29 |
Correct |
1 ms |
648 KB |
Output is correct |
30 |
Correct |
1 ms |
596 KB |
Output is correct |
31 |
Correct |
1 ms |
572 KB |
Output is correct |
32 |
Correct |
1 ms |
596 KB |
Output is correct |
33 |
Correct |
162 ms |
173364 KB |
Output is correct |
34 |
Correct |
451 ms |
182208 KB |
Output is correct |
35 |
Correct |
345 ms |
173340 KB |
Output is correct |
36 |
Correct |
402 ms |
177128 KB |
Output is correct |
37 |
Correct |
155 ms |
172536 KB |
Output is correct |
38 |
Correct |
159 ms |
172644 KB |
Output is correct |
39 |
Correct |
154 ms |
179556 KB |
Output is correct |
40 |
Correct |
155 ms |
179412 KB |
Output is correct |
41 |
Correct |
132 ms |
170692 KB |
Output is correct |
42 |
Correct |
136 ms |
171660 KB |
Output is correct |
43 |
Correct |
125 ms |
170580 KB |
Output is correct |
44 |
Correct |
145 ms |
174508 KB |
Output is correct |
45 |
Correct |
117 ms |
170732 KB |
Output is correct |
46 |
Correct |
120 ms |
170744 KB |
Output is correct |
47 |
Correct |
140 ms |
174892 KB |
Output is correct |
48 |
Correct |
134 ms |
174924 KB |
Output is correct |
49 |
Correct |
363 ms |
174684 KB |
Output is correct |
50 |
Correct |
373 ms |
174588 KB |
Output is correct |
51 |
Correct |
200 ms |
181420 KB |
Output is correct |
52 |
Correct |
196 ms |
180928 KB |
Output is correct |
53 |
Correct |
293 ms |
172872 KB |
Output is correct |
54 |
Correct |
224 ms |
173452 KB |
Output is correct |
55 |
Correct |
192 ms |
171644 KB |
Output is correct |
56 |
Correct |
227 ms |
176400 KB |
Output is correct |
57 |
Correct |
164 ms |
172300 KB |
Output is correct |
58 |
Correct |
158 ms |
172788 KB |
Output is correct |
59 |
Correct |
132 ms |
174932 KB |
Output is correct |