제출 #776765

#제출 시각아이디문제언어결과실행 시간메모리
776765lollipop쌀 창고 (IOI11_ricehub)C++17
68 / 100
1060 ms8512 KiB
#include "ricehub.h"
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/rope>
#define int long long
#define pb push_back
#define s second
#define f first
#define pf push_front
#define inf 100000000000000000
#define bitebi __builtin_popcountll
#define FOR( i , n ) for( int i = 0 ; i < n ; i ++ )
#define YES cout <<"YES\n"
#define NO cout << "NO\n"
#define debug cout << "Here Fine" << endl ;
#define pr pair < int , int >
#define fbo find_by_order // returns iterator
#define ook order_of_key // returns strictly less numbers than key
using namespace std ;
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
using namespace __gnu_pbds;
using namespace __gnu_cxx;
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
const double Pi=acos(-1.0);
const double EPS=1E-8;
const int mod =  1000000007 ;
const int mod1 = 998244353 ;
const int N = 2e5 + 10 ;
//mt19937 R(time(0));
map < int , int > ma , ma1 ;
pair < int , int > sm[ N ] ;
set < pair < int , int > > se ;
pair < int , int > get_sum( int l , int r , int x ){
	int L , R ; 
	if( l > r ) return { 0 , 0 } ; 
	pair < int , int > p ;
	p = *( -- se.end() ) ;
	if( p.f < l ) return { 0 , 0 } ;  
	p = *(se.lower_bound( { l , -1 } ) ) ;
	L = p.s ;
	if( p.f > r ) return { 0 , 0 } ;
	p = *(--se.lower_bound( { r + 1 , -1 } ) ) ;
	R = p.s ; 
	p = sm[ R ] ;
	if( L != 0 ){
		p.f -= sm[ L - 1 ].f ;
		p.s -= sm[ L - 1 ].s ; 
	} 
	if( l <= x ){
		p.f = p.s * x - p.f ;
	}
	else{
		p.f = p.f - p.s * x ; 
	}
	return p ; 
}
int mx ;
int check( int x , int R ){
	int l = x - R , r = x + R ;
	pair < int , int > cur = get_sum( l , x , x ) ;
	pair < int , int > p = get_sum( x + 1 , r , x ) ;
	cur.f += p.f ; cur.s += p.s ;  
	if( cur.f <= mx ) return cur.s ; 
	int R1 = R - 1 ; 
	 l = x - R1 , r = x + R1 ;
	cur = get_sum( l , x , x ) ;
	p = get_sum( x + 1 , r , x ) ;	
	cur.f += p.f ; cur.s += p.s ; 
	if( cur.f + R > mx ) return -1 ;
	int lf = ( mx - cur.f ) ;
	cur.s = cur.s + ( lf / R ) ; 
	return cur.s ; 	 
}
signed besthub(signed R, signed L, signed X[], long long B){
       int ans = 0 ; mx = B ; 
       FOR( i , R ){
       	se.insert( { X[ i ] , i } ) ; 
       	 if( i == 0 ){
       	 	sm[ i ] = { X[ i ] , 1 } ; 
       	 	continue ; 
		 }
		 sm[ i ] = sm[ i - 1 ] ;
		 sm[ i ].f += X[ i ] ;
		 sm[ i ].s += 1 ; 
	   }
       FOR( i , R ){
       	  int x = X[ i ] ;
       	  int l = 0 , r = L ;
       	  while( l <= r ){
       	    int mid = ( l + r ) / 2 ;
			int y = check( x , mid ) ;
			if( y == -1 ){
				r = mid - 1 ; 
				continue ; 
			} 	
			ans = max( ans , y ) ;
			l = mid + 1 ; 
		  }
	   }
       return ans ; 
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...