# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
343360 |
2021-01-03T18:41:14 Z |
bigDuck |
Horses (IOI15_horses) |
C++14 |
|
742 ms |
41196 KB |
#include "horses.h"
#include<bits/stdc++.h>
using namespace std;
#define INIT ios_base :: sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define mp make_pair
#define pb push_back
#define ft first
#define sc second
#define ll long long
#define pii pair<int, int>
#define count_bits __builtin_popcount
ll mod=((ll)1e9)+7;
int N;
ll exp(ll x, ll e){
if(e==1){
return x%mod;
}
if(e==0){
return 1;
}
return (exp(x, e%2)*exp( (x*x)%mod, e/2))%mod;
}
ll inv(ll x){
return exp(x, mod-2);
}
ll prod=1ll;
multiset<pii> suf;
int x[500010], y[500010];
int seg[2000010];
void build_seg(int v, int tl, int tr){
if(tl==tr){
seg[v]=y[tl];
return;
}
int mid=(tl+tr)>>1ll;
build_seg(2*v, tl, mid); build_seg(2*v+1, mid+1, tr);
seg[v]=max(seg[2*v], seg[2*v+1]);
return;
}
void update_seg(int v, int tl, int tr, int pos, int x){
if(tl==tr){
seg[v]=x;
y[tl]=x;
return;
}
int mid=(tl+tr)>>1ll;
if(pos<=mid){
update_seg(2*v, tl, mid, pos, x);
}
else{
update_seg(2*v+1, mid+1, tr, pos, x);
}
seg[v]=max(seg[2*v], seg[2*v+1]);
return;
}
int query(int v, int tl, int tr, int l, int r){
if(l>r){
return 0;
}
if( (tl==l) && (tr==r) ){
return seg[v];
}
int mid=(tl+tr)>>1ll;
int q1=query(2*v, tl, mid, l, min(r, mid)), q2=query(2*v+1, mid+1, tr, max(l, mid+1), r);
return max(q1, q2);
}
int get_resp(int N){
ll prod2=1ll;
ll prod3=1ll;
ll prod1=1ll;
ll res=y[N];
auto it=suf.end();
ll lt=N;
if(it==suf.begin()){
res=query(1, 1, N, 1, lt);
return (res*prod)%mod;
}
it--;
int cnt=0;
for(;;it--){
ll pos=it->ft, X=it->sc;
ll Y=query(1, 1, N, pos, lt);
if( ( ( ( (res*prod3)%mod )*((prod1) ) ) )<Y ){
//cout<<res<<" "<<((res*prod2)%mod)<<" "<<Y<<" "<<prod<<"\n";
res=(Y*inv(prod2))%mod;
prod3=prod2;
prod1=1ll;
cnt++;
}
lt=pos-1;
prod2*=X;
prod1*=X;
if(prod2>=((ll)1e9)){
break;
}
if(it==suf.begin()){
break;
}
}
if( (prod2<((ll)1e9)) && (lt>0) ){
ll Y=query(1, 1, N, 1, lt);
if( ( ( ( (res*prod3)%mod )*(prod1 ) ) )<Y ){
//cout<<res<<" "<<((res*prod2)%mod)<<" "<<Y<<" "<<prod<<"\n";
res=(Y*inv(prod2))%mod;
prod3=prod2;
prod1=1;
cnt++;
}
}
res=(res*prod)%mod;
return res;
}
int init(int n, int X[], int Y[]) {
//cout<<inv(1000000000ll)<<" "<<((1000000000ll*inv(1000000000ll))%mod )<<"\n";
N=n;
for(int i=1; i<=N; i++){
x[i]=X[i-1];
y[i]=Y[i-1];
}
build_seg(1, 1, N);
for(int i=1; i<=N; i++){
prod=(prod*x[i])%mod;
}
for(int i=1; i<=N; i++){
if(x[i]>1){
suf.insert({i, x[i]});
}
}
return get_resp(N);
}
int updateX(int pos, int val) {
auto it=suf.lower_bound({pos+1, 0});
if( (it!=suf.end()) ){
if( (it->ft)==(pos+1) ){
prod=(prod*inv(it->sc))%mod;
suf.erase(it);
}
}
if( (val>1) ){suf.insert({(pos+1), val});}
prod=(prod*val)%mod;
return get_resp(N);
}
int updateY(int pos, int val) {
update_seg(1, 1, N, pos+1, val);
return get_resp(N);
}
Compilation message
horses.cpp: In function 'void update_seg(int, int, int, int, int)':
horses.cpp:52:54: warning: declaration of 'x' shadows a global declaration [-Wshadow]
52 | void update_seg(int v, int tl, int tr, int pos, int x){
| ^
horses.cpp:36:5: note: shadowed declaration is here
36 | int x[500010], y[500010];
| ^
horses.cpp: In function 'int get_resp(int)':
horses.cpp:86:19: warning: declaration of 'N' shadows a global declaration [-Wshadow]
86 | int get_resp(int N){
| ^
horses.cpp:15:5: note: shadowed declaration is here
15 | int N;
| ^
horses.cpp:95:31: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
95 | res=query(1, 1, N, 1, lt);
| ^~
horses.cpp:96:26: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
96 | return (res*prod)%mod;
| ~~~~~~~~~~^~~~
horses.cpp:102:29: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
102 | ll Y=query(1, 1, N, pos, lt);
| ^~~
horses.cpp:102:34: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
102 | ll Y=query(1, 1, N, pos, lt);
| ^~
horses.cpp:122:32: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
122 | ll Y=query(1, 1, N, 1, lt);
| ^~
horses.cpp:133:12: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
133 | return res;
| ^~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
0 ms |
364 KB |
Output is correct |
5 |
Correct |
0 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
0 ms |
364 KB |
Output is correct |
8 |
Correct |
1 ms |
384 KB |
Output is correct |
9 |
Correct |
1 ms |
384 KB |
Output is correct |
10 |
Correct |
0 ms |
364 KB |
Output is correct |
11 |
Correct |
0 ms |
364 KB |
Output is correct |
12 |
Correct |
0 ms |
364 KB |
Output is correct |
13 |
Correct |
0 ms |
364 KB |
Output is correct |
14 |
Correct |
0 ms |
364 KB |
Output is correct |
15 |
Correct |
0 ms |
364 KB |
Output is correct |
16 |
Correct |
1 ms |
364 KB |
Output is correct |
17 |
Correct |
1 ms |
384 KB |
Output is correct |
18 |
Correct |
1 ms |
364 KB |
Output is correct |
19 |
Correct |
1 ms |
364 KB |
Output is correct |
20 |
Correct |
1 ms |
512 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
396 KB |
Output is correct |
8 |
Correct |
0 ms |
364 KB |
Output is correct |
9 |
Correct |
0 ms |
364 KB |
Output is correct |
10 |
Correct |
1 ms |
384 KB |
Output is correct |
11 |
Correct |
0 ms |
364 KB |
Output is correct |
12 |
Correct |
1 ms |
364 KB |
Output is correct |
13 |
Correct |
0 ms |
364 KB |
Output is correct |
14 |
Correct |
0 ms |
364 KB |
Output is correct |
15 |
Correct |
1 ms |
364 KB |
Output is correct |
16 |
Correct |
1 ms |
364 KB |
Output is correct |
17 |
Correct |
1 ms |
364 KB |
Output is correct |
18 |
Correct |
0 ms |
364 KB |
Output is correct |
19 |
Correct |
1 ms |
364 KB |
Output is correct |
20 |
Correct |
1 ms |
364 KB |
Output is correct |
21 |
Correct |
1 ms |
364 KB |
Output is correct |
22 |
Correct |
1 ms |
384 KB |
Output is correct |
23 |
Correct |
2 ms |
376 KB |
Output is correct |
24 |
Correct |
2 ms |
364 KB |
Output is correct |
25 |
Correct |
2 ms |
364 KB |
Output is correct |
26 |
Correct |
1 ms |
364 KB |
Output is correct |
27 |
Correct |
4 ms |
364 KB |
Output is correct |
28 |
Correct |
3 ms |
364 KB |
Output is correct |
29 |
Correct |
1 ms |
364 KB |
Output is correct |
30 |
Correct |
2 ms |
364 KB |
Output is correct |
31 |
Correct |
3 ms |
364 KB |
Output is correct |
32 |
Correct |
4 ms |
364 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
742 ms |
36720 KB |
Output is correct |
2 |
Correct |
331 ms |
40300 KB |
Output is correct |
3 |
Correct |
348 ms |
40428 KB |
Output is correct |
4 |
Correct |
471 ms |
40940 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
0 ms |
364 KB |
Output is correct |
3 |
Correct |
0 ms |
364 KB |
Output is correct |
4 |
Correct |
0 ms |
364 KB |
Output is correct |
5 |
Correct |
0 ms |
364 KB |
Output is correct |
6 |
Correct |
0 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
0 ms |
364 KB |
Output is correct |
9 |
Correct |
0 ms |
364 KB |
Output is correct |
10 |
Correct |
0 ms |
364 KB |
Output is correct |
11 |
Correct |
1 ms |
364 KB |
Output is correct |
12 |
Correct |
1 ms |
364 KB |
Output is correct |
13 |
Correct |
1 ms |
364 KB |
Output is correct |
14 |
Correct |
0 ms |
364 KB |
Output is correct |
15 |
Correct |
1 ms |
364 KB |
Output is correct |
16 |
Correct |
1 ms |
364 KB |
Output is correct |
17 |
Correct |
1 ms |
364 KB |
Output is correct |
18 |
Correct |
0 ms |
364 KB |
Output is correct |
19 |
Correct |
1 ms |
364 KB |
Output is correct |
20 |
Correct |
1 ms |
364 KB |
Output is correct |
21 |
Correct |
1 ms |
492 KB |
Output is correct |
22 |
Correct |
1 ms |
384 KB |
Output is correct |
23 |
Correct |
1 ms |
364 KB |
Output is correct |
24 |
Correct |
2 ms |
364 KB |
Output is correct |
25 |
Correct |
2 ms |
364 KB |
Output is correct |
26 |
Correct |
1 ms |
364 KB |
Output is correct |
27 |
Correct |
4 ms |
364 KB |
Output is correct |
28 |
Correct |
2 ms |
364 KB |
Output is correct |
29 |
Correct |
1 ms |
364 KB |
Output is correct |
30 |
Correct |
3 ms |
364 KB |
Output is correct |
31 |
Correct |
3 ms |
364 KB |
Output is correct |
32 |
Correct |
4 ms |
364 KB |
Output is correct |
33 |
Correct |
44 ms |
12524 KB |
Output is correct |
34 |
Correct |
38 ms |
12524 KB |
Output is correct |
35 |
Correct |
218 ms |
36076 KB |
Output is correct |
36 |
Correct |
181 ms |
35820 KB |
Output is correct |
37 |
Correct |
105 ms |
12428 KB |
Output is correct |
38 |
Correct |
104 ms |
24300 KB |
Output is correct |
39 |
Correct |
36 ms |
12268 KB |
Output is correct |
40 |
Correct |
168 ms |
35820 KB |
Output is correct |
41 |
Correct |
63 ms |
12396 KB |
Output is correct |
42 |
Correct |
81 ms |
12396 KB |
Output is correct |
43 |
Correct |
172 ms |
35820 KB |
Output is correct |
44 |
Correct |
161 ms |
35948 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
0 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
0 ms |
364 KB |
Output is correct |
9 |
Correct |
1 ms |
364 KB |
Output is correct |
10 |
Correct |
0 ms |
364 KB |
Output is correct |
11 |
Correct |
0 ms |
364 KB |
Output is correct |
12 |
Correct |
1 ms |
384 KB |
Output is correct |
13 |
Correct |
1 ms |
364 KB |
Output is correct |
14 |
Correct |
1 ms |
364 KB |
Output is correct |
15 |
Correct |
1 ms |
364 KB |
Output is correct |
16 |
Correct |
1 ms |
364 KB |
Output is correct |
17 |
Correct |
1 ms |
364 KB |
Output is correct |
18 |
Correct |
1 ms |
364 KB |
Output is correct |
19 |
Correct |
1 ms |
364 KB |
Output is correct |
20 |
Correct |
1 ms |
364 KB |
Output is correct |
21 |
Correct |
1 ms |
364 KB |
Output is correct |
22 |
Correct |
1 ms |
364 KB |
Output is correct |
23 |
Correct |
1 ms |
364 KB |
Output is correct |
24 |
Correct |
1 ms |
364 KB |
Output is correct |
25 |
Correct |
2 ms |
364 KB |
Output is correct |
26 |
Correct |
2 ms |
364 KB |
Output is correct |
27 |
Correct |
4 ms |
364 KB |
Output is correct |
28 |
Correct |
2 ms |
364 KB |
Output is correct |
29 |
Correct |
1 ms |
364 KB |
Output is correct |
30 |
Correct |
2 ms |
364 KB |
Output is correct |
31 |
Correct |
3 ms |
364 KB |
Output is correct |
32 |
Correct |
4 ms |
364 KB |
Output is correct |
33 |
Correct |
724 ms |
36972 KB |
Output is correct |
34 |
Correct |
331 ms |
39020 KB |
Output is correct |
35 |
Correct |
354 ms |
38924 KB |
Output is correct |
36 |
Correct |
462 ms |
39020 KB |
Output is correct |
37 |
Correct |
45 ms |
14700 KB |
Output is correct |
38 |
Correct |
45 ms |
14700 KB |
Output is correct |
39 |
Correct |
198 ms |
38252 KB |
Output is correct |
40 |
Correct |
184 ms |
38124 KB |
Output is correct |
41 |
Correct |
107 ms |
13036 KB |
Output is correct |
42 |
Correct |
106 ms |
25580 KB |
Output is correct |
43 |
Correct |
37 ms |
12780 KB |
Output is correct |
44 |
Correct |
171 ms |
38252 KB |
Output is correct |
45 |
Correct |
63 ms |
12908 KB |
Output is correct |
46 |
Correct |
84 ms |
12908 KB |
Output is correct |
47 |
Correct |
157 ms |
38124 KB |
Output is correct |
48 |
Correct |
157 ms |
38124 KB |
Output is correct |
49 |
Correct |
175 ms |
16748 KB |
Output is correct |
50 |
Correct |
114 ms |
16748 KB |
Output is correct |
51 |
Correct |
401 ms |
39276 KB |
Output is correct |
52 |
Correct |
237 ms |
39276 KB |
Output is correct |
53 |
Correct |
713 ms |
16140 KB |
Output is correct |
54 |
Correct |
316 ms |
31340 KB |
Output is correct |
55 |
Correct |
158 ms |
15468 KB |
Output is correct |
56 |
Correct |
288 ms |
41196 KB |
Output is correct |
57 |
Correct |
443 ms |
16236 KB |
Output is correct |
58 |
Correct |
623 ms |
16748 KB |
Output is correct |
59 |
Correct |
159 ms |
40300 KB |
Output is correct |