# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
414921 |
2021-05-31T10:39:06 Z |
Bill_00 |
Horses (IOI15_horses) |
C++14 |
|
944 ms |
56744 KB |
#include "horses.h"
#include <bits/stdc++.h>
#define MOD 1000000007
typedef long long ll;
using namespace std;
int xx[500005],yy[500005];
long long y[500005],x[500005],rightt[500005],leftt[500005];
long long pro[5000000],n,mx[5000000];
set<pair<ll,ll> >s;
void build1(long long id,long long l,long long r){
if(l==r){
mx[id]=y[l];
return;
}
ll m=(l+r)>>1;
build1(id*2,l,m);
build1(id*2+1,m+1,r);
mx[id]=max(mx[id*2],mx[id*2+1]);
}
void build(long long id,long long l,long long r){
if(l==r){
pro[id]=x[l];
return;
}
long long m=(l+r)>>1;
build(id*2,l,m);
build(id*2+1,m+1,r);
pro[id]=pro[id*2]*pro[id*2+1];
if(pro[id]>=MOD) pro[id]%=MOD;
}
long long query(long long id,long long l,long long r,long long L,long long R){
if(R<L) return 1;
if(r<L || R<l) return 1;
if(L<=l && r<=R) return pro[id];
long long m=(l+r)>>1;
return (query(id*2,l,m,L,R)*query(id*2+1,m+1,r,L,R))%MOD;
}
long long query1(ll id,ll l,ll r,ll L,ll R){
if(R<l || r<L) return 0;
if(L<=l && r<=R) return mx[id];
ll m=(l+r)>>1;
return max(query1(id*2,l,m,L,R),query1(id*2+1,m+1,r,L,R));
}
void update(ll id,ll l,ll r,ll d,ll e){
if(l==r){
pro[id]=e;
return;
}
ll m=(l+r)>>1;
if(m>=d) update(id*2,l,m,d,e);
else update(id*2+1,m+1,r,d,e);
pro[id]=pro[id*2]*pro[id*2+1];
if(pro[id]>=MOD) pro[id]%=MOD;
}
void update1(ll id,ll l,ll r,ll d,ll e){
if(l==r){
mx[id]=e;
return;
}
ll m=(l+r)>>1;
if(m>=d) update1(id*2,l,m,d,e);
else update1(id*2+1,m+1,r,d,e);
mx[id]=max(mx[id*2],mx[id*2+1]);
}
int init(int N,int X[],int Y[]){
s.insert({-1,-1});
memset(leftt,-1,sizeof(leftt));
memset(rightt,-1,sizeof(rightt));
n=(long long)N;
for(long long i=0;i<n;i++){
y[i]=(long long)Y[i];
x[i]=(long long)X[i];
}
build(1,0,n-1);
build1(1,0,n-1);
bool flag=0;
long long l;
for(long long i=0;i<n;i++){
if(x[i]==1 && flag==0){
flag=1;
l=i;
}
if(x[i]!=1 && flag==1){
flag=0;
s.insert({l,i-1});
rightt[l]=i-1;
leftt[i-1]=l;
}
}
if(flag==1){
rightt[l]=n-1;
leftt[n-1]=l;
s.insert({l,n-1});
}
long long c=y[n-1];
pair<long double,ll>p={0,-1};
for(ll i=n-1;i>=0;i--){
ll val=y[i];
if(leftt[i]!=-1){
i=leftt[i];
val=query1(1,0,n-1,i,rightt[i]);
}
// cout << (long double)(val)/(long double)(c) << ' ' << i << '\n';
p=max(p,{(long double)(val)/(long double)(c),i});
c*=x[i];
if(c>=1000000000) break;
}
ll ans=query(1,0,n-1,0,p.second);
ll id=p.second,val=y[id];
if(rightt[id]!=-1) val=query1(1,0,n-1,id,rightt[id]);
return (ans*val)%MOD;
}
int updateX(int pos, int val){
update(1,0,n-1,pos,val);
x[pos]=val;
if(val==1){
pair<ll,ll>temp={pos,1000000000};
auto it=s.lower_bound(temp);
--it;
if(it->first>pos || pos>it->second){
leftt[pos]=pos;
rightt[pos]=pos;
s.insert({leftt[pos],rightt[pos]});
if(pos>0 && leftt[pos-1]!=-1){
rightt[leftt[pos-1]]=rightt[pos];
leftt[rightt[pos]]=leftt[pos-1];
s.erase({leftt[pos-1],pos-1});
s.erase({pos,rightt[pos]});
s.insert({leftt[pos-1],rightt[pos]});
rightt[pos]=-1;
leftt[pos-1]=-1;
}
if(pos<(n-1) && rightt[pos+1]!=-1){
rightt[leftt[pos]]=rightt[pos+1];
leftt[rightt[pos+1]]=leftt[pos];
s.erase({leftt[pos],pos});
s.erase({pos+1,rightt[pos+1]});
s.insert({leftt[pos],rightt[pos+1]});
rightt[pos+1]=-1;
leftt[pos]=-1;
}
}
}
else{
pair<ll,ll>temp={pos,1000000000};
auto it=s.lower_bound(temp);
--it;
if(it->first<=pos && pos<=it->second){
ll st=it->first;
ll en=it->second;
s.erase(it);
leftt[en]=-1;
rightt[st]=-1;
if(st!=pos){
rightt[st]=pos-1;
leftt[pos-1]=st;
s.insert({st,pos-1});
}
if(en!=pos){
leftt[en]=pos+1;
rightt[pos+1]=en;
s.insert({pos+1,en});
}
}
}
long long c=y[n-1];
pair<long double,ll>p={0,-1};
for(ll i=n-1;i>=0;i--){
ll value=y[i];
if(leftt[i]!=-1){
i=leftt[i];
value=query1(1,0,n-1,i,rightt[i]);
}
p=max(p,{(long double)(value)/(long double)(c),i});
c*=x[i];
if(c>=1000000000) break;
}
ll ans=query(1,0,n-1,0,p.second);
ll id=p.second,value=y[id];
if(rightt[id]!=-1) value=query1(1,0,n-1,id,rightt[id]);
return (ans*value)%MOD;
}
int updateY(int pos, int val) {
update1(1,0,n-1,pos,val);
y[pos]=val;
long long c=y[n-1];
pair<long double,ll>p={0,-1};
for(ll i=n-1;i>=0;i--){
ll value=y[i];
if(leftt[i]!=-1){
i=leftt[i];
value=query1(1,0,n-1,i,rightt[i]);
}
p=max(p,{(long double)(value)/(long double)(c),i});
c*=x[i];
if(c>=1000000000) break;
}
ll ans=query(1,0,n-1,0,p.second);
ll id=p.second,value=y[id];
if(rightt[id]!=-1) value=query1(1,0,n-1,id,rightt[id]);
return (ans*value)%MOD;
}
Compilation message
horses.cpp: In function 'int init(int, int*, int*)':
horses.cpp:111:18: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
111 | return (ans*val)%MOD;
| ^
horses.cpp: In function 'int updateX(int, int)':
horses.cpp:182:20: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
182 | return (ans*value)%MOD;
| ^
horses.cpp: In function 'int updateY(int, int)':
horses.cpp:203:20: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
203 | return (ans*value)%MOD;
| ^
horses.cpp: In function 'int init(int, int*, int*)':
horses.cpp:87:14: warning: 'l' may be used uninitialized in this function [-Wmaybe-uninitialized]
87 | leftt[i-1]=l;
| ~~~~~~~~~~^~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
8140 KB |
Output is correct |
2 |
Correct |
5 ms |
8140 KB |
Output is correct |
3 |
Correct |
5 ms |
8140 KB |
Output is correct |
4 |
Correct |
5 ms |
8140 KB |
Output is correct |
5 |
Correct |
5 ms |
8108 KB |
Output is correct |
6 |
Correct |
5 ms |
8140 KB |
Output is correct |
7 |
Correct |
5 ms |
8140 KB |
Output is correct |
8 |
Correct |
5 ms |
8112 KB |
Output is correct |
9 |
Correct |
5 ms |
8144 KB |
Output is correct |
10 |
Correct |
5 ms |
8116 KB |
Output is correct |
11 |
Correct |
5 ms |
8140 KB |
Output is correct |
12 |
Correct |
5 ms |
8140 KB |
Output is correct |
13 |
Correct |
5 ms |
8140 KB |
Output is correct |
14 |
Correct |
6 ms |
8140 KB |
Output is correct |
15 |
Correct |
5 ms |
8140 KB |
Output is correct |
16 |
Correct |
6 ms |
8140 KB |
Output is correct |
17 |
Correct |
5 ms |
8148 KB |
Output is correct |
18 |
Correct |
5 ms |
8140 KB |
Output is correct |
19 |
Correct |
5 ms |
8140 KB |
Output is correct |
20 |
Correct |
5 ms |
8140 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
8140 KB |
Output is correct |
2 |
Correct |
4 ms |
8160 KB |
Output is correct |
3 |
Correct |
5 ms |
8108 KB |
Output is correct |
4 |
Correct |
5 ms |
8140 KB |
Output is correct |
5 |
Correct |
5 ms |
8112 KB |
Output is correct |
6 |
Correct |
5 ms |
8140 KB |
Output is correct |
7 |
Correct |
5 ms |
8140 KB |
Output is correct |
8 |
Correct |
5 ms |
8140 KB |
Output is correct |
9 |
Correct |
5 ms |
8112 KB |
Output is correct |
10 |
Correct |
5 ms |
8140 KB |
Output is correct |
11 |
Correct |
5 ms |
8140 KB |
Output is correct |
12 |
Correct |
5 ms |
8116 KB |
Output is correct |
13 |
Correct |
5 ms |
8108 KB |
Output is correct |
14 |
Correct |
5 ms |
8124 KB |
Output is correct |
15 |
Correct |
5 ms |
8140 KB |
Output is correct |
16 |
Correct |
5 ms |
8140 KB |
Output is correct |
17 |
Correct |
6 ms |
8112 KB |
Output is correct |
18 |
Correct |
5 ms |
8140 KB |
Output is correct |
19 |
Correct |
5 ms |
8140 KB |
Output is correct |
20 |
Correct |
5 ms |
8140 KB |
Output is correct |
21 |
Correct |
5 ms |
8140 KB |
Output is correct |
22 |
Correct |
5 ms |
8140 KB |
Output is correct |
23 |
Correct |
6 ms |
8196 KB |
Output is correct |
24 |
Correct |
5 ms |
8140 KB |
Output is correct |
25 |
Correct |
6 ms |
8140 KB |
Output is correct |
26 |
Correct |
5 ms |
8140 KB |
Output is correct |
27 |
Correct |
8 ms |
8140 KB |
Output is correct |
28 |
Correct |
6 ms |
8252 KB |
Output is correct |
29 |
Correct |
6 ms |
8108 KB |
Output is correct |
30 |
Correct |
6 ms |
8232 KB |
Output is correct |
31 |
Correct |
5 ms |
8100 KB |
Output is correct |
32 |
Correct |
10 ms |
8140 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
103 ms |
37956 KB |
Output is correct |
2 |
Correct |
145 ms |
39204 KB |
Output is correct |
3 |
Correct |
107 ms |
41044 KB |
Output is correct |
4 |
Correct |
144 ms |
44844 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
8140 KB |
Output is correct |
2 |
Correct |
4 ms |
8140 KB |
Output is correct |
3 |
Correct |
4 ms |
8140 KB |
Output is correct |
4 |
Correct |
5 ms |
8108 KB |
Output is correct |
5 |
Correct |
5 ms |
8112 KB |
Output is correct |
6 |
Correct |
5 ms |
8140 KB |
Output is correct |
7 |
Correct |
5 ms |
8140 KB |
Output is correct |
8 |
Correct |
5 ms |
8140 KB |
Output is correct |
9 |
Correct |
5 ms |
8140 KB |
Output is correct |
10 |
Correct |
6 ms |
8140 KB |
Output is correct |
11 |
Correct |
5 ms |
8140 KB |
Output is correct |
12 |
Correct |
5 ms |
8140 KB |
Output is correct |
13 |
Correct |
4 ms |
8140 KB |
Output is correct |
14 |
Correct |
5 ms |
8140 KB |
Output is correct |
15 |
Correct |
5 ms |
8140 KB |
Output is correct |
16 |
Correct |
5 ms |
8140 KB |
Output is correct |
17 |
Correct |
5 ms |
8140 KB |
Output is correct |
18 |
Correct |
6 ms |
8124 KB |
Output is correct |
19 |
Correct |
5 ms |
8140 KB |
Output is correct |
20 |
Correct |
5 ms |
8140 KB |
Output is correct |
21 |
Correct |
5 ms |
8140 KB |
Output is correct |
22 |
Correct |
6 ms |
8140 KB |
Output is correct |
23 |
Correct |
6 ms |
8140 KB |
Output is correct |
24 |
Correct |
5 ms |
8124 KB |
Output is correct |
25 |
Correct |
5 ms |
8140 KB |
Output is correct |
26 |
Correct |
5 ms |
8140 KB |
Output is correct |
27 |
Correct |
8 ms |
8240 KB |
Output is correct |
28 |
Correct |
6 ms |
8252 KB |
Output is correct |
29 |
Correct |
6 ms |
8220 KB |
Output is correct |
30 |
Correct |
6 ms |
8140 KB |
Output is correct |
31 |
Correct |
5 ms |
8140 KB |
Output is correct |
32 |
Correct |
9 ms |
8228 KB |
Output is correct |
33 |
Correct |
58 ms |
40428 KB |
Output is correct |
34 |
Correct |
50 ms |
40360 KB |
Output is correct |
35 |
Correct |
92 ms |
46148 KB |
Output is correct |
36 |
Correct |
74 ms |
46148 KB |
Output is correct |
37 |
Correct |
131 ms |
38536 KB |
Output is correct |
38 |
Correct |
139 ms |
54996 KB |
Output is correct |
39 |
Correct |
54 ms |
38288 KB |
Output is correct |
40 |
Correct |
62 ms |
42264 KB |
Output is correct |
41 |
Correct |
42 ms |
38340 KB |
Output is correct |
42 |
Correct |
102 ms |
38388 KB |
Output is correct |
43 |
Correct |
58 ms |
42592 KB |
Output is correct |
44 |
Correct |
52 ms |
42676 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
8140 KB |
Output is correct |
2 |
Correct |
4 ms |
8140 KB |
Output is correct |
3 |
Correct |
4 ms |
8140 KB |
Output is correct |
4 |
Correct |
4 ms |
8112 KB |
Output is correct |
5 |
Correct |
5 ms |
8140 KB |
Output is correct |
6 |
Correct |
4 ms |
8140 KB |
Output is correct |
7 |
Correct |
6 ms |
8140 KB |
Output is correct |
8 |
Correct |
5 ms |
8140 KB |
Output is correct |
9 |
Correct |
5 ms |
8140 KB |
Output is correct |
10 |
Correct |
6 ms |
8112 KB |
Output is correct |
11 |
Correct |
5 ms |
8108 KB |
Output is correct |
12 |
Correct |
4 ms |
8140 KB |
Output is correct |
13 |
Correct |
4 ms |
8108 KB |
Output is correct |
14 |
Correct |
4 ms |
8116 KB |
Output is correct |
15 |
Correct |
4 ms |
8140 KB |
Output is correct |
16 |
Correct |
4 ms |
8140 KB |
Output is correct |
17 |
Correct |
5 ms |
8140 KB |
Output is correct |
18 |
Correct |
4 ms |
8140 KB |
Output is correct |
19 |
Correct |
5 ms |
8268 KB |
Output is correct |
20 |
Correct |
4 ms |
8112 KB |
Output is correct |
21 |
Correct |
4 ms |
8140 KB |
Output is correct |
22 |
Correct |
4 ms |
8108 KB |
Output is correct |
23 |
Correct |
6 ms |
8140 KB |
Output is correct |
24 |
Correct |
5 ms |
8140 KB |
Output is correct |
25 |
Correct |
6 ms |
8248 KB |
Output is correct |
26 |
Correct |
5 ms |
8140 KB |
Output is correct |
27 |
Correct |
8 ms |
8140 KB |
Output is correct |
28 |
Correct |
6 ms |
8268 KB |
Output is correct |
29 |
Correct |
5 ms |
8140 KB |
Output is correct |
30 |
Correct |
5 ms |
8140 KB |
Output is correct |
31 |
Correct |
5 ms |
8140 KB |
Output is correct |
32 |
Correct |
8 ms |
8232 KB |
Output is correct |
33 |
Correct |
103 ms |
41084 KB |
Output is correct |
34 |
Correct |
153 ms |
46692 KB |
Output is correct |
35 |
Correct |
99 ms |
41028 KB |
Output is correct |
36 |
Correct |
120 ms |
44892 KB |
Output is correct |
37 |
Correct |
59 ms |
40360 KB |
Output is correct |
38 |
Correct |
50 ms |
40368 KB |
Output is correct |
39 |
Correct |
84 ms |
45504 KB |
Output is correct |
40 |
Correct |
75 ms |
45424 KB |
Output is correct |
41 |
Correct |
134 ms |
38544 KB |
Output is correct |
42 |
Correct |
134 ms |
55028 KB |
Output is correct |
43 |
Correct |
54 ms |
38312 KB |
Output is correct |
44 |
Correct |
64 ms |
42288 KB |
Output is correct |
45 |
Correct |
41 ms |
38412 KB |
Output is correct |
46 |
Correct |
108 ms |
38404 KB |
Output is correct |
47 |
Correct |
55 ms |
42668 KB |
Output is correct |
48 |
Correct |
59 ms |
42592 KB |
Output is correct |
49 |
Correct |
235 ms |
43640 KB |
Output is correct |
50 |
Correct |
138 ms |
43708 KB |
Output is correct |
51 |
Correct |
207 ms |
46272 KB |
Output is correct |
52 |
Correct |
125 ms |
46304 KB |
Output is correct |
53 |
Correct |
944 ms |
41844 KB |
Output is correct |
54 |
Correct |
315 ms |
56744 KB |
Output is correct |
55 |
Correct |
221 ms |
39364 KB |
Output is correct |
56 |
Correct |
181 ms |
44060 KB |
Output is correct |
57 |
Correct |
137 ms |
40044 KB |
Output is correct |
58 |
Correct |
692 ms |
40460 KB |
Output is correct |
59 |
Correct |
61 ms |
42640 KB |
Output is correct |