Submission #340652

# Submission time Handle Problem Language Result Execution time Memory
340652 2020-12-28T05:02:56 Z IZhO_2021_I_want_Silver Divide and conquer (IZhO14_divide) C++14
100 / 100
159 ms 11372 KB
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <set>
#include <map>
#include <iomanip>
#include <cassert>
#include <stack>
#include <queue>
#include <deque>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>-

using namespace std;
//using namespace __gnu_pbds;

typedef long long ll;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;

// template<typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
//  order_of_key (k) : Number of items strictly smaller than k .
//  find_by_order(k) : K-th element in a set (counting from zero).
#define sz(a) (int)a.size()
#define all(a) a.begin(), a.end()
#define pb push_back
#define ppb pop_back
#define mkp make_pair
#define F first
#define S second
#define lb lower_bound
#define ub upper_bound
#define show(a) cerr << #a <<" -> "<< a <<" "
#define nl cerr <<"\n"
#define int ll

const int N = (1 << 20) - 1;

int n, t[N*3], add[N*3], x[N], g[N], d[N], sumd[N], sumg[N];

void push(int v, int tl, int tr) {
    if (add[v]) {
        t[v] += add[v];
        if (tl < tr) {
            add[v*2] += add[v];
            add[v*2+1] += add[v];
        }
        add[v] = 0;
    }
}

void upd(int l, int r, int x, int v=1, int tl=1, int tr=n) {
    push(v, tl, tr);
    if (r < tl || tr < l) { return; }
    if (l <= tl && tr <= r) {
        add[v] += x;
        push(v, tl, tr);
        return;
    }
    int tm = (tl + tr) / 2;
    upd(l, r, x, v*2, tl, tm);
    upd(l, r, x, v*2+1, tm+1, tr);
    t[v] = max(t[v*2], t[v*2+1]);
}

int get(int pos, int v=1, int tl=1, int tr=n) {
    push(v, tl, tr);
    if (tl == tr) { return tl; }
    int tm = (tl + tr) / 2;
    if (t[v*2+1]+add[v*2+1] >= 0) { return get(pos, v*2+1, tm+1, tr); }
    else if (t[v*2]+add[v*2] >= 0) { return get(pos, v*2, tl, tm); }
    return -1;
}

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

        sumg[i] = sumg[i-1] + g[i];
        sumd[i] = sumd[i-1] + d[i];

        upd(i, i, sumd[i] - x[i]);
    }

    int ans = 0;
    for (int i = 1; i <= n; ++i) {
        upd(i, n, +x[i]);

        int j = get(i);
        if (i <= j) { ans = max(ans, sumg[j] - sumg[i-1]); }

        upd(i, n, -x[i]-d[i]);
    }
    cout << ans;
}

 main () {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int tests = 1;
	//cin >> tests;
	while (tests --) {
		solve();
	}
	return 0;
}
/*
    Just Chalish!
*/

Compilation message

divide.cpp:99:8: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   99 |  main () {
      |        ^
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 1 ms 492 KB Output is correct
17 Correct 2 ms 492 KB Output is correct
18 Correct 2 ms 492 KB Output is correct
19 Correct 2 ms 640 KB Output is correct
20 Correct 2 ms 492 KB Output is correct
21 Correct 2 ms 492 KB Output is correct
22 Correct 3 ms 620 KB Output is correct
23 Correct 6 ms 1004 KB Output is correct
24 Correct 7 ms 1004 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 1 ms 492 KB Output is correct
17 Correct 2 ms 492 KB Output is correct
18 Correct 2 ms 492 KB Output is correct
19 Correct 2 ms 640 KB Output is correct
20 Correct 2 ms 492 KB Output is correct
21 Correct 2 ms 492 KB Output is correct
22 Correct 3 ms 620 KB Output is correct
23 Correct 6 ms 1004 KB Output is correct
24 Correct 7 ms 1004 KB Output is correct
25 Correct 6 ms 876 KB Output is correct
26 Correct 12 ms 1388 KB Output is correct
27 Correct 13 ms 1516 KB Output is correct
28 Correct 72 ms 5484 KB Output is correct
29 Correct 75 ms 5740 KB Output is correct
30 Correct 159 ms 11372 KB Output is correct
31 Correct 149 ms 10092 KB Output is correct
32 Correct 152 ms 10220 KB Output is correct
33 Correct 150 ms 10092 KB Output is correct
34 Correct 126 ms 10112 KB Output is correct
35 Correct 132 ms 10612 KB Output is correct
36 Correct 134 ms 10860 KB Output is correct