# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
560159 |
2022-05-11T06:40:37 Z |
Koosha_mv |
Horses (IOI15_horses) |
C++14 |
|
1500 ms |
47308 KB |
#include <bits/stdc++.h>
using namespace std;
#define dbgv(v) cout<<#v<<" = "; f(i,0,v.size()) cout<<v[i]<<" "; cout<<endl
#define dbga(a,x,y) cout<<#a<<" = "; f(i,x,y) cout<<a[i]<<" "; cout<<endl
#define erorp(x) cout<<#x<<"={"<<x.F<<" , "<<x.S<<"}"<<endl
#define eror(x) cout<<#x<<'='<<(x)<<endl
#define f_(i,a,b) for(int i=a;i>=b;i--)
#define f(i,a,b) for(int i=a;i<b;i++)
#define nb(x) __builtin_popcount(x)
#define all(v) v.begin(),v.end()
#define bit(n,k) (((n)>>(k))&1)
#define Add(x,y) x=(x+y)%mod
#define maxm(a,b) a=max(a,b)
#define minm(a,b) a=min(a,b)
#define lst(x) x[x.size()-1]
#define sz(x) int(x.size())
#define mp make_pair
#define ll long long
#define pb push_back
#define S second
#define F first
//#include "horses.h"
const int N=5e5+99,mod=1e9+7;
const ll inf=1e18+mod;
ll n,t,a[N],b[N],L[N],R[N],seg[N<<1];
ll pd=1;
set<int> s;
ll pow(ll x,ll y,ll mod){return(!y?1:pow(x*x%mod,y/2,mod)*(y&1?x:1))%mod;}
void build(){
f(i,0,n) seg[i+n]=b[i];
f_(i,n-1,1) seg[i]=max(seg[i<<1],seg[i<<1|1]);
}
void update(int id,int val){
seg[id]=val;
for(id>>=1;id>0;id>>=1){
seg[id]=max(seg[id<<1],seg[id<<1|1]);
}
}
int get(int l,int r){
ll ans=0;
for(l+=n,r+=n;l<r;l>>=1,r>>=1){
if(l&1) maxm(ans,seg[l++]);
if(r&1) maxm(ans,seg[--r]);
}
return ans;
}
int solve(){
ll ans=1,res=1;
f(i,0,n) res=1ll*res*a[i]%mod;
f(i,0,n) s.insert(i);
build();
f_(i,n-1,0){
maxm(ans,a[i]*max(ans,b[i]));
res=1ll*res*pow(a[i],mod-2,mod)%mod;
if(i==0 || ans>mod) break;
}
ans%=mod;
return 1ll*res*ans%mod;
}
int init(int _n, int X[], int Y[]) {
n=_n;
f(i,0,n) a[i]=X[i];
f(i,0,n) b[i]=Y[i];
f(i,0,n){
pd=1ll*pd*a[i]%mod;
if(a[i]>1) s.insert(i);
}
build();
return solve();
}
int updateX(int pos, int val) {
if(a[pos]==1 && val!=1) s.insert(pos);
if(a[pos]!=1 && val==1) s.erase(pos);
pd=1ll*pd*pow(a[pos],mod-2,mod)%mod;
a[pos]=val;
pd=1ll*pd*a[pos]%mod;
return solve();
}
int updateY(int pos, int val) {
b[pos]=val;
update(pos+n,val);
return solve();
}
/*
int32_t main(){
ios:: sync_with_stdio(0), cin.tie(0), cout.tie(0);
int n,q,a[10],b[10];
cin>>n;
f(i,0,n) cin>>a[i];
f(i,0,n) cin>>b[i];
cout<<init(n,a,b)<<endl;
cin>>q;
while(q--){
int t,pos,val;
cin>>t>>pos>>val;
if(t==1) cout<<updateX(pos,val)<<endl;
else cout<<updateY(pos,val)<<endl;
}
}*/
/*
3
2 1 3
3 4 1
1
2 1 2
*/
Compilation message
horses.cpp: In function 'long long int pow(long long int, long long int, long long int)':
horses.cpp:31:21: warning: declaration of 'mod' shadows a global declaration [-Wshadow]
31 | ll pow(ll x,ll y,ll mod){return(!y?1:pow(x*x%mod,y/2,mod)*(y&1?x:1))%mod;}
| ^
horses.cpp:24:20: note: shadowed declaration is here
24 | const int N=5e5+99,mod=1e9+7;
| ^~~
horses.cpp: In function 'void build()':
horses.cpp:35:8: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
35 | f_(i,n-1,1) seg[i]=max(seg[i<<1],seg[i<<1|1]);
| ~^~
horses.cpp:7:29: note: in definition of macro 'f_'
7 | #define f_(i,a,b) for(int i=a;i>=b;i--)
| ^
horses.cpp: In function 'int get(int, int)':
horses.cpp:45:7: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
45 | for(l+=n,r+=n;l<r;l>>=1,r>>=1){
| ~^~~
horses.cpp:45:12: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
45 | for(l+=n,r+=n;l<r;l>>=1,r>>=1){
| ~^~~
horses.cpp:49:9: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
49 | return ans;
| ^~~
horses.cpp: In function 'int solve()':
horses.cpp:56:8: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
56 | f_(i,n-1,0){
| ~^~
horses.cpp:7:29: note: in definition of macro 'f_'
7 | #define f_(i,a,b) for(int i=a;i>=b;i--)
| ^
horses.cpp:62:20: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
62 | return 1ll*res*ans%mod;
| ~~~~~~~~~~~^~~~
horses.cpp: In function 'int updateY(int, int)':
horses.cpp:85:12: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
85 | update(pos+n,val);
| ~~~^~
# |
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 |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 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 |
1 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 |
1 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 |
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 |
# |
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 |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
0 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 |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
1 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 |
1 ms |
212 KB |
Output is correct |
21 |
Correct |
0 ms |
212 KB |
Output is correct |
22 |
Correct |
1 ms |
212 KB |
Output is correct |
23 |
Correct |
45 ms |
340 KB |
Output is correct |
24 |
Correct |
39 ms |
436 KB |
Output is correct |
25 |
Correct |
42 ms |
348 KB |
Output is correct |
26 |
Correct |
38 ms |
340 KB |
Output is correct |
27 |
Correct |
104 ms |
408 KB |
Output is correct |
28 |
Correct |
42 ms |
424 KB |
Output is correct |
29 |
Correct |
250 ms |
460 KB |
Output is correct |
30 |
Correct |
96 ms |
340 KB |
Output is correct |
31 |
Correct |
248 ms |
432 KB |
Output is correct |
32 |
Correct |
154 ms |
408 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1584 ms |
43276 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
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 |
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 |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 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 |
1 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 |
1 ms |
212 KB |
Output is correct |
22 |
Correct |
0 ms |
212 KB |
Output is correct |
23 |
Correct |
46 ms |
416 KB |
Output is correct |
24 |
Correct |
42 ms |
440 KB |
Output is correct |
25 |
Correct |
43 ms |
432 KB |
Output is correct |
26 |
Correct |
42 ms |
444 KB |
Output is correct |
27 |
Correct |
97 ms |
340 KB |
Output is correct |
28 |
Correct |
44 ms |
416 KB |
Output is correct |
29 |
Correct |
254 ms |
404 KB |
Output is correct |
30 |
Correct |
89 ms |
340 KB |
Output is correct |
31 |
Correct |
242 ms |
412 KB |
Output is correct |
32 |
Correct |
160 ms |
412 KB |
Output is correct |
33 |
Execution timed out |
1556 ms |
47308 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 |
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 |
1 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 |
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 |
1 ms |
212 KB |
Output is correct |
20 |
Correct |
1 ms |
212 KB |
Output is correct |
21 |
Correct |
0 ms |
212 KB |
Output is correct |
22 |
Correct |
1 ms |
212 KB |
Output is correct |
23 |
Correct |
45 ms |
424 KB |
Output is correct |
24 |
Correct |
38 ms |
340 KB |
Output is correct |
25 |
Correct |
41 ms |
428 KB |
Output is correct |
26 |
Correct |
37 ms |
432 KB |
Output is correct |
27 |
Correct |
93 ms |
340 KB |
Output is correct |
28 |
Correct |
45 ms |
420 KB |
Output is correct |
29 |
Correct |
245 ms |
340 KB |
Output is correct |
30 |
Correct |
92 ms |
428 KB |
Output is correct |
31 |
Correct |
238 ms |
588 KB |
Output is correct |
32 |
Correct |
147 ms |
416 KB |
Output is correct |
33 |
Execution timed out |
1563 ms |
45516 KB |
Time limit exceeded |
34 |
Halted |
0 ms |
0 KB |
- |