답안 #307714

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
307714 2020-09-29T07:44:35 Z kartel 금 캐기 (IZhO14_divide) C++14
100 / 100
323 ms 48376 KB
#include <iostream>
#include <stdio.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
#define in(x) freopen(x, "r", stdin)
#define out(x) freopen(x, "w", stdout)
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC optimize("-O3")
#define F first
#define S second
#define pb push_back
#define N +200500
#define M ll(998244353)
#define sz(x) (int)x.size()
#define re return
#define oo ll(1e18)
#define el '\n'
#define pii pair <int, int>
#define all(x) (x).begin(), (x).end()
#define arr_all(x, n) (x + 1), (x + 1 + n)
//#define vi vector <int>
using namespace std;
//using namespace __gnu_pbds;
//typedef tree <int, null_type, less_equal <int> , rb_tree_tag, tree_order_statistics_node_update> ordered_set;
typedef long long ll;
typedef long double ld;

struct tree{
    tree *L, *R;
    ll mn;

    tree () {
        mn = 1e9;
        L = NULL;
        R = NULL;
    }

    void upd(ll l, ll r, ll ps, ll val)
    {
        if (l == r)
            mn = val;
        else
        {
            ll md = (l + r) / 2ll;

            if (ps <= md)
            {
                if (L == NULL)
                    L = new tree();

                L -> upd(l, md, ps, val);
            }
            else
            {
                if (R == NULL)
                    R = new tree();

                R -> upd(md + 1, r, ps, val);
            }

            mn = 1e9;

            if (L != NULL) mn = min(mn, L -> mn);
            if (R != NULL) mn = min(mn, R -> mn);
        }
    }

    ll get(ll l, ll r, ll tl, ll tr)
    {
        if (l > r || tl > tr || l > tr || tl > r)
            return 1e9;

        if (l == tl && r == tr)
            return mn;

        ll md = (l + r) / 2ll;
        ll cur_0 = 1e9;
        ll cur_1 = 1e9;

        if (L != NULL)
            cur_0 = L -> get(l, md, tl, min(md, tr));

        if (R != NULL)
            cur_1 = R -> get(md + 1, r, max(md + 1, tl), tr);

        return min(cur_0, cur_1);
    }
};

tree t;
int i, n, x, g, e;
ll pf[N], pr, ans;

int main()
{
//    ios_base::sync_with_stdio(0);
//    cin.tie(NULL);
//    in("divide.in");
//    out("divide.out");
//    in("input.txt");
//    out("output.txt");

    cin >> n;

    // pr[i] - pr[j - 1] >= x[i] - x[j]
    // pr[i] - x[i] >= pr[j - 1] - x[j]

    for (i = 1; i <= n; i++)
    {
        ll prr = pr;
        cin >> x >> g >> e;

        pr += e;
        pf[i] = pf[i - 1] + g;

        int j = t.get(0, 2e9, 0, 1e9 + pr - x);

        if (j == 1e9)
            j = i;

        ans = max(ans, pf[i] - pf[j - 1]);

        t.upd(0, 2e9, 1e9 + prr - x, i);
    }

    cout << ans;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 256 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 256 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 2 ms 384 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 2 ms 640 KB Output is correct
16 Correct 3 ms 768 KB Output is correct
17 Correct 4 ms 896 KB Output is correct
18 Correct 4 ms 384 KB Output is correct
19 Correct 4 ms 1024 KB Output is correct
20 Correct 3 ms 1024 KB Output is correct
21 Correct 4 ms 768 KB Output is correct
22 Correct 6 ms 1024 KB Output is correct
23 Correct 17 ms 3456 KB Output is correct
24 Correct 18 ms 3448 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 256 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 2 ms 384 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 2 ms 640 KB Output is correct
16 Correct 3 ms 768 KB Output is correct
17 Correct 4 ms 896 KB Output is correct
18 Correct 4 ms 384 KB Output is correct
19 Correct 4 ms 1024 KB Output is correct
20 Correct 3 ms 1024 KB Output is correct
21 Correct 4 ms 768 KB Output is correct
22 Correct 6 ms 1024 KB Output is correct
23 Correct 17 ms 3456 KB Output is correct
24 Correct 18 ms 3448 KB Output is correct
25 Correct 11 ms 1920 KB Output is correct
26 Correct 24 ms 3712 KB Output is correct
27 Correct 25 ms 2176 KB Output is correct
28 Correct 116 ms 3064 KB Output is correct
29 Correct 137 ms 3368 KB Output is correct
30 Correct 286 ms 4088 KB Output is correct
31 Correct 209 ms 4088 KB Output is correct
32 Correct 213 ms 4216 KB Output is correct
33 Correct 255 ms 33912 KB Output is correct
34 Correct 247 ms 22384 KB Output is correct
35 Correct 308 ms 48376 KB Output is correct
36 Correct 323 ms 47944 KB Output is correct