답안 #1035930

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1035930 2024-07-26T19:41:07 Z pera 금 캐기 (IZhO14_divide) C++17
0 / 100
4 ms 5872 KB
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int N = 1e5 + 1;
int n , ans = 0 , SZ;
vector<int> x(N) , g(N) , e(N) , sum_e(N) , sum_g(N) , h(N) , t(N);
void upd(int u , int x){
   assert(u <= SZ);
   while(u <= SZ){
      t[u] = min(t[u] , x);
      u += u&-u;
   }
}
int GET(int u){
   assert(u <= SZ);
   int val = 1e18;
   while(u > 0){
      val = min(val , t[u]);
      u -= u&-u;
   }
   return val;
}
void solve(int l , int r){
   if(l > r){
      return;
   }
   SZ = r - l + 1;
   int m = (l + r) / 2;
   for(int i = l;i <= r;i ++){
      sum_e[i] = sum_e[i - 1] + e[i];
      sum_g[i] = sum_g[i - 1] + g[i];
   }
   vector<pair<int , int>> v , u;
   for(int i = l;i <= r;i ++){
      if(i < m){
         v.push_back({x[i - 1] - sum_e[i - 1] , i});
         u.push_back({sum_e[i - 1] - x[i] , i});
      }else{
         v.push_back({x[i + 1] - sum_e[i] , i});
         u.push_back({sum_e[i] - x[i] , i});
      }
   }
   sort(v.begin() , v.end());
   sort(u.begin() , u.end());
   for(int i = 0;i < (int)u.size();i ++){
      h[u[i].second] = (i == 0 ? 1 : h[u[i - 1].second] + (u[i].first != u[i - 1].first));
   }
   int mn = 1e15;
   for(auto [_value , id] : u){
      //cout << id << " " << h[id] << " " << sum_g[id - 1] << endl;
      if(id < m){
         mn = min(mn , h[id - 1]);
      }else{
         ans = max(ans , sum_g[id] - mn);
         if(x[id + 1] - x[m - 1] >= sum_e[id] - sum_e[m - 1] && sum_e[id] - sum_e[m - 1] > x[id] - x[m]){
            ans = max(ans , sum_g[id] - sum_g[m - 1]);
         }
      }
   }
  // cout << endl;
   for(int i = l;i <= r;i ++){
      sum_e[i] = sum_g[i] = h[i] = 0;
   }
   //cout << l << " " << m << " " << r << " " << mx << endl;
   solve(l , m - 1);
   solve(m + 1 , r);
}
main(){
   cin >> n;
   for(int i = 1;i <= n;i ++){
      cin >> x[i] >> g[i] >> e[i];
      t[i] = 1e18;
   }
   x[n + 1] = 1e10;
   x[0] = -1e9;
   solve(1 , n);
   /*for(int L = 1;L <= n;L ++){
      for(int R = L;R <= n;R ++){
         int s = 0 , se = 0;
         for(int i = L;i <= R;i ++){
            se += e[i];
            s += g[i];
         }
         if(x[R + 1] - x[L - 1] >= se && se > x[R] - x[L]){
            ans = max(ans , s);
         }
      }
   }*/
   cout << ans << endl;
}

Compilation message

divide.cpp:68:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   68 | main(){
      | ^~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 5724 KB Output is correct
2 Incorrect 2 ms 5872 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 5724 KB Output is correct
2 Incorrect 2 ms 5872 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 5724 KB Output is correct
2 Incorrect 2 ms 5872 KB Output isn't correct
3 Halted 0 ms 0 KB -