Submission #776765

# Submission time Handle Problem Language Result Execution time Memory
776765 2023-07-08T08:47:36 Z lollipop Rice Hub (IOI11_ricehub) C++17
68 / 100
1000 ms 8512 KB
#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 time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 2 ms 340 KB Output is correct
28 Correct 2 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 2 ms 340 KB Output is correct
4 Correct 3 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 2 ms 340 KB Output is correct
8 Correct 2 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 2 ms 340 KB Output is correct
12 Correct 3 ms 376 KB Output is correct
13 Correct 3 ms 340 KB Output is correct
14 Correct 3 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 2 ms 340 KB Output is correct
19 Correct 2 ms 340 KB Output is correct
20 Correct 4 ms 396 KB Output is correct
21 Correct 11 ms 716 KB Output is correct
22 Correct 11 ms 724 KB Output is correct
23 Correct 9 ms 724 KB Output is correct
24 Correct 15 ms 720 KB Output is correct
25 Correct 18 ms 596 KB Output is correct
26 Correct 23 ms 724 KB Output is correct
27 Correct 24 ms 596 KB Output is correct
28 Correct 24 ms 716 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 141 ms 1932 KB Output is correct
2 Correct 143 ms 1940 KB Output is correct
3 Correct 699 ms 8512 KB Output is correct
4 Execution timed out 1060 ms 8508 KB Time limit exceeded
5 Halted 0 ms 0 KB -