Submission #1350048

#TimeUsernameProblemLanguageResultExecution timeMemory
1350048bakhtiyarnRice Hub (IOI11_ricehub)C++20
Compilation error
0 ms0 KiB
#include <bits/stdc++.h>
#include "ricehub.h"
using namespace std;

#define ll long long;
const ll N = 3e5+5;
ll x[N], pre[N];
ll R, L, B; 

ll sm_ara(ll l, ll r){
  auto it1 = lower_bound(x+1, x+R+1, l);
  auto it2 = upper_bound(x+1, x+R+1, r); it2--;
  
  ll idx1 = it1 - x;
  ll idx2 = it2 - x;
  return pre[idx2] - pre[idx1-1];
}

ll cnt_ara(ll l, ll r){
  auto it1 = lower_bound(x+1, x+R+1, l);
  auto it2 = upper_bound(x+1, x+R+1, r);
  return it2-it1;
}

ll CNT(ll p){
  if(p < 1 or p > L) return 0;
  // cout << p << endl;
  
  ll l = 1, r = R, ans = 0;
  while(l <= r){
    ll mid = (l+r)/2;
    
    ll sayl = cnt_ara(p-mid+1, p);
    ll sayr = cnt_ara(p+1, p+mid-1);
    
    ll sml = sm_ara(p-mid+1, p);
    ll smr = sm_ara(p+1, p+mid-1);
    
    ll add = cnt_ara(p-mid, p-mid) + cnt_ara(p+mid, p+mid);
    
    ll sm = 0;
    sm += smr - sayr * p;
    sm += sayl * p - sml;
    
    if(sm <= B){
      add = min(add, (B-sm)/mid);
    }
    sm += add * mid;
    
    if(sm <= B) ans = sayl + sayr + add, l = mid+1;
    else r = mid-1;
  }
  
  return ans;
}

// for(ll i=1; i<=n; i++) 
ll besthub(ll R, ll L, ll X[], ll B){
  for(ll i=1; i<=R; i++) x[i] = X[i-1], pre[i] = pre[i-1] + x[i];
  
  // cout << CNT(9) << endl;
  // return;
  
  ll ans = 0;
  for(ll i=1; i<=R; i++) ans = max(ans, CNT(x[i]-1));
  for(ll i=1; i<=R; i++) ans = max(ans, CNT(x[i]+1));
  return ans;
}

// signed main() {
//   ios_base::sync_with_stdio(0);
//   cin.tie(0);
//   cout.tie(0);
//   solve();
// }

Compilation message (stderr)

ricehub.cpp:5:17: error: declaration does not declare anything [-fpermissive]
    5 | #define ll long long;
      |                 ^~~~
ricehub.cpp:6:7: note: in expansion of macro 'll'
    6 | const ll N = 3e5+5;
      |       ^~
ricehub.cpp:6:10: error: 'N' does not name a type
    6 | const ll N = 3e5+5;
      |          ^
ricehub.cpp:5:17: error: declaration does not declare anything [-fpermissive]
    5 | #define ll long long;
      |                 ^~~~
ricehub.cpp:7:1: note: in expansion of macro 'll'
    7 | ll x[N], pre[N];
      | ^~
ricehub.cpp:7:4: error: 'x' does not name a type
    7 | ll x[N], pre[N];
      |    ^
ricehub.cpp:5:17: error: declaration does not declare anything [-fpermissive]
    5 | #define ll long long;
      |                 ^~~~
ricehub.cpp:8:1: note: in expansion of macro 'll'
    8 | ll R, L, B;
      | ^~
ricehub.cpp:8:4: error: 'R' does not name a type
    8 | ll R, L, B;
      |    ^
ricehub.cpp:5:17: error: declaration does not declare anything [-fpermissive]
    5 | #define ll long long;
      |                 ^~~~
