# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
620921 |
2022-08-03T10:26:06 Z |
amin |
Horses (IOI15_horses) |
C++14 |
|
1500 ms |
30492 KB |
#include "horses.h"
#include<bits/stdc++.h>
using namespace std;
long long x[500001];
long long seg[1000002],segg[1000002],mu[1000002];
long long y[500001];
long long h=(1e9+1);
long long mod=1e9+7;
void build(long v,long tl,long tr)
{
if(tl==tr)
{
seg[v]=x[tl];
mu[v]=seg[v];
return ;
}
long tm=(tl+tr)/2;
build(v*2,tl,tm);
build(v*2+1,tm+1,tr);
seg[v]=seg[v*2]*seg[v*2+1];
mu[v]=(mu[v*2]*mu[v*2+1])%mod;
if(seg[v]>h)
{
seg[v]=h;
}
}
void update(long v,long tl,long tr,long in)
{
if(tl==tr&&tl==in)
{
seg[v]=x[in];
mu[v]=seg[v];
return ;
}
long tm=(tl+tr)/2;
if(tm>=in)
{
update(v*2,tl,tm,in);
}else
{
update(v*2+1,tm+1,tr,in);
}
seg[v]=seg[v*2]*seg[v*2+1];
mu[v]=(mu[v*2]*mu[v*2+1])%mod;
if(seg[v]>h)
{
seg[v]=h;
}
}
long long get(long v,long tl,long tr,long l,long r)
{
if(l==tl&&r==tr)
{
return seg[v];
}
long tm=(tl+tr)/2;
if(r<=tm)
{
return get(v*2,tl,tm,l,r);
}
if(l>tm)
{
return get(v*2+1,tm+1,tr,l,r);
}
long long j=get(v*2,tl,tm,l,tm)*get(v*2+1,tm+1,tr,tm+1,r);
if(j>h)
{
j=h;
}
return j;
}
long n;
void build2(long v,long tl,long tr)
{
if(tl==tr)
{
segg[v]=tl;
return ;
}
long tm=(tl+tr)/2;
build2(v*2,tl,tm);
build2(v*2+1,tm+1,tr);
long long a=segg[v*2];
long long b=segg[v*2+1];
// cout<<a<<' '<<b<<' ';
// cout<<y[a]<<' '<<y[b]*get(1,0,n-1,a+1,b)<<endl;
if(y[a]>(y[b]*get(1,0,n-1,a+1,b)))
{
segg[v]=a;
}else
{
segg[v]=b;
}
}
void update2(long v,long tl,long tr,long in)
{
if(tl==tr)
{
segg[v]=tl;
return ;
}
long tm=(tl+tr)/2;
if(tm>=in)
{
update2(v*2,tl,tm,in);
}else
{
update2(v*2+1,tm+1,tr,in);
}
long long a=segg[v*2];
long long b=segg[v*2+1];
// cout<<a<<' '<<b<<' ';
// cout<<y[a]<<' '<<y[b]*get(1,0,n-1,a+1,b)<<endl;
if(y[a]>(y[b]*get(1,0,n-1,a+1,b)))
{
segg[v]=a;
}else
{
segg[v]=b;
}
}
long long get2(long v,long tl,long tr,long l,long r)
{
if(l==tl&&r==tr)
{
return mu[v];
}
long tm=(tl+tr)/2;
if(r<=tm)
{
return get2(v*2,tl,tm,l,r);
}
if(l>tm)
{
return get2(v*2+1,tm+1,tr,l,r);
}
long long j=(get2(v*2,tl,tm,l,tm)*get2(v*2+1,tm+1,tr,tm+1,r))%mod;
return j;
}
int init(int N, int X[], int Y[]) {
// cout<<mod<<endl;
n=N;
for(long i=0;i<n;i++)
{
x[i]=X[i];
y[i]=Y[i];
}
build(1,0,n-1);
long jj=0;
long in=0;
long long ans=y[in];
long long o=1;
long long t=in;
for(long i=in+1;i<n;i++)
{
o*=x[i];
if(o>h)
o=h;
if(o*y[i]<y[t])
{
continue;
}else
{
t=i;
o=1;
}
}
ans=(get2(1,0,n-1,0,t)*y[t])%mod;
return ans;
}
int updateX(int pos, int val) {
x[pos]=val;
update(1,0,n-1,pos);
long jj=0;
long in=0;
long long ans=y[in];
long long o=1;
long long t=in;
for(long i=in+1;i<n;i++)
{
o*=x[i];
if(o>h)
{
o=h;
}
if(o*y[i]<y[t])
{
continue;
}else
{
t=i;
o=1;
}
}
ans=(get2(1,0,n-1,0,t)*y[t])%mod;
return ans;
}
int updateY(int pos, int val) {
y[pos]=val;
update(1,0,n-1,pos);
long jj=0;
long in=0;
long long ans=y[in];
long long o=1;
long long t=in;
for(long i=in+1;i<n;i++)
{
o*=x[i];
if(o>h)
{
o=h;
}
if(o*y[i]<y[t])
{
continue;
}else
{
t=i;
o=1;
}
}
ans=(get2(1,0,n-1,0,t)*y[t])%mod;
return ans;
}
Compilation message
horses.cpp: In function 'int init(int, int*, int*)':
horses.cpp:177:10: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
177 | return ans;
| ^~~
horses.cpp:157:10: warning: unused variable 'jj' [-Wunused-variable]
157 | long jj=0;
| ^~
horses.cpp: In function 'int updateX(int, int)':
horses.cpp:208:10: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
208 | return ans;
| ^~~
horses.cpp:186:8: warning: unused variable 'jj' [-Wunused-variable]
186 | long jj=0;
| ^~
horses.cpp: In function 'int updateY(int, int)':
horses.cpp:236:10: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
236 | return ans;
| ^~~
horses.cpp:214:11: warning: unused variable 'jj' [-Wunused-variable]
214 | long jj=0;
| ^~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
340 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 |
340 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 |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
212 KB |
Output is correct |
17 |
Correct |
1 ms |
288 KB |
Output is correct |
18 |
Correct |
1 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 |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
1 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 |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
1 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 |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
212 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
21 |
Correct |
0 ms |
212 KB |
Output is correct |
22 |
Correct |
1 ms |
212 KB |
Output is correct |
23 |
Correct |
6 ms |
340 KB |
Output is correct |
24 |
Correct |
6 ms |
412 KB |
Output is correct |
25 |
Correct |
3 ms |
340 KB |
Output is correct |
26 |
Correct |
2 ms |
340 KB |
Output is correct |
27 |
Correct |
4 ms |
340 KB |
Output is correct |
28 |
Correct |
3 ms |
340 KB |
Output is correct |
29 |
Correct |
2 ms |
340 KB |
Output is correct |
30 |
Correct |
2 ms |
340 KB |
Output is correct |
31 |
Correct |
5 ms |
340 KB |
Output is correct |
32 |
Correct |
3 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1595 ms |
28080 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
340 KB |
Output is correct |
8 |
Correct |
1 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 |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
0 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
0 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 |
340 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 |
4 ms |
340 KB |
Output is correct |
24 |
Correct |
4 ms |
412 KB |
Output is correct |
25 |
Correct |
3 ms |
324 KB |
Output is correct |
26 |
Correct |
2 ms |
340 KB |
Output is correct |
27 |
Correct |
4 ms |
340 KB |
Output is correct |
28 |
Correct |
3 ms |
340 KB |
Output is correct |
29 |
Correct |
2 ms |
320 KB |
Output is correct |
30 |
Correct |
2 ms |
340 KB |
Output is correct |
31 |
Correct |
4 ms |
340 KB |
Output is correct |
32 |
Correct |
3 ms |
340 KB |
Output is correct |
33 |
Execution timed out |
1507 ms |
30492 KB |
Time limit exceeded |
34 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
340 KB |
Output is correct |
12 |
Correct |
0 ms |
340 KB |
Output is correct |
13 |
Correct |
0 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
0 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 |
212 KB |
Output is correct |
23 |
Correct |
4 ms |
340 KB |
Output is correct |
24 |
Correct |
4 ms |
340 KB |
Output is correct |
25 |
Correct |
2 ms |
340 KB |
Output is correct |
26 |
Correct |
2 ms |
324 KB |
Output is correct |
27 |
Correct |
3 ms |
340 KB |
Output is correct |
28 |
Correct |
3 ms |
340 KB |
Output is correct |
29 |
Correct |
3 ms |
312 KB |
Output is correct |
30 |
Correct |
2 ms |
340 KB |
Output is correct |
31 |
Correct |
4 ms |
340 KB |
Output is correct |
32 |
Correct |
4 ms |
340 KB |
Output is correct |
33 |
Execution timed out |
1557 ms |
29680 KB |
Time limit exceeded |
34 |
Halted |
0 ms |
0 KB |
- |