Submission #307713

# Submission time Handle Problem Language Result Execution time Memory
307713 2020-09-29T07:43:49 Z kartel Divide and conquer (IZhO14_divide) C++14
0 / 100
0 ms 256 KB
#include <iostream>
#include <stdio.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
#define in(x) freopen(x, "r", stdin)
#define out(x) freopen(x, "w", stdout)
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC optimize("-O3")
#define F first
#define S second
#define pb push_back
#define N +200500
#define M ll(998244353)
#define sz(x) (int)x.size()
#define re return
#define oo ll(1e18)
#define el '\n'
#define pii pair <int, int>
#define all(x) (x).begin(), (x).end()
#define arr_all(x, n) (x + 1), (x + 1 + n)
//#define vi vector <int>
using namespace std;
//using namespace __gnu_pbds;
//typedef tree <int, null_type, less_equal <int> , rb_tree_tag, tree_order_statistics_node_update> ordered_set;
typedef long long ll;
typedef long double ld;

struct tree{
    tree *L, *R;
    ll mn;

    tree () {
        mn = 1e9;
        L = NULL;
        R = NULL;
    }

    void upd(ll l, ll r, ll ps, ll val)
    {
        if (l == r)
            mn = val;
        else
        {
            ll md = (l + r) / 2ll;

            if (ps <= md)
            {
                if (L == NULL)
                    L = new tree();

                L -> upd(l, md, ps, val);
            }
            else
            {
                if (R == NULL)
                    R = new tree();

                R -> upd(md + 1, r, ps, val);
            }

            mn = 1e9;

            if (L != NULL) mn = min(mn, L -> mn);
            if (R != NULL) mn = min(mn, R -> mn);
        }
    }

    ll get(ll l, ll r, ll tl, ll tr)
    {
        if (l > r || tl > tr || l > tr || tl > r)
            return 1e9;

        if (l == tl && r == tr)
            return mn;

        ll md = (l + r) / 2ll;
        ll cur_0 = 1e9;
        ll cur_1 = 1e9;

        if (L != NULL)
            cur_0 = L -> get(l, md, tl, min(md, tr));

        if (R != NULL)
            cur_1 = R -> get(md + 1, r, max(md + 1, tl), tr);

        return min(cur_0, cur_1);
    }
};

tree t;
int i, n, x, g, e;
ll pf[N], pr, ans;

int main()
{
//    ios_base::sync_with_stdio(0);
//    cin.tie(NULL);
    in("divide.in");
    out("divide.out");
//    in("input.txt");
//    out("output.txt");

    cin >> n;

    // pr[i] - pr[j - 1] >= x[i] - x[j]
    // pr[i] - x[i] >= pr[j - 1] - x[j]

    for (i = 1; i <= n; i++)
    {
        ll prr = pr;
        cin >> x >> g >> e;

        pr += e;
        pf[i] = pf[i - 1] + g;

        int j = t.get(0, 2e9, 0, 1e9 + pr - x);

        if (j == 1e9)
            j = i;

        ans = max(ans, pf[i] - pf[j - 1]);

        t.upd(0, 2e9, 1e9 + prr - x, i);
    }

    cout << ans;
}

Compilation message

divide.cpp: In function 'int main()':
divide.cpp:5:22: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
    5 | #define in(x) freopen(x, "r", stdin)
      |               ~~~~~~~^~~~~~~~~~~~~~~
divide.cpp:99:5: note: in expansion of macro 'in'
   99 |     in("divide.in");
      |     ^~
divide.cpp:6:23: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
    6 | #define out(x) freopen(x, "w", stdout)
      |                ~~~~~~~^~~~~~~~~~~~~~~~
divide.cpp:100:5: note: in expansion of macro 'out'
  100 |     out("divide.out");
      |     ^~~
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 256 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 256 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 256 KB Output isn't correct
2 Halted 0 ms 0 KB -