Submission #491508

# Submission time Handle Problem Language Result Execution time Memory
491508 2021-12-02T18:25:08 Z Yazan_Alattar Divide and conquer (IZhO14_divide) C++14
48 / 100
1000 ms 6856 KB
#include <iostream>
#include <fstream>
#include <vector>
#include <cstring>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <list>
#include <utility>
#include <cmath>
#include <assert.h>
#include <numeric>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pb push_back
#define endl "\n"
#define all(x) x.begin(), x.end()
const int M = 100007;
const ll inf = 1e18;
const ll mod = 1e9 + 7;
const double pi = acos(-1);
const int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};

ll n, x[M], g[M], d[M], seg[4 * M], lazy[4 * M], ans;

void push(int node, int l, int r)
{
    if(lazy[node] != 0){
        seg[node] += (r - l + 1) * lazy[node];
        if(l != r){
            lazy[2 * node] += lazy[node];
            lazy[2 * node + 1] += lazy[node];
        }
        lazy[node] = 0;
    }
    return;
}

void upd(int st, int en, ll v, int node = 1, int l = 1, int r = n)
{
    push(node, l, r);
    if(l > en || r < st) return;
    if(l >= st && r <= en){
        lazy[node] += v;
        push(node, l, r);
        return;
    }
    int mid = (l + r) / 2;
    upd(st, en, v, 2 * node, l, mid);
    upd(st, en, v, 2 * node + 1, mid + 1, r);
    seg[node] = max(seg[2 * node], seg[2 * node + 1]);
    return;
}

int get(int st, int en, int node = 1, int l = 1, int r = n)
{
    push(node, l, r);
    if(l > en || r < st || seg[node] < 0) return -1;
    if(l == r) return l;
    int mid = (l + r) / 2;
    int ret = get(st, en, 2 * node + 1, mid + 1, r);
    if(ret == -1) ret = get(st, en, 2 * node, l, mid);
    return ret;
}

int main()
{
    ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    cin >> n;
    for(int i = 1; i <= n; ++i){
        cin >> x[i] >> g[i] >> d[i];
        g[i] += g[i - 1];
        d[i] += d[i - 1];
        upd(i, i, d[i] - x[i]);
    }
    for(int i = 1; i <= n; ++i){
        ll add = x[i] - x[i - 1];
        if(i > 1) add += -d[i - 1] + d[i - 2];
        upd(i, n, add);
        ans = max(ans, g[get(i, n)] - g[i - 1]);
    }
    cout << ans << endl;
    return 0;
}
// Don't forget special cases. (n = 1?)
// Look for the constraints. (Runtime array? overflow?)
# Verdict Execution time Memory Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 0 ms 332 KB Output is correct
5 Correct 0 ms 332 KB Output is correct
6 Correct 0 ms 332 KB Output is correct
7 Correct 0 ms 332 KB Output is correct
8 Correct 0 ms 332 KB Output is correct
9 Correct 0 ms 332 KB Output is correct
10 Correct 0 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 0 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 0 ms 332 KB Output is correct
5 Correct 0 ms 332 KB Output is correct
6 Correct 0 ms 332 KB Output is correct
7 Correct 0 ms 332 KB Output is correct
8 Correct 0 ms 332 KB Output is correct
9 Correct 0 ms 332 KB Output is correct
10 Correct 0 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 0 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 0 ms 332 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 2 ms 332 KB Output is correct
17 Correct 3 ms 408 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 2 ms 332 KB Output is correct
21 Correct 10 ms 332 KB Output is correct
22 Correct 15 ms 464 KB Output is correct
23 Correct 94 ms 716 KB Output is correct
24 Correct 94 ms 716 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 0 ms 332 KB Output is correct
5 Correct 0 ms 332 KB Output is correct
6 Correct 0 ms 332 KB Output is correct
7 Correct 0 ms 332 KB Output is correct
8 Correct 0 ms 332 KB Output is correct
9 Correct 0 ms 332 KB Output is correct
10 Correct 0 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 0 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 0 ms 332 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 2 ms 332 KB Output is correct
17 Correct 3 ms 408 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 2 ms 332 KB Output is correct
21 Correct 10 ms 332 KB Output is correct
22 Correct 15 ms 464 KB Output is correct
23 Correct 94 ms 716 KB Output is correct
24 Correct 94 ms 716 KB Output is correct
25 Correct 4 ms 716 KB Output is correct
26 Correct 8 ms 1052 KB Output is correct
27 Correct 7 ms 1100 KB Output is correct
28 Correct 40 ms 3444 KB Output is correct
29 Correct 41 ms 3496 KB Output is correct
30 Correct 86 ms 6732 KB Output is correct
31 Correct 80 ms 6852 KB Output is correct
32 Correct 82 ms 6748 KB Output is correct
33 Correct 80 ms 6676 KB Output is correct
34 Execution timed out 1088 ms 6856 KB Time limit exceeded
35 Halted 0 ms 0 KB -