Submission #332210

# Submission time Handle Problem Language Result Execution time Memory
332210 2020-12-01T16:58:55 Z topovik Divide and conquer (IZhO14_divide) C++14
100 / 100
172 ms 8028 KB
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

#define f first
#define s second
#define pb push_back
#define INF 1000000000

using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef long double ld;

typedef tree<
ll,
null_type,
greater<ll>,
rb_tree_tag,
tree_order_statistics_node_update> ordered_set;

const ll N = 2e5;

ll a[N], b[N], c[N];

ll ans = 0;
ll n;

void Divide(ll l, ll r)
{
    if (l == r)
    {
        ans = max(ans, b[l]);
        return;
    }
    ll mdl = (l + r) >> 1;
    Divide(l, mdl);
    Divide(mdl + 1, r);
    vector <pair<ll, ll> > fr, sc;
    ll power = 0, sum = 0;
    for (ll i = mdl + 1; i <= r; i++) sum += b[i], power += c[i] - (a[i] - a[i - 1]), sc.pb({power, sum});
    power = 0, sum = 0;
    for (ll i = mdl; i >= l; i--) power += c[i] - (a[min(i + 1, mdl)] - a[i]), sum += b[i], fr.pb({power, sum});
    sort(fr.begin(), fr.end());
    sort(sc.begin(), sc.end());
    ll j = sc.size() - 1, mx = -1e18;
    for (ll i = 0; i < fr.size(); i++)
    {
        while (j >= 0 && sc[j].f + fr[i].f >= 0) mx = max(mx, sc[j].s), j--;
        ans = max(ans, fr[i].s + mx);
    }
}

int main()
{
    cin >> n;
    for (ll i = 0; i < n; i++) cin >> a[i] >> b[i] >> c[i];
    Divide(0, n - 1);
    cout << ans;
}

Compilation message

divide.cpp: In function 'void Divide(ll, ll)':
divide.cpp:47:22: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   47 |     for (ll i = 0; i < fr.size(); i++)
      |                    ~~^~~~~~~~~~~
# 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 0 ms 364 KB Output is correct
4 Correct 1 ms 364 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 364 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 0 ms 364 KB Output is correct
4 Correct 1 ms 364 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 364 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 364 KB Output is correct
17 Correct 2 ms 364 KB Output is correct
18 Correct 3 ms 492 KB Output is correct
19 Correct 2 ms 364 KB Output is correct
20 Correct 2 ms 364 KB Output is correct
21 Correct 2 ms 492 KB Output is correct
22 Correct 3 ms 492 KB Output is correct
23 Correct 7 ms 748 KB Output is correct
24 Correct 7 ms 748 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 0 ms 364 KB Output is correct
4 Correct 1 ms 364 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 364 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 364 KB Output is correct
17 Correct 2 ms 364 KB Output is correct
18 Correct 3 ms 492 KB Output is correct
19 Correct 2 ms 364 KB Output is correct
20 Correct 2 ms 364 KB Output is correct
21 Correct 2 ms 492 KB Output is correct
22 Correct 3 ms 492 KB Output is correct
23 Correct 7 ms 748 KB Output is correct
24 Correct 7 ms 748 KB Output is correct
25 Correct 6 ms 620 KB Output is correct
26 Correct 11 ms 924 KB Output is correct
27 Correct 14 ms 1072 KB Output is correct
28 Correct 81 ms 3708 KB Output is correct
29 Correct 83 ms 3960 KB Output is correct
30 Correct 172 ms 8028 KB Output is correct
31 Correct 145 ms 6748 KB Output is correct
32 Correct 138 ms 6876 KB Output is correct
33 Correct 135 ms 6620 KB Output is correct
34 Correct 145 ms 6620 KB Output is correct
35 Correct 144 ms 7132 KB Output is correct
36 Correct 151 ms 7260 KB Output is correct