Submission #160383

# Submission time Handle Problem Language Result Execution time Memory
160383 2019-10-27T08:33:44 Z godwind Art Exhibition (JOI18_art) C++17
50 / 100
1000 ms 77448 KB
#pragma GCC optimize("Ofast")
#pragma GCC optimize("no-stack-protector")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("fast-math")
#pragma GCC target("sse,sse2,sse3,ssse3,popcnt,abm,mmx,tune=native")
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <stdio.h>
#include <cstdio>
#include <math.h>
#include <cmath>
#include <string>
#include <cstring>
#include <queue>
#include <deque>
#include <random>
#include <iomanip>
#include <bitset>
 
 
using namespace std;
 
template<typename T> void uin(T &a, T b) {
    if (b < a) {
        a = b;
    }
}
 
template<typename T> void uax(T &a, T b) {
    if (b > a) {
        a = b;
    }
}
 
#define int long long
#define left left228
#define right right228
#define prev prev228
#define list list228
#define mp make_pair
#define all(v) v.begin(), v.end()
#define forn(i, n) for (int i = 0; i < (int)n; ++i)
#define firn(i, n) for (int i = 1; i < (int)n; ++i)
#define x first
#define y second

const int N = 500 * 1000 + 228;

int a[N], b[N];
int X;
vector<int> crd;

