Submission #1350045

#TimeUsernameProblemLanguageResultExecution timeMemory
1350045bakhtiyarnRice Hub (IOI11_ricehub)C++20
Compilation error
0 ms0 KiB
#include "ricehub.h"
using namespace std;
#define int long long

const int N = 3e5+5;
int x[N], pre[N];
int R, L, B; 

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

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

int CNT(int p){
  if(p < 1 or p > L) return 0;
  // cout << p << endl;
  
  int l = 1, r = R, ans = 0;
  while(l <= r){
    int mid = (l+r)/2;
    
    int sayl = cnt_ara(p-mid+1, p);
    int sayr = cnt_ara(p+1, p+mid-1);
    
    int sml = sm_ara(p-mid+1, p);
    int smr = sm_ara(p+1, p+mid-1);
    
    int add = cnt_ara(p-mid, p-mid) + cnt_ara(p+mid, p+mid);
    
    int 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(int i=1; i<=n; i++) 
int besthub(int R, int L, int X[], int B){
  for(int i=1; i<=R; i++) x[i] = X[i-1], pre[i] = pre[i-1] + x[i];
  
  // cout << CNT(9) << endl;
  // return;
  
  int ans = 0;
  for(int i=1; i<=R; i++) ans = max(ans, CNT(x[i]-1));
  for(int 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: In function 'long long int sm_ara(long long int, long long int)':
ricehub.cpp:10:14: error: 'lower_bound' was not declared in this scope
   10 |   auto it1 = lower_bound(x+1, x+R+1, l);
      |              ^~~~~~~~~~~
ricehub.cpp:11:14: error: 'upper_bound' was not declared in this scope
   11 |   auto it2 = upper_bound(x+1, x+R+1, r); it2--;
      |              ^~~~~~~~~~~
ricehub.cpp: In function 'long long int cnt_ara(long long int, long long int)':
ricehub.cpp:19:14: error: 'lower_bound' was not declared in this scope
   19 |   auto it1 = lower_bound(x+1, x+R+1, l);
      |              ^~~~~~~~~~~
ricehub.cpp:20:14: error: 'upper_bound' was not declared in this scope
   20 |   auto it2 = upper_bound(x+1, x+R+1, r);
      |              ^~~~~~~~~~~
ricehub.cpp: In function 'long long int CNT(long long int)':
ricehub.cpp:45:13: error: 'min' was not declared in this scope; did you mean 'mid'?
   45 |       add = min(add, (B-sm)/mid);
      |             ^~~
      |             mid
ricehub.cpp: In function 'long long int besthub(long long int, long long int, long long int*, long long int)':
ricehub.cpp:64:33: error: 'max' was not declared in this scope
   64 |   for(int i=1; i<=R; i++) ans = max(ans, CNT(x[i]-1));
      |                                 ^~~
ricehub.cpp:65:33: error: 'max' was not declared in this scope
   65 |   for(int i=1; i<=R; i++) ans = max(ans, CNT(x[i]+1));
      |                                 ^~~