이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "horses.h"
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using P=pair<int,int>;
int x[500000],y[500000];
int n;
const ll mod=1000000007LL;
struct segtree{
int n;
vector<ll> dat;
void build(int n_){
n=1;
while(n<n_)n<<=1;
dat.resize(2*n,1);
}
void upd(int k,ll s){
k+=n;
dat[k]=s%mod;
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]%mod;
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;
struct RMQ{
int n;
vector<ll> dat;
void build(int n_){
n=1;
while(n<n_)n<<=1;
dat.resize(2*n,0);
}
void upd(int k,ll s){
k+=n;
dat[k]=s;
k>>=1;
while(k>0){
dat[k]=max(dat[k<<1],dat[k<<1|1]);
k>>=1;
}
}
ll get(int a,int b,int k,int l,int r){
if(b<=l||r<=a)return 0;
if(a<=l&&r<=b)return dat[k];
int m=(l+r)/2;
return max(get(a,b,k<<1,l,m),get(a,b,k<<1|1,m,r));
}
ll get(int a,int b){return get(a,b,1,0,n);}
} rmq;
set<P> st;
ll calc(){
ll id=-1,t=1,by=-1;
for(auto it=prev(st.end());;it--){
ll yy=rmq.get(it->first,it->second+1);
if(yy>t*by){
by=yy;
id=it->first;
t=1;
}
t*=x[it->first];
if(t>=mod)break;
if(it==st.begin())break;
}
return by*seg.get(0,id+1)%mod;
}
int init(int N, int X[], int Y[]) {
n=N;
seg.build(n+10);
rmq.build(n+10);
int l=0;
for(int i=0;i<n;i++){
x[i]=X[i];
y[i]=Y[i];
if(x[i]!=1){
if(i>0)st.insert(P(l,i-1));
l=i;
}
seg.upd(i,x[i]);
rmq.upd(i,y[i]);
}
st.insert(P(l,n-1));
return calc();
}
int updateX(int pos, int val) {
if(x[pos]==val)return calc();
if(x[pos]==1){
auto it=prev(st.lower_bound(P(pos+1,0)));
st.insert(P(pos,it->second));
if(it->first!=pos)st.insert(P(it->first,pos-1));
st.erase(it);
}else if(val==1){
auto it=prev(st.lower_bound(P(pos+1,0)));
if(it!=st.begin()){
auto i2=prev(it);
st.insert(P(i2->first,it->second));
st.erase(i2);
st.erase(it);
}
}
x[pos]=val;
seg.upd(pos,val);
return calc();
}
int updateY(int pos, int val) {
y[pos]=val;
rmq.upd(pos,val);
return calc();
}
컴파일 시 표준 에러 (stderr) 메시지
horses.cpp: In function 'll calc()':
horses.cpp:73:24: warning: conversion to 'int' from 'll {aka long long int}' may alter its value [-Wconversion]
return by*seg.get(0,id+1)%mod;
~~^~
horses.cpp: In function 'int init(int, int*, int*)':
horses.cpp:91:13: warning: conversion to 'int' from 'll {aka long long int}' may alter its value [-Wconversion]
return calc();
~~~~^~
horses.cpp: In function 'int updateX(int, int)':
horses.cpp:94:28: warning: conversion to 'int' from 'll {aka long long int}' may alter its value [-Wconversion]
if(x[pos]==val)return calc();
~~~~^~
horses.cpp:111:13: warning: conversion to 'int' from 'll {aka long long int}' may alter its value [-Wconversion]
return calc();
~~~~^~
horses.cpp: In function 'int updateY(int, int)':
horses.cpp:117:13: warning: conversion to 'int' from 'll {aka long long int}' may alter its value [-Wconversion]
return calc();
~~~~^~
# | 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... |