ricehub.cpp:10:1: note: in expansion of macro 'll'
   10 | ll sm_ara(ll l, ll r){
      | ^~
ricehub.cpp:5:21: error: expected ')' before ';' token
    5 | #define ll long long;
      |                     ^
ricehub.cpp:10:11: note: in expansion of macro 'll'
   10 | ll sm_ara(ll l, ll r){
      |           ^~
ricehub.cpp:10:10: note: to match this '('
   10 | ll sm_ara(ll l, ll r){
      |          ^
ricehub.cpp:5:21: error: expected constructor, destructor, or type conversion before ';' token
    5 | #define ll long long;
      |                     ^
ricehub.cpp:10:11: note: in expansion of macro 'll'
   10 | ll sm_ara(ll l, ll r){
      |           ^~
ricehub.cpp:10:14: error: 'l' does not name a type; did you mean 'll'?
   10 | ll sm_ara(ll l, ll r){
      |              ^
      |              ll
ricehub.cpp:10:20: error: 'r' does not name a type
   10 | ll sm_ara(ll l, ll r){
      |                    ^
ricehub.cpp:5:17: error: declaration does not declare anything [-fpermissive]
    5 | #define ll long long;
      |                 ^~~~
ricehub.cpp:19:1: note: in expansion of macro 'll'
   19 | ll cnt_ara(ll l, ll r){
      | ^~
ricehub.cpp:5:21: error: expected ')' before ';' token
    5 | #define ll long long;
      |                     ^
ricehub.cpp:19:12: note: in expansion of macro 'll'
   19 | ll cnt_ara(ll l, ll r){
      |            ^~
ricehub.cpp:19:11: note: to match this '('
   19 | ll cnt_ara(ll l, ll r){
      |           ^
ricehub.cpp:5:21: error: expected constructor, destructor, or type conversion before ';' token
    5 | #define ll long long;
      |                     ^
ricehub.cpp:19:12: note: in expansion of macro 'll'
   19 | ll cnt_ara(ll l, ll r){
      |            ^~
ricehub.cpp:19:15: error: 'l' does not name a type; did you mean 'll'?
   19 | ll cnt_ara(ll l, ll r){
      |               ^
      |               ll
ricehub.cpp:19:21: error: 'r' does not name a type
   19 | ll cnt_ara(ll l, ll r){
      |                     ^
ricehub.cpp:5:17: error: declaration does not declare anything [-fpermissive]
    5 | #define ll long long;
      |                 ^~~~
ricehub.cpp:25:1: note: in expansion of macro 'll'
   25 | ll CNT(ll p){
      | ^~
ricehub.cpp:5:21: error: expected ')' before ';' token
    5 | #define ll long long;
      |                     ^
ricehub.cpp:25:8: note: in expansion of macro 'll'
   25 | ll CNT(ll p){
      |        ^~
ricehub.cpp:25:7: note: to match this '('
   25 | ll CNT(ll p){
      |       ^
ricehub.cpp:5:21: error: expected constructor, destructor, or type conversion before ';' token
    5 | #define ll long long;
      |                     ^
ricehub.cpp:25:8: note: in expansion of macro 'll'
   25 | ll CNT(ll p){
      |        ^~
ricehub.cpp:25:11: error: 'p' does not name a type
   25 | ll CNT(ll p){
      |           ^
ricehub.cpp:5:17: error: declaration does not declare anything [-fpermissive]
    5 | #define ll long long;
      |                 ^~~~
ricehub.cpp:58:1: note: in expansion of macro 'll'
   58 | ll besthub(ll R, ll L, ll X[], ll B){
      | ^~
ricehub.cpp:5:21: error: expected ')' before ';' token
    5 | #define ll long long;
      |                     ^
ricehub.cpp:58:12: note: in expansion of macro 'll'
   58 | ll besthub(ll R, ll L, ll X[], ll B){
      |            ^~
ricehub.cpp:58:11: note: to match this '('
   58 | ll besthub(ll R, ll L, ll X[], ll B){
      |           ^
ricehub.cpp:5:21: error: expected constructor, destructor, or type conversion before ';' token
    5 | #define ll long long;
      |                     ^
ricehub.cpp:58:12: note: in expansion of macro 'll'
   58 | ll besthub(ll R, ll L, ll X[], ll B){
      |            ^~
ricehub.cpp:58:15: error: 'R' does not name a type
   58 | ll besthub(ll R, ll L, ll X[], ll B){
      |               ^
ricehub.cpp:58:21: error: 'L' does not name a type
   58 | ll besthub(ll R, ll L, ll X[], ll B){
      |                     ^
ricehub.cpp:58:27: error: 'X' does not name a type
   58 | ll besthub(ll R, ll L, ll X[], ll B){
      |                           ^
ricehub.cpp:58:35: error: 'B' does not name a type
   58 | ll besthub(ll R, ll L, ll X[], ll B){
      |                                   ^