답안 #341519

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
341519 2020-12-29T22:21:07 Z Sprdalo 금 캐기 (IZhO14_divide) C++17
100 / 100
50 ms 12396 KB
#include <bits/stdc++.h>

using namespace std;

#define int ll
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<double> vd;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<pi> vp;
typedef vector<pl> vpl;

struct st{
    int x;
    int g;
    int d;
};

vi p, t;

template<int maxn>
struct segtree{
    struct node{
        int x, ind;

        node(int x = INT32_MIN, int ind = 0) : x(x), ind(ind) {}

        node& operator+= (const node& other){
            if (x < other.x){
                x = other.x;
                ind = other.ind;
            }
            return *this;
        }

        node operator+(const node& other){
            auto tmp = *this;
            return tmp += other;
        }
    };

    node a[2*maxn];

    void init(){
        int n = t.size();

        for (int i = 1; i <= maxn; ++i)
            a[i+maxn-1] = node{INT32_MIN, i};

        for (int i = 1; i < n; ++i)
            a[i+maxn-1] = node{t[i], i};

        for (int i = maxn-1; i > 0; --i)
            a[i] = a[2*i] + a[2*i+1];
    }

    node get(int x, int pos = 1, int l = 1, int r = maxn){
        if (a[pos].x < x) return node{0, -1};
        if (pos >= maxn) return a[pos];

        int mid = (l+r)/2;
        auto tmp = get(x, 2*pos+1, mid+1, r);

        if (!tmp.x && tmp.ind == -1)
            tmp = get(x, 2*pos, l, mid);

        return tmp;
    }
};

segtree<131072> drvo;

signed main()
{
    ios_base::sync_with_stdio(false); 
    cin.tie(nullptr); 
    cout.tie(nullptr); 
    cerr.tie(nullptr);    

    int n, sol = 0;
    cin >> n;

    vector<st> a(n+1);
    for (int i = 1; i <= n; ++i){
        cin >> a[i].x >> a[i].g >> a[i].d;

        if (a[i].d >= 1)
            sol = max(sol, a[i].g);
    }

    p = vi(n+1); t = vi(n+1);
    vi d = {0};
    for (int i = 1; i <= n; ++i){
        p[i] = p[i-1] + a[i].g;
        d.push_back(d.back() + a[i].d);
        t[i] = d[i] - a[i].x;
    }
    drvo.init();

    for (int i = 1; i <= n; ++i){
        auto k = drvo.get(d[i-1]-a[i].x);

        sol = max(sol, p[k.ind] - p[i-1]);
    }

    cout << sol << '\n';
}
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4460 KB Output is correct
2 Correct 3 ms 4460 KB Output is correct
3 Correct 3 ms 4460 KB Output is correct
4 Correct 3 ms 4460 KB Output is correct
5 Correct 3 ms 4460 KB Output is correct
6 Correct 4 ms 4460 KB Output is correct
7 Correct 3 ms 4460 KB Output is correct
8 Correct 4 ms 4388 KB Output is correct
9 Correct 3 ms 4460 KB Output is correct
10 Correct 3 ms 4460 KB Output is correct
11 Correct 3 ms 4460 KB Output is correct
12 Correct 3 ms 4480 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4460 KB Output is correct
2 Correct 3 ms 4460 KB Output is correct
3 Correct 3 ms 4460 KB Output is correct
4 Correct 3 ms 4460 KB Output is correct
5 Correct 3 ms 4460 KB Output is correct
6 Correct 4 ms 4460 KB Output is correct
7 Correct 3 ms 4460 KB Output is correct
8 Correct 4 ms 4388 KB Output is correct
9 Correct 3 ms 4460 KB Output is correct
10 Correct 3 ms 4460 KB Output is correct
11 Correct 3 ms 4460 KB Output is correct
12 Correct 3 ms 4480 KB Output is correct
13 Correct 3 ms 4460 KB Output is correct
14 Correct 4 ms 4460 KB Output is correct
15 Correct 4 ms 4460 KB Output is correct
16 Correct 4 ms 4460 KB Output is correct
17 Correct 4 ms 4460 KB Output is correct
18 Correct 4 ms 4588 KB Output is correct
19 Correct 4 ms 4460 KB Output is correct
20 Correct 4 ms 4460 KB Output is correct
21 Correct 4 ms 4588 KB Output is correct
22 Correct 4 ms 4608 KB Output is correct
23 Correct 6 ms 4972 KB Output is correct
24 Correct 6 ms 4844 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4460 KB Output is correct
2 Correct 3 ms 4460 KB Output is correct
3 Correct 3 ms 4460 KB Output is correct
4 Correct 3 ms 4460 KB Output is correct
5 Correct 3 ms 4460 KB Output is correct
6 Correct 4 ms 4460 KB Output is correct
7 Correct 3 ms 4460 KB Output is correct
8 Correct 4 ms 4388 KB Output is correct
9 Correct 3 ms 4460 KB Output is correct
10 Correct 3 ms 4460 KB Output is correct
11 Correct 3 ms 4460 KB Output is correct
12 Correct 3 ms 4480 KB Output is correct
13 Correct 3 ms 4460 KB Output is correct
14 Correct 4 ms 4460 KB Output is correct
15 Correct 4 ms 4460 KB Output is correct
16 Correct 4 ms 4460 KB Output is correct
17 Correct 4 ms 4460 KB Output is correct
18 Correct 4 ms 4588 KB Output is correct
19 Correct 4 ms 4460 KB Output is correct
20 Correct 4 ms 4460 KB Output is correct
21 Correct 4 ms 4588 KB Output is correct
22 Correct 4 ms 4608 KB Output is correct
23 Correct 6 ms 4972 KB Output is correct
24 Correct 6 ms 4844 KB Output is correct
25 Correct 5 ms 4844 KB Output is correct
26 Correct 7 ms 5100 KB Output is correct
27 Correct 7 ms 5228 KB Output is correct
28 Correct 24 ms 7812 KB Output is correct
29 Correct 25 ms 8304 KB Output is correct
30 Correct 47 ms 12396 KB Output is correct
31 Correct 42 ms 11244 KB Output is correct
32 Correct 43 ms 11372 KB Output is correct
33 Correct 43 ms 11116 KB Output is correct
34 Correct 44 ms 11116 KB Output is correct
35 Correct 47 ms 11628 KB Output is correct
36 Correct 50 ms 11884 KB Output is correct