답안 #682065

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
682065 2023-01-15T14:43:58 Z YENGOYAN 금 캐기 (IZhO14_divide) C++17
17 / 100
2 ms 340 KB
/*
    //\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\\
    \\                                    //
    //  271828___182845__904523__53602__  \\
    \\  87___47____13______52____66__24_  //
    //  97___75____72______47____09___36  \\
    \\  999595_____74______96____69___67  //
    //  62___77____24______07____66__30_  \\
    \\  35___35____47______59____45713__  //
    //                                    \\
    \\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\//
                                                */

#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <cmath>
#include <climits>
#include <algorithm>
#include <random>
#include <queue>
#include <deque>
#include <iomanip>
#include <string>
#include <tuple>
#include <bitset>
#include <chrono>
#include <ctime>
#include <fstream>
#include <stack>
#include <cstdio>

using namespace std;
using ll = long long;
const int N = 4e5 + 5;
const ll mod = 1e9 + 7, inf = LLONG_MAX;

int s = 1;
vector<ll> seg, vec;

struct camp {
    int x, g, d;
};

void build(int l, int r, int u) {
    if (l == r) {
        if (l < vec.size()) seg[u] = vec[l];
        else seg[u] = -inf;
        return;
    }
    int m = (l + r) / 2;
    build(l, m, 2 * u + 1), build(m + 1, r, 2 * u + 2);
    seg[u] = max(seg[2 * u + 1], seg[2 * u + 2]);
}

ll get(int l, int r, int lx, int rx, int u) {
    if (lx >= l && rx <= r) return seg[u];
    if (lx > r || rx < l) return -inf;
    int m = (lx + rx) / 2;
    return max(get(l, r, lx, m, 2 * u + 1), get(l, r, m + 1, rx, 2 * u + 2));
}

void solve() {
    int n; cin >> n;
    vector<camp> v(n);
    for (int i = 0; i < n; ++i) {
        cin >> v[i].x >> v[i].g >> v[i].d;
    }
    vector<ll> pref(n + 1);
    vec = vector<ll>(n + 1);
    for (int i = 1; i <= n; ++i) {
        pref[i] = pref[i - 1] + v[i - 1].d;
        vec[i] = pref[i] - v[i - 1].x;
    }
    while (s <= n) s <<= 1;
    seg = vector<ll>(2 * s);
    vector<ll> pref_en(n + 1), gold(n + 1);
    for (int i = 1; i <= n; ++i) {
        gold[i] = gold[i - 1] + v[i - 1].g;
    }
    build(0, s - 1, 0);
    long long ans = 0;
    for (int i = 1; i <= n; ++i) {
        /*for (int j = i; j <= n; ++j) {
            if (pref[j] - v[j - 1].x >= pref[i - 1] - v[i - 1].x) ans = max(ans, gold[j] - gold[i - 1]);
        }*/
        ll val = pref[i - 1] - v[i - 1].x;
        int l = i, r = n + 1;
        while (l + 1 < r) {
            int m = (l + r) / 2;
            int a = get(m, n, 0, s - 1, 0);
            if (a >= val) l = m;
            else r = m;
        }
        if (vec[l] >= val) ans = max(ans, gold[l] - gold[i - 1]);
    }
    cout << ans;
}

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    //int t; cin >> t;
    //while (t--) 
    solve();
}

Compilation message

divide.cpp: In function 'void build(int, int, int)':
divide.cpp:50:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   50 |         if (l < vec.size()) seg[u] = vec[l];
      |             ~~^~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 2 ms 340 KB Output is correct
18 Incorrect 2 ms 340 KB Output isn't correct
19 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 2 ms 340 KB Output is correct
18 Incorrect 2 ms 340 KB Output isn't correct
19 Halted 0 ms 0 KB -