이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#define fast ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#include <bits/stdc++.h>
using namespace std;
#define sqr 200
#define mid (l+r)/2
#define pb push_back
#define ppb pop_back
#define fi first
#define se second
#define lb lower_bound
#define ub upper_bound
#define ins insert
#define era erase
#define C continue
#define mem(dp,i) memset(dp,i,sizeof(dp))
#define mset multiset
typedef long long ll;
typedef short int si;
typedef long double ld;
typedef pair<int,int> pi;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<pi> vpi;
typedef vector<pll> vpll;
const ll mod=1e9+7;
const ll inf= 4e18;
const ld pai=acos(-1);
#include "horses.h"
ll n ;
ll a[500009],cost[500009];
//
ll tree[2000009];
ll merge ( ll x , ll y ){
x%=mod;
y%=mod;
return (x*y)%mod;
}
void build(ll node,ll l,ll r){
if ( l == r ){
tree[node] = a[l];
return ;
}
build(node*2,l,mid);
build(node*2+1,mid+1,r);
tree[node] = merge ( tree[node*2] , tree[node*2+1] ) ;
}
void upd(ll node,ll l,ll r,ll id){
if ( l==r ){
tree[node] = a[l];
return ;
}
if ( id<=mid ) upd(node*2,l,mid,id);
else upd(node*2+1,mid+1,r,id);
tree[node] = merge ( tree[node*2] , tree[node*2+1] ) ;
}
ll query(ll node,ll l,ll r,ll s,ll e){
if ( l>r || s>r || e<l ) return 1;
if ( s<=l && e>=r ) return tree[node];
return merge( query(node*2,l,mid,s,e) , query(node*2+1,mid+1,r,s,e) );
}
//
ll MX [ 2000009];
void buildRMQ(int node,int l,int r){
if ( l==r ) {
MX [ node ] = cost[l];
return ;
}
buildRMQ(node*2,l,mid);
buildRMQ(node*2+1,mid+1,r);
MX [node] = max ( MX[node*2] , MX[node*2+1] );
}
void updRMQ(int node,int l,int r,int id){
if ( l==r ){
MX [ node ] = cost[l];
return ;
}
if ( id <= mid ) updRMQ(node*2,l,mid,id);
else updRMQ(node*2+1,mid+1,r,id);
MX [node] = max ( MX[node*2] , MX[node*2+1] );
}
ll RMQ ( int node,int l,int r,int s,int e){
if ( l>r || s>r || e<l ) return 0;
if ( s<=l && e>=r ) return MX[node];
return max ( RMQ ( node*2,l,mid,s,e ) , RMQ ( node*2+1,mid+1,r,s,e) );
}
//
set< pi > s;
void buildIntervals(){
for ( int i =0 ;i < n;i ++ ){
int j =i+1 ;
while ( j<n && a[j]==1 )j ++ ;
j -- ;
s.ins ( { i , j } ) ;
i = j ;
}
}
void add ( int pos ){
auto it = s.ub ( { pos , 1e9 } );
it -- ;
int l = it->fi , r = it->se;
if ( l == pos ) return ;
s.era ( it ) ;
s.ins ( { l , pos-1 } );
s.ins ( {pos, r } );
}
void del ( int pos ){
auto it = s.ub ( { pos , 1e9 } );
it -- ;
int l = it->fi , r = it->se;
if ( it == s.begin() ) return ;
it -- ;
s.era ( {l,r} ) ;
int L = it->fi , R = it->se;
s.era( it ) ;
s.ins ( { L , r } ) ;
}
ll check ( int l, int r ){
int num = 0 ;
for ( int i =l ;i <=r ;i ++ ) num += (a[i]>1);
return (num>=2);
}
ll solve(){
auto it = -- s.end();
ll crnt =1 ;
for ( auto u :s ){
if ( check(u.fi , u.se ) ){
while ( 1) {
}
}
}
for ( ; ; it--){
int l = it->fi , r = it->se;
crnt *= query(1,0,n-1,l,r);
if ( crnt > 2e9 ){
it++;
break;
}
if ( it == s.begin() ) break;
}crnt = 1;
ll ans = 0;
int ST = it->fi ;
if ( ST ) ans = cost[ ST - 1 ];
for( ; it!=s.end() ; it ++ ){
int l = it->fi , r =it->se;
ll A = query ( 1,0,n-1 , l, r);
ll COST = RMQ ( 1,0,n-1 , l, r);
if ( COST == 0 ) while(1){}
if ( A != a[l])while(1){}
crnt *= A;
if ( crnt > 2e9) while(1){}
ans = max ( ans, crnt * COST);
}
ans %= mod ;
ans *= query ( 1 , 0 , n-1 , 0 , ST-1 ) ;
ans %= mod ;
return ans;
}
int init(int N, int X[], int Y[]) {
n = N;
for ( int i =0 ;i < n ;i ++ ) a[i]=X[i];
for ( int i =0 ;i < n ;i ++ ) cost [i] = Y [i];
build(1,0,n-1);
buildRMQ(1,0,n-1);
buildIntervals();
return solve();
}
int updateX(int pos, int val) {
if ( a[pos] == 1 ) add(pos);
if ( val == 1 ) del(pos);
a[pos]=val;
upd(1,0,n-1,pos);
return solve();
}
int updateY(int pos, int val) {
cost[pos]=val;
updRMQ(1,0,n-1,pos);
return solve();
}
컴파일 시 표준 에러 (stderr) 메시지
horses.cpp: In function 'void del(int)':
horses.cpp:114:26: warning: unused variable 'R' [-Wunused-variable]
int L = it->fi , R = it->se;
^
horses.cpp: In function 'll solve()':
horses.cpp:136:29: warning: conversion to 'double' from 'll {aka long long int}' may alter its value [-Wconversion]
if ( crnt > 2e9 ){
^~~
horses.cpp:148:40: warning: conversion to 'int' from 'll {aka long long int}' may alter its value [-Wconversion]
ll COST = RMQ ( 1,0,n-1 , l, r);
~^~
horses.cpp:152:25: warning: conversion to 'double' from 'll {aka long long int}' may alter its value [-Wconversion]
if ( crnt > 2e9) while(1){}
^~~
horses.cpp: In function 'int init(int, int*, int*)':
horses.cpp:165:23: warning: conversion to 'int' from 'll {aka long long int}' may alter its value [-Wconversion]
buildRMQ(1,0,n-1);
~^~
horses.cpp:167:21: warning: conversion to 'int' from 'll {aka long long int}' may alter its value [-Wconversion]
return solve();
~~~~~^~
horses.cpp: In function 'int updateX(int, int)':
horses.cpp:174:21: warning: conversion to 'int' from 'll {aka long long int}' may alter its value [-Wconversion]
return solve();
~~~~~^~
horses.cpp: In function 'int updateY(int, int)':
horses.cpp:178:21: warning: conversion to 'int' from 'll {aka long long int}' may alter its value [-Wconversion]
updRMQ(1,0,n-1,pos);
~^~
horses.cpp:179:21: warning: conversion to 'int' from 'll {aka long long int}' may alter its value [-Wconversion]
return solve();
~~~~~^~
# | 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... |