This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "horses.h"
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
int x[500000],y[500000],dat[1<<22];
int n;
const ll mod=1000000007LL;
struct segtree{
int n;
void build(int n_){
n=1;
while(n<n_)n<<=1;
for(int i=0;i<2*n;i++)dat[i]=1;
}
void upd(int k,ll s){
k+=n;
dat[k]=s;
k>>=1;
while(k>0){
dat[k]=dat[k<<1]*dat[k<<1|1]%mod;
k>>=1;
}
}
ll get(int a,int b,int k,int l,int r){
if(b<=l||r<=a)return 1LL;
if(a<=l&&r<=b)return dat[k];
int m=(l+r)/2;
return get(a,b,k<<1,l,m)*get(a,b,k<<1|1,m,r)%mod;
}
ll get(int a,int b){return get(a,b,1,0,n);}
} seg;
int calc(){
vector<ll> s(n);
ll id=n-1,t=x[n-1];
for(int i=n-2;i>=0;i--){
if(y[i]>t*y[id]){
id=i;
t=1;
}
t*=x[i];
if(t>=mod){
break;
}
}
return y[id]*seg.get(0,id+1)%mod;
}
int init(int N, int X[], int Y[]) {
n=N;
seg.build(n);
for(int i=0;i<n;i++){
x[i]=X[i];
y[i]=Y[i];
seg.upd(i,x[i]);
}
return calc();
}
int updateX(int pos, int val) {
x[pos]=val;
seg.upd(pos,val);
return calc();
}
int updateY(int pos, int val) {
y[pos]=val;
return calc();
}
Compilation message (stderr)
horses.cpp: In member function 'void segtree::upd(int, ll)':
horses.cpp:17:10: warning: conversion to 'int' from 'll {aka long long int}' may alter its value [-Wconversion]
dat[k]=s;
^
horses.cpp: In function 'int calc()':
horses.cpp:45:27: warning: conversion to 'int' from 'll {aka long long int}' may alter its value [-Wconversion]
return y[id]*seg.get(0,id+1)%mod;
~~^~
horses.cpp:45:30: warning: conversion to 'int' from 'll {aka long long int}' may alter its value [-Wconversion]
return y[id]*seg.get(0,id+1)%mod;
~~~~~~~~~~~~~~~~~~~~~^~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |