# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
796393 |
2023-07-28T11:05:34 Z |
Rafi22 |
Horses (IOI15_horses) |
C++14 |
|
0 ms |
0 KB |
#include <bits/stdc++.h>
#include "horses.h"
using namespace std;
#define endl '\n'
#define st first
#define nd second
#define pb push_back
#define sz(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()
#define ll long long
ll mod=1000000007;
int inf=1000000007;
ll infl=1000000000000000007;
const int pot=1<<19,N=500007;
ll pw(ll a,int b)
{
ll res=1;
while(b)
{
if(b%2) res=res*a%mod;
a=a*a%mod;
b/=2;
}
return res;
}
int seg[2*pot+7];
void ins(int v,int x)
{
v+=pot-1;
seg[v]=x;
while(v>1)
{
v/=2;
seg[v]=max(seg[2*v],seg[2*v+1]);
}
}
int que(int v,int a,int b,int l,int r)
{
if(a<=l&&b>=r) return seg[v];
if(r<a||l>b) return 0;
return max(que(2*v,a,b,l,(l+r)/2),que(2*v+1,a,b,(l+r)/2+1,r));
}
set<int>S;
ll inv[N],x[N];
ll T=1;
ll get()
{
ll W=T,p=1;
vector<int>V;
for(auto i:S)
{
if(p>1000000000) break;
W=W*inv[-i]%mod;
p=p*x[-i];
V.pb(-i);
}
reverse(all(V));
__int128 ans=0,t=1;
for(auto i:V)
{
//cout<<i<<" "<<que(1,i,pot,1,pot)<<endl;
t=t*x[i];
ans=max(ans,t*que(1,i,pot,1,pot));
}
return ans%mod*W%mod;
}
int init(int n,vector<int>X,vector<int>Y)
{
for(int i=0;i<n;i++) seg[i+pot]=Y[i];
for(int i=pot-1;i>0;i--) seg[i]=max(seg[2*i],seg[2*i+1]);
for(int i=0;i<n;i++)
{
T=T*X[i]%mod;
x[i+1]=X[i];
inv[i+1]=pw(X[i],mod-2);
if(X[i]>1) S.insert(-(i+1));
}
return get();
}
ll updateX(int i,ll v)
{
i++;
T=T*inv[i]%mod;
S.erase(-i);
T=T*v%mod;
inv[i]=pw(v,mod-2);
if(v>1) S.insert(-i);
x[i]=v;
return get();
}
ll updateY(int i,ll v)
{
i++;
ins(i,v);
return get();
}
/*
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cout<<init(3,{2,1,3},{3,4,1})<<endl;
cout<<updateY(1,2)<<endl;
return 0;
}*/
Compilation message
horses.cpp: In function 'long long int get()':
horses.cpp:73:21: warning: conversion from '__int128' to 'long long int' may change value [-Wconversion]
73 | return ans%mod*W%mod;
| ~~~~~~~~~^~~~
horses.cpp: In function 'int init(int, std::vector<int>, std::vector<int>)':
horses.cpp:84:29: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
84 | inv[i+1]=pw(X[i],mod-2);
| ~~~^~
horses.cpp:87:15: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
87 | return get();
| ~~~^~
horses.cpp: In function 'long long int updateX(int, long long int)':
horses.cpp:97:20: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
97 | inv[i]=pw(v,mod-2);
| ~~~^~
horses.cpp: In function 'long long int updateY(int, long long int)':
horses.cpp:106:11: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
106 | ins(i,v);
| ^
/usr/bin/ld: /tmp/ccaNb1Ht.o: in function `main':
grader.c:(.text.startup+0xaa): undefined reference to `init(int, int*, int*)'
/usr/bin/ld: grader.c:(.text.startup+0x113): undefined reference to `updateX(int, int)'
/usr/bin/ld: grader.c:(.text.startup+0x16d): undefined reference to `updateY(int, int)'
collect2: error: ld returned 1 exit status