struct node
{
    int mx, mod;
    int l, r;
    node() {
        mx = mod = l = r = 0;
    }
};
vector< node > d;
void build(int l, int r, int v = 1) {
    d[v].l = l, d[v].r = r;
    if (l == r) {
        d[v].mx = crd.back() - crd[l - 1];
    } else {
        int m = (l + r) >> 1;
        build(l, m, v << 1); build(m + 1, r, v << 1 | 1);
        d[v].mx = max(d[v << 1].mx, d[v << 1 | 1].mx);
    }
}
int gets(int v) {
    return d[v].mx + d[v].mod;
}
void push(int v) {
    d[v << 1].mod += d[v].mod;
    d[v << 1 | 1].mod += d[v].mod;
    d[v].mod = 0;
    d[v].mx = max(gets(v << 1), gets(v << 1 | 1));
}
void update(int l, int r, int x, int v = 1) {
    if (l > r || d[v].l > r || d[v].r < l) return;
    if (l <= d[v].l && d[v].r <= r) {
        d[v].mod += x;
    } else {
        push(v);
        update(l, r, x, v << 1); update(l, r, x, v << 1 | 1);
        d[v].mx = max(gets(v << 1), gets(v << 1 | 1));
    }
}
int get(int l, int r, int v = 1) {
    if (l > r || d[v].l > r || d[v].r < l) return 0;
    if (l <= d[v].l && d[v].r <= r) return gets(v);
    push(v);
    return max(get(l, r, v << 1), get(l, r, v << 1 | 1));
}
void init(int n) {
    int ss = 1;
    while (ss < n) ss <<= 1;
    ss <<= 1;
    d.resize(ss + 3, node());
    build(1, n);
}

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    unordered_map<int, int> sum;
    sum.rehash(500 * 1000 + 228);
    for (int i = 1; i <= n; ++i) {
        cin >> a[i] >> b[i];
        sum[a[i]] += b[i];
        crd.push_back(a[i]);
    }
    sort(crd.begin(), crd.end());
    crd.erase(unique(crd.begin(), crd.end()), crd.end());
    int sz = (int)crd.size();
    init(sz);
    int res = 0;
    int pv = crd.back();
    int delta = 0;
    for (int i = sz; i; --i) {
        delta += crd[i - 1] - pv;
        pv = crd[i - 1];
        update(i, sz, sum[crd[i - 1]]);
        uax(res, delta + get(i, sz));
    }
    cout << res << '\n';
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 5 ms 4472 KB Output is correct
2 Correct 6 ms 4476 KB Output is correct
3 Correct 5 ms 4472 KB Output is correct
4 Correct 6 ms 4472 KB Output is correct
5 Correct 6 ms 4472 KB Output is correct
6 Correct 6 ms 4472 KB Output is correct
7 Correct 6 ms 4472 KB Output is correct
8 Correct 6 ms 4472 KB Output is correct
9 Correct 5 ms 4472 KB Output is correct
10 Correct 6 ms 4472 KB Output is correct
11 Correct 6 ms 4472 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 4472 KB Output is correct
2 Correct 6 ms 4476 KB Output is correct
3 Correct 5 ms 4472 KB Output is correct
4 Correct 6 ms 4472 KB Output is correct
5 Correct 6 ms 4472 KB Output is correct
6 Correct 6 ms 4472 KB Output is correct
7 Correct 6 ms 4472 KB Output is correct
8 Correct 6 ms 4472 KB Output is correct
9 Correct 5 ms 4472 KB Output is correct
10 Correct 6 ms 4472 KB Output is correct
11 Correct 6 ms 4472 KB Output is correct
12 Correct 6 ms 4472 KB Output is correct
13 Correct 6 ms 4472 KB Output is correct
14 Correct 6 ms 4472 KB Output is correct
15 Correct 6 ms 4472 KB Output is correct
16 Correct 6 ms 4472 KB Output is correct
17 Correct 6 ms 4472 KB Output is correct
18 Correct 6 ms 4472 KB Output is correct
19 Correct 6 ms 4476 KB Output is correct
20 Correct 6 ms 4472 KB Output is correct
21 Correct 6 ms 4472 KB Output is correct
22 Correct 6 ms 4472 KB Output is correct
23 Correct 6 ms 4472 KB Output is correct
24 Correct 6 ms 4472 KB Output is correct
25 Correct 6 ms 4472 KB Output is correct
26 Correct 6 ms 4440 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 4472 KB Output is correct
2 Correct 6 ms 4476 KB Output is correct
3 Correct 5 ms 4472 KB Output is correct
4 Correct 6 ms 4472 KB Output is correct
5 Correct 6 ms 4472 KB Output is correct
6 Correct 6 ms 4472 KB Output is correct
7 Correct 6 ms 4472 KB Output is correct
8 Correct 6 ms 4472 KB Output is correct
9 Correct 5 ms 4472 KB Output is correct
10 Correct 6 ms 4472 KB Output is correct
11 Correct 6 ms 4472 KB Output is correct
12 Correct 6 ms 4472 KB Output is correct
13 Correct 6 ms 4472 KB Output is correct
14 Correct 6 ms 4472 KB Output is correct
15 Correct 6 ms 4472 KB Output is correct
16 Correct 6 ms 4472 KB Output is correct
17 Correct 6 ms 4472 KB Output is correct
18 Correct 6 ms 4472 KB Output is correct
19 Correct 6 ms 4476 KB Output is correct
20 Correct 6 ms 4472 KB Output is correct
21 Correct 6 ms 4472 KB Output is correct
22 Correct 6 ms 4472 KB Output is correct
23 Correct 6 ms 4472 KB Output is correct
24 Correct 6 ms 4472 KB Output is correct
25 Correct 6 ms 4472 KB Output is correct
26 Correct 6 ms 4440 KB Output is correct
27 Correct 12 ms 5240 KB Output is correct
28 Correct 12 ms 5240 KB Output is correct
29 Correct 11 ms 5240 KB Output is correct
30 Correct 11 ms 5240 KB Output is correct
31 Correct 11 ms 5240 KB Output is correct
32 Correct 11 ms 5240 KB Output is correct
33 Correct 11 ms 5240 KB Output is correct
34 Correct 12 ms 5240 KB Output is correct
35 Correct 12 ms 5240 KB Output is correct
36 Correct 11 ms 5240 KB Output is correct
37 Correct 12 ms 5240 KB Output is correct
38 Correct 12 ms 5240 KB Output is correct
39 Correct 12 ms 5240 KB Output is correct
40 Correct 11 ms 5240 KB Output is correct
41 Correct 11 ms 5240 KB Output is correct
42 Correct 12 ms 5244 KB Output is correct
43 Correct 12 ms 5240 KB Output is correct
44 Correct 12 ms 5240 KB Output is correct
45 Correct 11 ms 5240 KB Output is correct
46 Correct 12 ms 5368 KB Output is correct
47 Correct 12 ms 5240 KB Output is correct
48 Correct 12 ms 5240 KB Output is correct
49 Correct 13 ms 5244 KB Output is correct
50 Correct 12 ms 5240 KB Output is correct
51 Correct 12 ms 5240 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 4472 KB Output is correct
2 Correct 6 ms 4476 KB Output is correct
3 Correct 5 ms 4472 KB Output is correct
4 Correct 6 ms 4472 KB Output is correct
5 Correct 6 ms 4472 KB Output is correct
6 Correct 6 ms 4472 KB Output is correct
7 Correct 6 ms 4472 KB Output is correct
8 Correct 6 ms 4472 KB Output is correct
9 Correct 5 ms 4472 KB Output is correct
10 Correct 6 ms 4472 KB Output is correct
11 Correct 6 ms 4472 KB Output is correct
12 Correct 6 ms 4472 KB Output is correct
13 Correct 6 ms 4472 KB Output is correct
14 Correct 6 ms 4472 KB Output is correct
15 Correct 6 ms 4472 KB Output is correct
16 Correct 6 ms 4472 KB Output is correct
17 Correct 6 ms 4472 KB Output is correct
18 Correct 6 ms 4472 KB Output is correct
19 Correct 6 ms 4476 KB Output is correct
20 Correct 6 ms 4472 KB Output is correct
21 Correct 6 ms 4472 KB Output is correct
22 Correct 6 ms 4472 KB Output is correct
23 Correct 6 ms 4472 KB Output is correct
24 Correct 6 ms 4472 KB Output is correct
25 Correct 6 ms 4472 KB Output is correct
26 Correct 6 ms 4440 KB Output is correct
27 Correct 12 ms 5240 KB Output is correct
28 Correct 12 ms 5240 KB Output is correct
29 Correct 11 ms 5240 KB Output is correct
30 Correct 11 ms 5240 KB Output is correct
31 Correct 11 ms 5240 KB Output is correct
32 Correct 11 ms 5240 KB Output is correct
33 Correct 11 ms 5240 KB Output is correct
34 Correct 12 ms 5240 KB Output is correct
35 Correct 12 ms 5240 KB Output is correct
36 Correct 11 ms 5240 KB Output is correct
37 Correct 12 ms 5240 KB Output is correct
38 Correct 12 ms 5240 KB Output is correct
39 Correct 12 ms 5240 KB Output is correct
40 Correct 11 ms 5240 KB Output is correct
41 Correct 11 ms 5240 KB Output is correct
42 Correct 12 ms 5244 KB Output is correct
43 Correct 12 ms 5240 KB Output is correct
44 Correct 12 ms 5240 KB Output is correct
45 Correct 11 ms 5240 KB Output is correct
46 Correct 12 ms 5368 KB Output is correct
47 Correct 12 ms 5240 KB Output is correct
48 Correct 12 ms 5240 KB Output is correct
49 Correct 13 ms 5244 KB Output is correct
50 Correct 12 ms 5240 KB Output is correct
51 Correct 12 ms 5240 KB Output is correct
52 Correct 1000 ms 64736 KB Output is correct
53 Execution timed out 1014 ms 77448 KB Time limit exceeded
54 Halted 0 ms 0 KB -