이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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<pair<int,long long> >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()
{
long long last=n-1,x=1,ans=0;
if(ms.size()==0)return qry(1,0,n+5,0,n-1);
multiset<pair<int,long long> >::iterator it=--ms.end(),st;
while(true)
{
pair<int,long long>z=*it;
long long in=z.first,val=z.second;
x*=val;
st=it;
if(it==ms.begin())break;
if(x>=2e9)break;
it--;
}
x=1;
long long ml;
for(st;st!=ms.end();st++)
{
pair<int,long long>z=*st;
long long ind=z.first,val=z.second,nxt;
if(x==1)ml=max(1ll,qrx(1,0,n+5,0,ind-1));
x*=val;
if(st==--ms.end())nxt=n;
else
{
pair<int,long long>z=*(++st);
st--;
nxt=z.first;
}
cout<<' '<<x<<' '<<ind<<' '<<last<<' '<<ml<<' '<<qry(1,0,n+5,ind,nxt-1)<<endl;
long long mx=x*qry(1,0,n+5,ind,nxt-1);
ans=max(ans,mx);
}
ans%=mod;
return (ans*ml)%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];
ms.insert({i,a[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)
{
ms.erase(ms.lower_bound({pos,a[pos]}));
a[pos]=val;
ms.insert({pos,a[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();
}
컴파일 시 표준 에러 (stderr) 메시지
horses.cpp: In function 'long long int slov()':
horses.cpp:25: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:25: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:34:15: warning: conversion to 'double' from 'long long int' may alter its value [-Wconversion]
if(x>=2e9)break;
^~~
horses.cpp:30:19: warning: unused variable 'in' [-Wunused-variable]
long long in=z.first,val=z.second;
^~
horses.cpp:39:11: warning: statement has no effect [-Wunused-value]
for(st;st!=ms.end();st++)
^
horses.cpp:43:37: warning: conversion to 'int' from 'long long int' may alter its value [-Wconversion]
if(x==1)ml=max(1ll,qrx(1,0,n+5,0,ind-1));
~^~
horses.cpp:43:45: warning: conversion to 'int' from 'long long int' may alter its value [-Wconversion]
if(x==1)ml=max(1ll,qrx(1,0,n+5,0,ind-1));
~~~^~
horses.cpp:48:32: warning: declaration of 'z' shadows a previous local [-Wshadow]
pair<int,long long>z=*(++st);
^
horses.cpp:41:28: note: shadowed declaration is here
pair<int,long long>z=*st;
^
horses.cpp:52:67: warning: conversion to 'int' from 'long long int' may alter its value [-Wconversion]
cout<<' '<<x<<' '<<ind<<' '<<last<<' '<<ml<<' '<<qry(1,0,n+5,ind,nxt-1)<<endl;
~^~
horses.cpp:52:79: warning: conversion to 'int' from 'long long int' may alter its value [-Wconversion]
cout<<' '<<x<<' '<<ind<<' '<<last<<' '<<ml<<' '<<qry(1,0,n+5,ind,nxt-1)<<endl;
^
horses.cpp:52:77: warning: conversion to 'int' from 'long long int' may alter its value [-Wconversion]
cout<<' '<<x<<' '<<ind<<' '<<last<<' '<<ml<<' '<<qry(1,0,n+5,ind,nxt-1)<<endl;
~~~^~
horses.cpp:53:33: warning: conversion to 'int' from 'long long int' may alter its value [-Wconversion]
long long mx=x*qry(1,0,n+5,ind,nxt-1);
~^~
horses.cpp:53:45: warning: conversion to 'int' from 'long long int' may alter its value [-Wconversion]
long long mx=x*qry(1,0,n+5,ind,nxt-1);
^
horses.cpp:53:43: warning: conversion to 'int' from 'long long int' may alter its value [-Wconversion]
long long mx=x*qry(1,0,n+5,ind,nxt-1);
~~~^~
horses.cpp: In function 'int init(int, int*, int*)':
horses.cpp:93:18: warning: conversion to 'int' from 'long long int' may alter its value [-Wconversion]
upx(1,0,n+5,i,a[i]);
~^~
horses.cpp:94:18: warning: conversion to 'int' from 'long long int' may alter its value [-Wconversion]
upy(1,0,n+5,i,b[i]);
~^~
horses.cpp:96: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:103:14: warning: conversion to 'int' from 'long long int' may alter its value [-Wconversion]
upx(1,0,n+5,pos,val);
~^~
horses.cpp:104: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:109:14: warning: conversion to 'int' from 'long long int' may alter its value [-Wconversion]
upy(1,0,n+5,pos,val);
~^~
horses.cpp:110:16: warning: conversion to 'int' from 'long long int' may alter its value [-Wconversion]
return slov();
~~~~^~
horses.cpp: In function 'long long int slov()':
horses.cpp:57:16: warning: 'ml' may be used uninitialized in this function [-Wmaybe-uninitialized]
return (ans*ml)%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... |