# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
302338 |
2020-09-18T15:49:23 Z |
bensonlzl |
Horses (IOI15_horses) |
C++14 |
|
949 ms |
95516 KB |
#include "horses.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
const ll mod = 1000000007ll;
const ld eps = 1e-9;
ll modinv(ll x){
ll ans = 1, base = x, exp = mod-2;
while (exp){
if (exp & 1) ans *= base;
base *= base;
base %= mod;
ans %= mod;
exp >>= 1;
}
return ans;
}
ll Xval[500005], Yval[500005];
ll Xprod[500005];
ld logX[500005];
int n;
struct node{
node *left = nullptr, *right = nullptr;
int s, e;
ll maxi = 0;
node(int _s, int _e){
s = _s;
e = _e;
if (s == e){
maxi = Yval[s];
return;
}
left = new node(s,(s+e)/2);
right = new node((s+e)/2+1,e);
maxi = max(left->maxi,right->maxi);
}
void update(int x){
if (s == e){
maxi = Yval[s];
return;
}
if (x <= (s+e)/2) left->update(x);
else right->update(x);
maxi = max(left->maxi,right->maxi);
}
ll query(int l, int r){
if (r < l) return 1;
if (l > e || r < s) return 1;
else if (l <= s && e <= r) return maxi;
return max(left->query(l,r),right->query(l,r));
}
} *Yroot = nullptr;
set<int> non1X;
ld querylogX(int x){
ld sum = 0;
for (; x; x -= (x & -x)) sum += logX[x];
return sum;
}
ll queryX(int x){
ll prod = 1;
for (; x; x -= (x & -x)){
prod *= Xprod[x];
prod %= mod;
}
return prod;
}
ll solve(){
//cerr << "SOLVING\n";
if (non1X.empty()) return Yroot->query(1,n);
ll lastpos = n;
ld bestLog = logl(Yroot->query(1,*(non1X.begin())-1));
ll bestval = Yroot->query(1,*(non1X.begin())-1);
auto it = (--non1X.end());
//for (auto it2 : non1X) cerr << it2 << ' ';
//cerr << '\n';
for (int i = 0; i < 30; ++i){
//cerr << bestLog << ' ' << bestval << '\n';
int pos = *it;
ld curLog = querylogX(pos) + logl(Yroot->query(pos,lastpos));
if (curLog > bestLog + eps){
bestLog = curLog;
bestval = (queryX(pos) * Yroot->query(pos,lastpos)) % mod;
}
lastpos = pos-1;
if (it == non1X.begin()) break;
else it--;
}
//cerr << bestval << '\n';
//cerr << "END SOLVING\n";
return bestval;
}
int init(int N, int X[], int Y[]) {
n = N;
for (int i = 1; i <= n; ++i){
Xprod[i] = Xval[i] = X[i-1];
Yval[i] = Y[i-1];
logX[i] = logl(X[i-1]);
if (Xval[i] != 1) non1X.insert(i);
}
for (int i = 1; i < 20; ++i){
for (int j = (1 << i); j <= n; j += (1 << i)){
Xprod[j] *= Xprod[j - (1 << (i-1))];
Xprod[j] %= mod;
logX[j] += logX[j - (1 << (i-1))];
}
}
Yroot = new node(1,N);
non1X.insert(1);
return solve();
}
int updateX(int pos, int val) {
pos++;
ll valc = (modinv(Xval[pos]) * (ll)val)%mod;
ld lg1 = logl(Xval[pos]), lg2 = logl(val);
int x = pos;
for (; x <= n; x += (x & -x)){
Xprod[x] *= valc;
Xprod[x] %= mod;
logX[x] += lg2 - lg1;
}
if (Xval[pos] == 1 && val != 1) non1X.insert(pos);
else if (Xval[pos] != 1 && val == 1) non1X.erase(pos);
non1X.insert(1);
Xval[pos] = val;
return solve();
}
int updateY(int pos, int val) {
pos++;
Yval[pos] = val;
Yroot->update(pos);
return solve();
}
Compilation message
horses.cpp: In function 'll solve()':
horses.cpp:91:54: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
91 | ld curLog = querylogX(pos) + logl(Yroot->query(pos,lastpos));
| ^~~~~~~
horses.cpp:94:46: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
94 | bestval = (queryX(pos) * Yroot->query(pos,lastpos)) % mod;
| ^~~~~~~
horses.cpp: In function 'int init(int, int*, int*)':
horses.cpp:122:14: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
122 | return solve();
| ~~~~~^~
horses.cpp: In function 'int updateX(int, int)':
horses.cpp:139:14: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
139 | return solve();
| ~~~~~^~
horses.cpp: In function 'int updateY(int, int)':
horses.cpp:146:14: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
146 | return solve();
| ~~~~~^~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
512 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
0 ms |
384 KB |
Output is correct |
5 |
Correct |
1 ms |
384 KB |
Output is correct |
6 |
Correct |
1 ms |
384 KB |
Output is correct |
7 |
Correct |
1 ms |
384 KB |
Output is correct |
8 |
Correct |
1 ms |
384 KB |
Output is correct |
9 |
Correct |
0 ms |
384 KB |
Output is correct |
10 |
Correct |
1 ms |
384 KB |
Output is correct |
11 |
Correct |
1 ms |
384 KB |
Output is correct |
12 |
Correct |
1 ms |
384 KB |
Output is correct |
13 |
Correct |
1 ms |
384 KB |
Output is correct |
14 |
Correct |
1 ms |
384 KB |
Output is correct |
15 |
Correct |
1 ms |
384 KB |
Output is correct |
16 |
Correct |
1 ms |
384 KB |
Output is correct |
17 |
Correct |
1 ms |
384 KB |
Output is correct |
18 |
Correct |
1 ms |
384 KB |
Output is correct |
19 |
Correct |
1 ms |
384 KB |
Output is correct |
20 |
Correct |
1 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
1 ms |
384 KB |
Output is correct |
5 |
Correct |
1 ms |
384 KB |
Output is correct |
6 |
Correct |
1 ms |
384 KB |
Output is correct |
7 |
Correct |
1 ms |
384 KB |
Output is correct |
8 |
Correct |
1 ms |
384 KB |
Output is correct |
9 |
Correct |
1 ms |
512 KB |
Output is correct |
10 |
Correct |
1 ms |
384 KB |
Output is correct |
11 |
Correct |
1 ms |
384 KB |
Output is correct |
12 |
Correct |
1 ms |
384 KB |
Output is correct |
13 |
Correct |
0 ms |
384 KB |
Output is correct |
14 |
Correct |
1 ms |
384 KB |
Output is correct |
15 |
Correct |
1 ms |
512 KB |
Output is correct |
16 |
Correct |
1 ms |
384 KB |
Output is correct |
17 |
Correct |
1 ms |
384 KB |
Output is correct |
18 |
Correct |
1 ms |
384 KB |
Output is correct |
19 |
Correct |
1 ms |
384 KB |
Output is correct |
20 |
Correct |
1 ms |
384 KB |
Output is correct |
21 |
Correct |
1 ms |
384 KB |
Output is correct |
22 |
Correct |
1 ms |
512 KB |
Output is correct |
23 |
Correct |
6 ms |
512 KB |
Output is correct |
24 |
Correct |
5 ms |
512 KB |
Output is correct |
25 |
Correct |
5 ms |
512 KB |
Output is correct |
26 |
Correct |
5 ms |
512 KB |
Output is correct |
27 |
Correct |
5 ms |
512 KB |
Output is correct |
28 |
Correct |
5 ms |
512 KB |
Output is correct |
29 |
Correct |
2 ms |
512 KB |
Output is correct |
30 |
Correct |
6 ms |
512 KB |
Output is correct |
31 |
Correct |
4 ms |
512 KB |
Output is correct |
32 |
Correct |
5 ms |
512 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
866 ms |
95448 KB |
Output is correct |
2 |
Correct |
937 ms |
95352 KB |
Output is correct |
3 |
Correct |
949 ms |
95480 KB |
Output is correct |
4 |
Correct |
912 ms |
95320 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
1 ms |
384 KB |
Output is correct |
5 |
Correct |
1 ms |
512 KB |
Output is correct |
6 |
Correct |
1 ms |
384 KB |
Output is correct |
7 |
Correct |
1 ms |
384 KB |
Output is correct |
8 |
Correct |
1 ms |
384 KB |
Output is correct |
9 |
Correct |
1 ms |
384 KB |
Output is correct |
10 |
Correct |
1 ms |
384 KB |
Output is correct |
11 |
Correct |
1 ms |
384 KB |
Output is correct |
12 |
Correct |
1 ms |
384 KB |
Output is correct |
13 |
Correct |
1 ms |
384 KB |
Output is correct |
14 |
Correct |
1 ms |
384 KB |
Output is correct |
15 |
Correct |
1 ms |
384 KB |
Output is correct |
16 |
Correct |
1 ms |
384 KB |
Output is correct |
17 |
Correct |
1 ms |
384 KB |
Output is correct |
18 |
Correct |
1 ms |
384 KB |
Output is correct |
19 |
Correct |
1 ms |
384 KB |
Output is correct |
20 |
Correct |
1 ms |
384 KB |
Output is correct |
21 |
Correct |
1 ms |
384 KB |
Output is correct |
22 |
Correct |
1 ms |
384 KB |
Output is correct |
23 |
Correct |
5 ms |
640 KB |
Output is correct |
24 |
Correct |
5 ms |
512 KB |
Output is correct |
25 |
Correct |
5 ms |
512 KB |
Output is correct |
26 |
Correct |
5 ms |
512 KB |
Output is correct |
27 |
Correct |
7 ms |
512 KB |
Output is correct |
28 |
Correct |
5 ms |
512 KB |
Output is correct |
29 |
Correct |
2 ms |
512 KB |
Output is correct |
30 |
Correct |
6 ms |
512 KB |
Output is correct |
31 |
Correct |
4 ms |
512 KB |
Output is correct |
32 |
Correct |
5 ms |
512 KB |
Output is correct |
33 |
Correct |
208 ms |
71032 KB |
Output is correct |
34 |
Correct |
185 ms |
71032 KB |
Output is correct |
35 |
Correct |
312 ms |
94328 KB |
Output is correct |
36 |
Correct |
311 ms |
94328 KB |
Output is correct |
37 |
Correct |
199 ms |
71032 KB |
Output is correct |
38 |
Correct |
238 ms |
83068 KB |
Output is correct |
39 |
Correct |
122 ms |
70776 KB |
Output is correct |
40 |
Correct |
304 ms |
94332 KB |
Output is correct |
41 |
Correct |
153 ms |
71032 KB |
Output is correct |
42 |
Correct |
179 ms |
70904 KB |
Output is correct |
43 |
Correct |
244 ms |
94328 KB |
Output is correct |
44 |
Correct |
243 ms |
94328 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
1 ms |
384 KB |
Output is correct |
5 |
Correct |
1 ms |
384 KB |
Output is correct |
6 |
Correct |
1 ms |
384 KB |
Output is correct |
7 |
Correct |
1 ms |
384 KB |
Output is correct |
8 |
Correct |
1 ms |
384 KB |
Output is correct |
9 |
Correct |
1 ms |
384 KB |
Output is correct |
10 |
Correct |
1 ms |
384 KB |
Output is correct |
11 |
Correct |
1 ms |
384 KB |
Output is correct |
12 |
Correct |
0 ms |
384 KB |
Output is correct |
13 |
Correct |
1 ms |
384 KB |
Output is correct |
14 |
Correct |
1 ms |
384 KB |
Output is correct |
15 |
Correct |
1 ms |
384 KB |
Output is correct |
16 |
Correct |
1 ms |
384 KB |
Output is correct |
17 |
Correct |
1 ms |
384 KB |
Output is correct |
18 |
Correct |
1 ms |
384 KB |
Output is correct |
19 |
Correct |
1 ms |
384 KB |
Output is correct |
20 |
Correct |
1 ms |
384 KB |
Output is correct |
21 |
Correct |
1 ms |
384 KB |
Output is correct |
22 |
Correct |
1 ms |
384 KB |
Output is correct |
23 |
Correct |
5 ms |
512 KB |
Output is correct |
24 |
Correct |
5 ms |
512 KB |
Output is correct |
25 |
Correct |
5 ms |
640 KB |
Output is correct |
26 |
Correct |
5 ms |
512 KB |
Output is correct |
27 |
Correct |
5 ms |
512 KB |
Output is correct |
28 |
Correct |
6 ms |
512 KB |
Output is correct |
29 |
Correct |
2 ms |
512 KB |
Output is correct |
30 |
Correct |
6 ms |
512 KB |
Output is correct |
31 |
Correct |
4 ms |
512 KB |
Output is correct |
32 |
Correct |
5 ms |
512 KB |
Output is correct |
33 |
Correct |
866 ms |
95484 KB |
Output is correct |
34 |
Correct |
920 ms |
95352 KB |
Output is correct |
35 |
Correct |
940 ms |
95352 KB |
Output is correct |
36 |
Correct |
901 ms |
95480 KB |
Output is correct |
37 |
Correct |
206 ms |
71032 KB |
Output is correct |
38 |
Correct |
186 ms |
71032 KB |
Output is correct |
39 |
Correct |
315 ms |
94456 KB |
Output is correct |
40 |
Correct |
312 ms |
94456 KB |
Output is correct |
41 |
Correct |
195 ms |
71032 KB |
Output is correct |
42 |
Correct |
234 ms |
82784 KB |
Output is correct |
43 |
Correct |
121 ms |
70860 KB |
Output is correct |
44 |
Correct |
303 ms |
94328 KB |
Output is correct |
45 |
Correct |
155 ms |
70908 KB |
Output is correct |
46 |
Correct |
180 ms |
70904 KB |
Output is correct |
47 |
Correct |
240 ms |
94328 KB |
Output is correct |
48 |
Correct |
241 ms |
94328 KB |
Output is correct |
49 |
Correct |
922 ms |
73080 KB |
Output is correct |
50 |
Correct |
803 ms |
72952 KB |
Output is correct |
51 |
Correct |
873 ms |
95224 KB |
Output is correct |
52 |
Correct |
871 ms |
95516 KB |
Output is correct |
53 |
Correct |
926 ms |
72952 KB |
Output is correct |
54 |
Correct |
860 ms |
85872 KB |
Output is correct |
55 |
Correct |
256 ms |
71132 KB |
Output is correct |
56 |
Correct |
925 ms |
95224 KB |
Output is correct |
57 |
Correct |
562 ms |
71928 KB |
Output is correct |
58 |
Correct |
815 ms |
72156 KB |
Output is correct |
59 |
Correct |
238 ms |
94328 KB |
Output is correct |