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 <stdio.h>
#include <stdlib.h>
#include <bits/stdc++.h>
using namespace std;
long long n,a[500500],b[500500],mod=1e9+7,tree[2005000],mxtree[2005000];
multiset<int>ms;
long long qrx(int nod,int l,int r,int x,int y)
{
if(x<=l&&r<=y)return tree[nod];
else if(r<x||y<l)return 1ll;
int mid=(l+r)/2;
return (qrx(nod*2,l,mid,x,y)*qrx(nod*2+1,mid+1,r,x,y))%mod;
}
long long qry(int nod,int l,int r,int x,int y)
{
if(x<=l&&r<=y)return mxtree[nod];
else if(r<x||y<l)return 0ll;
int mid=(l+r)/2;
return max(qry(nod*2,l,mid,x,y),qry(nod*2+1,mid+1,r,x,y));
}
long long slov()
{
if(ms.size()==0)return qry(1,0,n+5,0,n-1);
long long x=1,ans=0,st;
multiset<int>::iterator it=--ms.end(),its;
while(1)
{
int i=*it;
x*=a[i];
if(x>(long long)2e9)break;
its=it;
if(it==ms.begin())break;
it--;
}
st=*its;
if(st)
{
if(its!=ms.begin())
{
multiset<int>::iterator ls=its;
ls--;
ans=b[*ls];
}
}
x=1;
for(its;its!=ms.end();its++)
{
int i=*its,nxt;
x*=a[i];
if(its==--ms.end())nxt=n;
else
{
multiset<int>::iterator nxti=its;
nxti++;
nxt=*nxti;
}
ans=max(ans,x*qry(1,0,n+5,i,nxt-1));
}
ans%=mod;
ans*=qrx(1,0,n+5,0,st-1);
return ans%mod;
}
void upy(int nod,int l,int r,int x,long long val)
{
if(x<l||r<x)return;
if(l==r)
{
mxtree[nod]=val;
return;
}
int mid=(l+r)/2;
upy(nod*2,l,mid,x,val);
upy(nod*2+1,mid+1,r,x,val);
mxtree[nod]=max(mxtree[nod*2],mxtree[nod*2+1]);
}
void upx(int nod,int l,int r,int x,long long val)
{
if(x<l||r<x)return;
if(l==r)
{
tree[nod]=val;
return;
}
int mid=(l+r)/2;
upx(nod*2,l,mid,x,val);
upx(nod*2+1,mid+1,r,x,val);
tree[nod]=(tree[nod*2]*tree[nod*2+1])%mod;
}
int init(int N, int X[], int Y[])
{
n=N;
for(int i=0;i<n;i++)
{
a[i]=X[i];
b[i]=Y[i];
if(a[i]!=1)ms.insert(i);
upx(1,0,n+5,i,a[i]);
upy(1,0,n+5,i,b[i]);
}
return slov();
}
int updateX(int pos, int val)
{
if(a[pos]!=1)ms.erase(ms.lower_bound(pos));
a[pos]=val;
if(a[pos]!=1)ms.insert(pos);
upx(1,0,n+5,pos,val);
return slov();
}
int updateY(int pos, int val)
{
b[pos]=val;
upy(1,0,n+5,pos,val);
return slov();
}
Compilation message (stderr)
horses.cpp: In function 'long long int slov()':
horses.cpp:24:37: warning: conversion to 'int' from 'long long int' may alter its value [-Wconversion]
if(ms.size()==0)return qry(1,0,n+5,0,n-1);
~^~
horses.cpp:24:43: warning: conversion to 'int' from 'long long int' may alter its value [-Wconversion]
if(ms.size()==0)return qry(1,0,n+5,0,n-1);
~^~
horses.cpp:47:12: warning: statement has no effect [-Wunused-value]
for(its;its!=ms.end();its++)
^
horses.cpp:51:32: warning: conversion to 'int' from 'long long int' may alter its value [-Wconversion]
if(its==--ms.end())nxt=n;
^
horses.cpp:58:32: warning: conversion to 'int' from 'long long int' may alter its value [-Wconversion]
ans=max(ans,x*qry(1,0,n+5,i,nxt-1));
~^~
horses.cpp:61:19: warning: conversion to 'int' from 'long long int' may alter its value [-Wconversion]
ans*=qrx(1,0,n+5,0,st-1);
~^~
horses.cpp:61:26: warning: conversion to 'int' from 'long long int' may alter its value [-Wconversion]
ans*=qrx(1,0,n+5,0,st-1);
~~^~
horses.cpp: In function 'int init(int, int*, int*)':
horses.cpp:98:18: warning: conversion to 'int' from 'long long int' may alter its value [-Wconversion]
upx(1,0,n+5,i,a[i]);
~^~
horses.cpp:99:18: warning: conversion to 'int' from 'long long int' may alter its value [-Wconversion]
upy(1,0,n+5,i,b[i]);
~^~
horses.cpp:101:16: warning: conversion to 'int' from 'long long int' may alter its value [-Wconversion]
return slov();
~~~~^~
horses.cpp: In function 'int updateX(int, int)':
horses.cpp:108:14: warning: conversion to 'int' from 'long long int' may alter its value [-Wconversion]
upx(1,0,n+5,pos,val);
~^~
horses.cpp:109:16: warning: conversion to 'int' from 'long long int' may alter its value [-Wconversion]
return slov();
~~~~^~
horses.cpp: In function 'int updateY(int, int)':
horses.cpp:114:14: warning: conversion to 'int' from 'long long int' may alter its value [-Wconversion]
upy(1,0,n+5,pos,val);
~^~
horses.cpp:115:16: warning: conversion to 'int' from 'long long int' may alter its value [-Wconversion]
return slov();
~~~~^~
# | 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... |