답안 #90657

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
90657 2018-12-23T09:28:00 Z popovicirobert 금 캐기 (IZhO14_divide) C++14
0 / 100
122 ms 12944 KB
#include <bits/stdc++.h>
#define lsb(x) (x & (-x))
#define ll long long
#define ull unsigned long long
#define ld long double
// 217
// 44

using namespace std;

const int MAXN = (int) 1e5;

int x[MAXN + 1];
ll g[MAXN + 1], d[MAXN + 1];

bool cmp(const int &a, const int &b) {
    if(x[a] - d[a] == x[b] - d[b])
        return a < b;
    return x[a] - d[a] < x[b] - d[b];
}

map <ll, int> mp;

int aint[4 * MAXN + 1];

inline void refresh(int nod) {
    aint[nod] = min(aint[2 * nod], aint[2 * nod + 1]);
}

void update(int nod, int left, int right, int pos, int val) {
    if(left == right) {
        aint[nod] = min(val, aint[nod]);
    }
    else {
        int mid = (left + right) / 2;
        if(pos <= mid) update(2 * nod, left, mid, pos, val);
        else update(2 * nod + 1, mid + 1, right, pos, val);
        refresh(nod);
    }
}

int query(int nod, int left, int right, int l, int r) {
    if(l <= left && right <= r) {
        return aint[nod];
    }
    else {
        int mid = (left + right) / 2;
        int ans = 1e9;
        if(l <= mid) ans = min(ans, query(2 * nod, left, mid, l, r));
        if(mid < r) ans = min(ans, query(2 * nod + 1, mid + 1, right, l, r));
        refresh(nod);
        return ans;
    }
}

int main() {
    //ifstream cin("A.in");
    //ofstream cout("A.out");
    int i, n;
    ios::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);
    cin >> n;
    vector <int> nrm(n + 1);
    iota(nrm.begin(), nrm.end(), 0);
    for(i = 1; i <= n; i++) {
        cin >> x[i] >> g[i] >> d[i];
        d[i] += d[i - 1];
        g[i] += g[i - 1];
    }
    sort(nrm.begin(), nrm.end(), cmp);
    nrm.resize(unique(nrm.begin(), nrm.end()) - nrm.begin());
    int cur = 0;
    for(auto it : nrm) {
        mp[x[it] - d[it]] = ++cur;
    }
    for(i = 1; i <= 4 * cur; i++) {
        aint[i] = n;
    }
    ll ans = 0;
    for(i = 1; i <= n; i++) {
        update(1, 1, cur, mp[x[i - 1] - d[i - 1]], i - 1);
        int pos = query(1, 1, cur, mp[x[i] - d[i]], cur);
        ans = max(ans, g[i] - g[pos]);
        if(1 <= d[i] - d[i - 1]) {
            ans = max(ans, g[i] - g[i - 1]);
        }
    }
    cout << ans;
    //cin.close();
    //cout.close();
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Incorrect 2 ms 448 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 448 KB Output is correct
2 Correct 2 ms 448 KB Output is correct
3 Incorrect 2 ms 604 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 1044 KB Output is correct
2 Correct 9 ms 1748 KB Output is correct
3 Correct 10 ms 1860 KB Output is correct
4 Correct 55 ms 6952 KB Output is correct
5 Correct 59 ms 7880 KB Output is correct
6 Correct 120 ms 12912 KB Output is correct
7 Correct 110 ms 12912 KB Output is correct
8 Correct 112 ms 12912 KB Output is correct
9 Correct 122 ms 12944 KB Output is correct
10 Incorrect 111 ms 12944 KB Output isn't correct
11 Halted 0 ms 0 KB -