Submission #654501

# Submission time Handle Problem Language Result Execution time Memory
654501 2022-10-31T13:58:58 Z pauloamed Divide and conquer (IZhO14_divide) C++14
Compilation error
0 ms 0 KB
#include<bits/stdc++.h>
using namespace std;

#define int long long

const int MAXN = 100000;

struct BIT{
  int n; vector<int> v;
  BIT(int m = 0):n(m + 2), v(vector<int>(n, LLONG_MAX){}

  int query(int i){ int ans = LLONG_MAX;
    for(i++; i > 0; i -= i & (-i))
      ans = min(ans, v[i]);
    return ans;
  }

  void update(int i, int val){
    for(i++; i < n; i += i & (-i)) 
      v[i] = min(val, v[i]);
  }
};

BIT bit(MAXN);

int X[MAXN], G[MAXN], E[MAXN];

int idx(vector<int> &v, int x){
  int n = v.size();
  int id = lower_bound(v.begin(), v.end(), x) - v.begin();
  return n - 1 - id;
}

int32_t main(){
  int n; cin >> n;
  vector<int> vals;

  {
    int e_accu = 0;
    for(int i = 0; i < n; ++i){
      cin >> X[i] >> G[i] >> E[i];
      e_accu += E[i];
      int I = X[i] - e_accu;
      vals.push_back(I);
    }
  }

  vals.push_back(0);
  sort(vals.begin(), vals.end());
  vals.erase(unique(vals.begin(), vals.end()), vals.end());


  int e_accu = 0;
  int g_accu = 0;

  bit.update(idx(vals, 0), 0);

  int ans = 0;
  for(int i = 0; i < n; ++i){
    e_accu += E[i];
    g_accu += G[i];

    int Ival = X[i] - e_accu;
    int I = idx(vals, Ival);

    // cout << "Ival, I: " << Ival << " " << I << endl;

    int best = bit.query(I);
    bit.update(I, g_accu);

    // cout << "best: " << best << "\n";
    // cout << "g_accu: " << g_accu << endl;

    ans = max(ans, g_accu - best);
    ans = max(ans, G[i]);
  }
  cout << ans << "\n";
}

Compilation message

divide.cpp:24:9: error: 'MAXN' is not a type
   24 | BIT bit(MAXN);
      |         ^~~~
divide.cpp:78:1: error: expected '}' at end of input
   78 | }
      | ^
divide.cpp:8:11: note: to match this '{'
    8 | struct BIT{
      |           ^
divide.cpp: In constructor 'BIT::BIT(long long int)':
divide.cpp:10:55: error: expected ')' before '{' token
   10 |   BIT(int m = 0):n(m + 2), v(vector<int>(n, LLONG_MAX){}
      |                             ~                         ^
      |                                                       )
divide.cpp:22:1: error: expected '{' before '}' token
   22 | };
      | ^
divide.cpp: In member function 'int32_t BIT::main()':
divide.cpp:56:3: error: invalid use of member function 'BIT BIT::bit(int)' (did you forget the '()' ?)
   56 |   bit.update(idx(vals, 0), 0);
      |   ^~~
divide.cpp:68:16: error: invalid use of member function 'BIT BIT::bit(int)' (did you forget the '()' ?)
   68 |     int best = bit.query(I);
      |                ^~~
divide.cpp:69:5: error: invalid use of member function 'BIT BIT::bit(int)' (did you forget the '()' ?)
   69 |     bit.update(I, g_accu);
      |     ^~~
divide.cpp:64:9: warning: unused variable 'I' [-Wunused-variable]
   64 |     int I = idx(vals, Ival);
      |         ^
divide.cpp:78:1: warning: no return statement in function returning non-void [-Wreturn-type]
   78 | }
      | ^
divide.cpp: At global scope:
divide.cpp:78:1: error: expected unqualified-id at end of input