Submission #643885

# Submission time Handle Problem Language Result Execution time Memory
643885 2022-09-23T07:49:44 Z ghostwriter Divide and conquer (IZhO14_divide) C++14
48 / 100
50 ms 6308 KB
#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#include <debug.h>
#endif
#define ft front
#define bk back
#define st first
#define nd second
#define ins insert
#define ers erase
#define pb push_back
#define pf push_front
#define _pb pop_back
#define _pf pop_front
#define lb lower_bound
#define ub upper_bound
#define mtp make_tuple
#define bg begin
#define ed end
#define all(x) (x).bg(), (x).ed()
#define sz(x) (int)(x).size()
typedef long long ll; typedef unsigned long long ull;
typedef double db; typedef long double ldb;
typedef pair<int, int> pi; typedef pair<ll, ll> pll;
typedef vector<int> vi; typedef vector<ll> vll; typedef vector<pi> vpi; typedef vector<pll> vpll;
typedef string str;
template<typename T> T gcd(T a, T b) { return (b == 0? a : gcd(b, a % b)); }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }
#define FOR(i, l, r) for (int (i) = (l); (i) <= (r); ++(i))
#define FOS(i, r, l) for (int (i) = (r); (i) >= (l); --(i))
#define EACH(i, x) for (auto &(i) : (x))
#define WHILE while
#define file "TEST"
mt19937 rd(chrono::steady_clock::now().time_since_epoch().count());
ll rand(ll l, ll r) { return uniform_int_distribution<ll>(l, r)(rd); }
/*
    Tran The Bao
    VOI23 gold medal
*/
const ll oo = 1e18;
const int N = 1e5 + 5;
int n, x[N], g[N], d[N];
ll f[N], s[N], f1[N], rs = -oo;
vll v;
int getpos(ll x) { return lb(all(v), x) - v.bg(); }
void upd(int pos, ll v) { for (int i = pos; i >= 1; i -= (i & -i)) f1[i] = min(f1[i], v); }
ll get(int pos) { ll rs = oo; for (int i = pos; i < sz(v); i += (i & -i)) rs = min(rs, f1[i]); return rs; }
signed main() {
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    // freopen(file".inp", "r", stdin);
    // freopen(file".out", "w", stdout);
    cin >> n;
    FOR(i, 1, n) cin >> x[i] >> g[i] >> d[i];
    FOR(i, 1, n) {
    	f[i] = f[i - 1] + d[i];
    	s[i] = s[i - 1] + g[i];
    	v.pb(-f[i] + x[i]);
    	v.pb(-f[i - 1] + x[i]);
    }
    v.pb(-oo);
    sort(all(v));
    FOR(i, 1, sz(v) - 1) f1[i] = oo;
    FOR(i, 1, n) {
    	int pos = getpos(-f[i - 1] + x[i]);
    	upd(pos, s[i - 1]);
    	pos = getpos(-f[i] + x[i]);
    	rs = max(rs, s[i] - get(pos));
    }
    cout << rs;
    return 0;
}
/*
2
0 4 1
3 5 1
*/
/*
From Benq:
    stuff you should look for
        * int overflow, array bounds
        * special cases (n=1?)
        * do smth instead of nothing and stay organized
        * WRITE STUFF DOWN
        * DON'T GET STUCK ON ONE APPROACH
*/

Compilation message

divide.cpp: In function 'int main()':
divide.cpp:30:31: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   30 | #define FOR(i, l, r) for (int (i) = (l); (i) <= (r); ++(i))
      |                               ^
divide.cpp:54:5: note: in expansion of macro 'FOR'
   54 |     FOR(i, 1, n) cin >> x[i] >> g[i] >> d[i];
      |     ^~~
divide.cpp:30:31: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   30 | #define FOR(i, l, r) for (int (i) = (l); (i) <= (r); ++(i))
      |                               ^
divide.cpp:55:5: note: in expansion of macro 'FOR'
   55 |     FOR(i, 1, n) {
      |     ^~~
divide.cpp:30:31: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   30 | #define FOR(i, l, r) for (int (i) = (l); (i) <= (r); ++(i))
      |                               ^
divide.cpp:63:5: note: in expansion of macro 'FOR'
   63 |     FOR(i, 1, sz(v) - 1) f1[i] = oo;
      |     ^~~
divide.cpp:30:31: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   30 | #define FOR(i, l, r) for (int (i) = (l); (i) <= (r); ++(i))
      |                               ^
divide.cpp:64:5: note: in expansion of macro 'FOR'
   64 |     FOR(i, 1, n) {
      |     ^~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 0 ms 332 KB Output is correct
12 Correct 1 ms 328 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 0 ms 332 KB Output is correct
12 Correct 1 ms 328 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 0 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 468 KB Output is correct
19 Correct 1 ms 468 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 468 KB Output is correct
22 Correct 2 ms 468 KB Output is correct
23 Correct 4 ms 836 KB Output is correct
24 Correct 3 ms 852 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 0 ms 332 KB Output is correct
12 Correct 1 ms 328 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 0 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 468 KB Output is correct
19 Correct 1 ms 468 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 468 KB Output is correct
22 Correct 2 ms 468 KB Output is correct
23 Correct 4 ms 836 KB Output is correct
24 Correct 3 ms 852 KB Output is correct
25 Correct 2 ms 796 KB Output is correct
26 Correct 5 ms 1112 KB Output is correct
27 Correct 5 ms 1240 KB Output is correct
28 Correct 22 ms 4168 KB Output is correct
29 Correct 26 ms 4096 KB Output is correct
30 Incorrect 50 ms 6308 KB Output isn't correct
31 Halted 0 ms 0 KB -