Submission #1032208

# Submission time Handle Problem Language Result Execution time Memory
1032208 2024-07-23T13:12:03 Z MongHwa Divide and conquer (IZhO14_divide) C++17
100 / 100
42 ms 8148 KB
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
using namespace std;

#define ll long long

ll x[100005], g[100005], d[100005];
vector<pair<ll, int>> v;

void init(vector<int>& tree, int node, int start, int end)
{
    if(start == end)
        tree[node] = v[start].second;
    else
    {
        init(tree, node*2, start, (start+end)/2);
        init(tree, node*2+1, (start+end)/2+1, end);
        tree[node] = max(tree[node*2], tree[node*2+1]);
    }
}

int query(vector<int>& tree, int node, int start, int end, int left, int right)
{
    if(right < start || left > end)
        return 0;
    if(left <= start && end <= right)
        return tree[node];
    
    int l = query(tree, node*2, start, (start+end)/2, left, right);
    int r = query(tree, node*2+1, (start+end)/2+1, end, left, right);
    return max(l, r);
}

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);

    int n;
    cin >> n;

    for(int i = 1; i <= n; i++)
        cin >> x[i] >> g[i] >> d[i];
    
    for(int i = 1; i <= n; i++)
    {
        g[i] += g[i-1];
        d[i] += d[i-1];

        v.push_back({x[i]-d[i], i});
    }

    sort(v.begin(), v.end());

    int h = (int)ceil(log2(n));
    int tree_size = (1<<(h+1));
    vector<int> segtree(tree_size);

    init(segtree, 1, 0, n-1);

    ll ans = 0;
    for(int i = 1; i <= n; i++)
    {
        int pos = upper_bound(v.begin(), v.end(), make_pair(x[i]-d[i-1], n)) - v.begin();
        pos--;

        int j = query(segtree, 1, 0, n-1, 0, pos);
        if(j >= i)
            ans = max(ans, g[j]-g[i-1]);
    }

    cout << ans << '\n';
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2648 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 0 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 0 ms 2396 KB Output is correct
7 Correct 0 ms 2392 KB Output is correct
8 Correct 1 ms 2392 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 0 ms 2396 KB Output is correct
11 Correct 0 ms 2396 KB Output is correct
12 Correct 1 ms 2396 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2648 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 0 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 0 ms 2396 KB Output is correct
7 Correct 0 ms 2392 KB Output is correct
8 Correct 1 ms 2392 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 0 ms 2396 KB Output is correct
11 Correct 0 ms 2396 KB Output is correct
12 Correct 1 ms 2396 KB Output is correct
13 Correct 1 ms 2396 KB Output is correct
14 Correct 0 ms 2396 KB Output is correct
15 Correct 1 ms 2392 KB Output is correct
16 Correct 1 ms 2392 KB Output is correct
17 Correct 1 ms 2392 KB Output is correct
18 Correct 1 ms 2396 KB Output is correct
19 Correct 1 ms 2396 KB Output is correct
20 Correct 1 ms 2396 KB Output is correct
21 Correct 1 ms 2396 KB Output is correct
22 Correct 1 ms 2392 KB Output is correct
23 Correct 3 ms 2652 KB Output is correct
24 Correct 2 ms 2652 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2648 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 0 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 0 ms 2396 KB Output is correct
7 Correct 0 ms 2392 KB Output is correct
8 Correct 1 ms 2392 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 0 ms 2396 KB Output is correct
11 Correct 0 ms 2396 KB Output is correct
12 Correct 1 ms 2396 KB Output is correct
13 Correct 1 ms 2396 KB Output is correct
14 Correct 0 ms 2396 KB Output is correct
15 Correct 1 ms 2392 KB Output is correct
16 Correct 1 ms 2392 KB Output is correct
17 Correct 1 ms 2392 KB Output is correct
18 Correct 1 ms 2396 KB Output is correct
19 Correct 1 ms 2396 KB Output is correct
20 Correct 1 ms 2396 KB Output is correct
21 Correct 1 ms 2396 KB Output is correct
22 Correct 1 ms 2392 KB Output is correct
23 Correct 3 ms 2652 KB Output is correct
24 Correct 2 ms 2652 KB Output is correct
25 Correct 2 ms 2652 KB Output is correct
26 Correct 3 ms 2904 KB Output is correct
27 Correct 4 ms 3160 KB Output is correct
28 Correct 16 ms 4964 KB Output is correct
29 Correct 18 ms 5072 KB Output is correct
30 Correct 39 ms 8148 KB Output is correct
31 Correct 36 ms 7096 KB Output is correct
32 Correct 33 ms 7004 KB Output is correct
33 Correct 33 ms 6860 KB Output is correct
34 Correct 31 ms 6856 KB Output is correct
35 Correct 42 ms 7368 KB Output is correct
36 Correct 37 ms 7528 KB Output is correct