Submission #206253

#TimeUsernameProblemLanguageResultExecution timeMemory
206253awlintqaaHorses (IOI15_horses)C++14
17 / 100
1593 ms52088 KiB
#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 queryX(int x,int y,int z,int l,int r){ ll crnt =1; for ( int i = l ;i <= r ;i ++ )crnt *= a[i]; return crnt; } ll RMQX(int x,int y,int z,int l,int r){ ll crnt = 0; for ( int i =l ;i<=r ;i ++ )crnt=max ( crnt, cost[i]); return crnt; } 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 *= queryX(1,0,n-1,l,r); if ( crnt > (ll)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 = queryX ( 1,0,n-1 , l, r); ll COST = RMQX ( 1,0,n-1 , l, r); if ( COST == 0 ) while(1){} if ( A != a[l])while(1){} crnt *= A; if ( crnt > 2e9 || crnt == 0) while(1){} ans = max ( ans, crnt * COST); } ans %= mod ; ans *= queryX ( 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(); }

Compilation message (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 queryX(int, int, int, int, int)':
horses.cpp:123:15: warning: unused parameter 'x' [-Wunused-parameter]
 ll queryX(int x,int y,int z,int l,int r){
               ^
horses.cpp:123:21: warning: unused parameter 'y' [-Wunused-parameter]
 ll queryX(int x,int y,int z,int l,int r){
                     ^
horses.cpp:123:27: warning: unused parameter 'z' [-Wunused-parameter]
 ll queryX(int x,int y,int z,int l,int r){
                           ^
horses.cpp: In function 'll RMQX(int, int, int, int, int)':
horses.cpp:128:13: warning: unused parameter 'x' [-Wunused-parameter]
 ll RMQX(int x,int y,int z,int l,int r){
             ^
horses.cpp:128:19: warning: unused parameter 'y' [-Wunused-parameter]
 ll RMQX(int x,int y,int z,int l,int r){
                   ^
horses.cpp:128:25: warning: unused parameter 'z' [-Wunused-parameter]
 ll RMQX(int x,int y,int z,int l,int r){
                         ^
horses.cpp: In function 'll solve()':
horses.cpp:145:37: warning: conversion to 'int' from 'll {aka long long int}' may alter its value [-Wconversion]
                 crnt *= queryX(1,0,n-1,l,r);
                                    ~^~
horses.cpp:157:38: warning: conversion to 'int' from 'll {aka long long int}' may alter its value [-Wconversion]
                 ll A = queryX ( 1,0,n-1 , l, r);
                                     ~^~
horses.cpp:158:41: warning: conversion to 'int' from 'll {aka long long int}' may alter its value [-Wconversion]
                 ll COST = RMQX   ( 1,0,n-1 , l, r);
                                        ~^~
horses.cpp:162:25: warning: conversion to 'double' from 'll {aka long long int}' may alter its value [-Wconversion]
             if ( crnt > 2e9 || crnt == 0) while(1){}
                         ^~~
horses.cpp:166:34: warning: conversion to 'int' from 'll {aka long long int}' may alter its value [-Wconversion]
         ans *= queryX ( 1 , 0 , n-1 , 0 , ST-1 ) ;
                                 ~^~
horses.cpp: In function 'int init(int, int*, int*)':
horses.cpp:175:23: warning: conversion to 'int' from 'll {aka long long int}' may alter its value [-Wconversion]
         buildRMQ(1,0,n-1);
                      ~^~
horses.cpp:177: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:184: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:188:21: warning: conversion to 'int' from 'll {aka long long int}' may alter its value [-Wconversion]
         updRMQ(1,0,n-1,pos);
                    ~^~
horses.cpp:189:21: warning: conversion to 'int' from 'll {aka long long int}' may alter its value [-Wconversion]
         return solve();
                ~~~~~^~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...