Submission #366469

# Submission time Handle Problem Language Result Execution time Memory
366469 2021-02-14T08:54:55 Z kartel 3D Histogram (COCI20_histogram) C++14
0 / 110
2 ms 332 KB
#include <bits/stdc++.h>
#define in(x) freopen(x, "r", stdin)
#define out(x) freopen(x, "w", stdout)
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC optimize("-O3")
#define F first
#define S second
#define pb push_back
#define M ll(1e9 + 7)
#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>
#define eps (ld)1e-6
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;
typedef unsigned long long ull;
typedef short int si;

const int N = 2e5 + 500;

int n;
int a[N], b[N];
int mxa, mxb;
ll ans;
int ta[4 * N], tb[4 * N];

void build(int v, int l, int r) {
    if (l == r)
        ta[v] = a[l], tb[v] = b[l];
    else {
        int md = (l + r) >> 1;

        build(v * 2, l, md);
        build(v * 2 + 1, md + 1, r);

        ta[v] = min(ta[v * 2], ta[v * 2 + 1]);
        tb[v] = min(tb[v * 2], tb[v * 2 + 1]);
    }
}

int getlea(int v, int l, int r, int tl, int tr, int x) {
    if (ta[v] >= x)
        return -1;

    if (l > r || tl > tr || tl > r || l > tr)
        return -1;

    if (l == r)
        return l;


    int md = (l + r) >> 1;
    int cur = getlea(v * 2 + 1, md + 1, r, max(md + 1, tl), tr, x);

    if (cur == -1)
        return getlea(v * 2, l, md, tl, min(md, tr), x);

    return cur;
}

int getria(int v, int l, int r, int tl, int tr, int x) {
    if (ta[v] >= x)
        return -1;

    if (l > r || tl > tr || tl > r || l > tr)
        return -1;

    if (l == r)
        return l;

    int md = (l + r) >> 1;
    int cur = getria(v * 2, l, md, tl, min(md, tr), x);

    if (cur == -1)
        return getria(v * 2 + 1, md + 1, r, max(md + 1, tl), tr, x);

    return cur;
}

int getleb(int v, int l, int r, int tl, int tr, int x) {
    if (tb[v] >= x)
        return -1;

    if (l > r || tl > tr || tl > r || l > tr)
        return -1;

    if (l == r)
        return l;

    int md = (l + r) >> 1;
    int cur = getleb(v * 2 + 1, md + 1, r, max(md + 1, tl), tr, x);

    if (cur == -1)
        return getleb(v * 2, l, md, tl, min(md, tr), x);

    return cur;
}

int getrib(int v, int l, int r, int tl, int tr, int x) {
    if (tb[v] >= x)
        return -1;

    if (l > r || tl > tr || tl > r || l > tr)
        return -1;

    if (l == r)
        return l;


    int md = (l + r) >> 1;
    int cur = getrib(v * 2, l, md, tl, min(md, tr), x);

    if (cur == -1)
        return getrib(v * 2 + 1, md + 1, r, max(md + 1, tl), tr, x);

    return cur;
}

int geta(int v, int l, int r, int tl, int tr) {
    if (l > r || tl > tr || tl > r || l > tr)
        return 1e9;

    if (l == tl && r == tr)
        return ta[v];

    int md = (l + r) >> 1;

    return min(geta(v * 2, l, md, tl, min(md, tr)), geta(v * 2 + 1, md + 1, r, max(tl, md + 1), tr));
}

int getb(int v, int l, int r, int tl, int tr) {
    if (l > r || tl > tr || tl > r || l > tr)
        return 1e9;

    if (l == tl && r == tr)
        return tb[v];

    int md = (l + r) >> 1;

    return min(getb(v * 2, l, md, tl, min(md, tr)), getb(v * 2 + 1, md + 1, r, max(tl, md + 1), tr));
}

int main()
{
//    srand(time(0));
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

//    in("turtle.in");
//    out("turtle.out");
//    inf("input.txt");
//    out("output.txt");

    cin >> n;

    for (int i = 1; i <= n; i++) {
        cin >> a[i] >> b[i];

        mxa = max(a[i], mxa);
        mxb = max(b[i], mxb);
    }

    build(1, 0, n + 1);

    for (int i = 1; i <= n; i++) {
        int l = getlea(1, 0, n, 0, i - 1, a[i]);
        int r = getria(1, 0, n, i + 1, n + 1, a[i]);

        ans = max(ans, (r - l - 1) * 1ll * a[i] * getb(1, 0, n + 1, l + 1, r - 1));
    }

    for (int i = 1; i <= n; i++) {
        int l = getleb(1, 0, n + 1, 0, i - 1, b[i]);
        int r = getrib(1, 0, n + 1, i + 1, n + 1, b[i]);

        ans = max(ans, (r - l - 1) * 1ll * b[i] * geta(1, 0, n + 1, l + 1, r - 1));
    }

    cout << ans;
}
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 332 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 332 KB Output isn't correct
2 Halted 0 ms 0 KB -