Submission #654514

# Submission time Handle Problem Language Result Execution time Memory
654514 2022-10-31T14:43:06 Z pauloamed Divide and conquer (IZhO14_divide) C++14
100 / 100
140 ms 8124 KB
#include<bits/stdc++.h>
using namespace std;

#define int long long

const int MAXN = 200010;

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;
}

int idx(int v[], int i){
  if(i < 0) return 0;
  else return v[i];
}

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]; 
    if(i) E[i] += E[i - 1];
    if(i) G[i] += G[i - 1];

    int Iq = X[i] - E[i];
    int Iu = X[i] - idx(E, i - 1);

    vals.push_back(Iq);
    vals.push_back(Iu);
  }

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

  int ans = 0;
  for(int i = 0; i < n; ++i){
    int Iq = X[i] - E[i];
    int Iu = X[i] - idx(E, i - 1);

    Iq = idx(vals, Iq);
    Iu = idx(vals, Iu);

    bit.update(Iu, idx(G, i - 1));
    int best = bit.query(Iq);


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

Compilation message

divide.cpp: In function 'int32_t main()':
divide.cpp:43:7: warning: unused variable 'e_accu' [-Wunused-variable]
   43 |   int e_accu = 0;
      |       ^~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1876 KB Output is correct
2 Correct 1 ms 1876 KB Output is correct
3 Correct 1 ms 1876 KB Output is correct
4 Correct 1 ms 1876 KB Output is correct
5 Correct 1 ms 1876 KB Output is correct
6 Correct 1 ms 1876 KB Output is correct
7 Correct 1 ms 1876 KB Output is correct
8 Correct 1 ms 1876 KB Output is correct
9 Correct 1 ms 1876 KB Output is correct
10 Correct 2 ms 1876 KB Output is correct
11 Correct 1 ms 1876 KB Output is correct
12 Correct 2 ms 1876 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1876 KB Output is correct
2 Correct 1 ms 1876 KB Output is correct
3 Correct 1 ms 1876 KB Output is correct
4 Correct 1 ms 1876 KB Output is correct
5 Correct 1 ms 1876 KB Output is correct
6 Correct 1 ms 1876 KB Output is correct
7 Correct 1 ms 1876 KB Output is correct
8 Correct 1 ms 1876 KB Output is correct
9 Correct 1 ms 1876 KB Output is correct
10 Correct 2 ms 1876 KB Output is correct
11 Correct 1 ms 1876 KB Output is correct
12 Correct 2 ms 1876 KB Output is correct
13 Correct 1 ms 1876 KB Output is correct
14 Correct 1 ms 1876 KB Output is correct
15 Correct 2 ms 1876 KB Output is correct
16 Correct 2 ms 1876 KB Output is correct
17 Correct 2 ms 1876 KB Output is correct
18 Correct 3 ms 1876 KB Output is correct
19 Correct 3 ms 1876 KB Output is correct
20 Correct 2 ms 1876 KB Output is correct
21 Correct 3 ms 1876 KB Output is correct
22 Correct 4 ms 2004 KB Output is correct
23 Correct 6 ms 2196 KB Output is correct
24 Correct 7 ms 2132 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1876 KB Output is correct
2 Correct 1 ms 1876 KB Output is correct
3 Correct 1 ms 1876 KB Output is correct
4 Correct 1 ms 1876 KB Output is correct
5 Correct 1 ms 1876 KB Output is correct
6 Correct 1 ms 1876 KB Output is correct
7 Correct 1 ms 1876 KB Output is correct
8 Correct 1 ms 1876 KB Output is correct
9 Correct 1 ms 1876 KB Output is correct
10 Correct 2 ms 1876 KB Output is correct
11 Correct 1 ms 1876 KB Output is correct
12 Correct 2 ms 1876 KB Output is correct
13 Correct 1 ms 1876 KB Output is correct
14 Correct 1 ms 1876 KB Output is correct
15 Correct 2 ms 1876 KB Output is correct
16 Correct 2 ms 1876 KB Output is correct
17 Correct 2 ms 1876 KB Output is correct
18 Correct 3 ms 1876 KB Output is correct
19 Correct 3 ms 1876 KB Output is correct
20 Correct 2 ms 1876 KB Output is correct
21 Correct 3 ms 1876 KB Output is correct
22 Correct 4 ms 2004 KB Output is correct
23 Correct 6 ms 2196 KB Output is correct
24 Correct 7 ms 2132 KB Output is correct
25 Correct 6 ms 2132 KB Output is correct
26 Correct 11 ms 2388 KB Output is correct
27 Correct 14 ms 2388 KB Output is correct
28 Correct 52 ms 3936 KB Output is correct
29 Correct 67 ms 3876 KB Output is correct
30 Correct 140 ms 5820 KB Output is correct
31 Correct 99 ms 7648 KB Output is correct
32 Correct 106 ms 7704 KB Output is correct
33 Correct 103 ms 7488 KB Output is correct
34 Correct 98 ms 7476 KB Output is correct
35 Correct 138 ms 8020 KB Output is correct
36 Correct 115 ms 8124 KB Output is correct