This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define ff first
#define ss second
#define pb push_back
#define all(a) (a).begin(), (a).end()
#define replr(i, a, b) for (int i = int(a); i <= int(b); ++i)
#define reprl(i, a, b) for (int i = int(a); i >= int(b); --i)
#define rep(i, n) for (int i = 0; i < int(n); ++i)
#define mkp(a, b) make_pair(a, b)
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<PII> VPI;
typedef vector<VI> VVI;
typedef vector<VVI> VVVI;
typedef vector<VPI> VVPI;
typedef pair<ll, ll> PLL;
typedef vector<ll> VL;
typedef vector<PLL> VPL;
typedef vector<VL> VVL;
typedef vector<VVL> VVVL;
typedef vector<VPL> VVPL;
template<class T> T setmax(T& a, T b) {if (a < b) return a = b; return a;}
template<class T> T setmin(T& a, T b) {if (a < b) return a; return a = b;}
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
template<class T>
using indset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#include "meetings.h"
namespace TEST2 {
VL minimum_costs(VI H, VI L, VI R) {
int n = H.size();
VVL prefs(n, VL(n+1));
replr(x, 0, n-1) {
replr(i, 1, n) prefs[x][i] = H[i-1];
replr(i, (x+1)+1, n) setmax(prefs[x][i], prefs[x][i-1]);
reprl(i, (x+1)-1, 1) setmax(prefs[x][i], prefs[x][i+1]);
replr(i, 1, n) prefs[x][i] += prefs[x][i-1];
}
int q = L.size();
VL answ(q, 1e18);
rep(i, q) {
int l = L[i], r = R[i];
replr(x, l, r) {
setmin(answ[i], prefs[x][r+1]-prefs[x][l]);
}
}
return answ;
}
};
namespace TEST3 {
struct SEGMENT {
int prf;
int suf;
int mid;
int cpl;
SEGMENT(int a = -1e9) {
prf = suf = mid = cpl = a;
}
};
SEGMENT best(const SEGMENT& a, const SEGMENT& b) {
SEGMENT c;
setmax(c.prf, max(a.prf, a.cpl + b.prf));
setmax(c.suf, max(a.suf + b.cpl, b.suf));
setmax(c.mid, max({a.mid, b.mid, a.suf + b.prf}));
setmax(c.cpl, a.cpl + b.cpl);
return c;
}
struct SEGTREE {
int n;
vector<SEGMENT> tree;
SEGTREE(int sz) {
n = 1;
while (n < sz) n *= 2;
tree = vector<SEGMENT>(2*n);
}
void upd(int N, int L, int R, int i, int s) {
if (i < L || i > R) return;
if (L == R) {
tree[N] = SEGMENT(s == 1 ? 1 : -1e9);
return;
}
int M = (L + R) / 2;
upd(2*N+1, L, M, i, s);
upd(2*N+2, M+1, R, i, s);
tree[N] = best(tree[2*N+1], tree[2*N+2]);
}
SEGMENT get(int N, int L, int R, int l, int r) {
if (l <= L && R <= r) return tree[N];
if (R < l || L > r) return SEGMENT();
int M = (L + R) / 2;
return best(get(2*N+1, L, M, l, r), get(2*N+2, M+1, R, l, r));
}
void upd(int i, int s) {
upd(0, 0, n-1, i, s);
}
int get(int l, int r) {
return get(0, 0, n-1, l, r).mid;
}
};
VL minimum_costs(VI H, VI L, VI R) {
int n = H.size();
SEGTREE seg(n);
rep(i, n) seg.upd(i, H[i]);
int q = L.size();
VL answ(q);
rep(i, q) {
auto[l, r] = make_tuple(L[i], R[i]);
int mx = seg.get(l, r);
answ[i] = 2 * (r-l+1) - (mx < 0 ? 0 : mx);
}
return answ;
}
};
VL minimum_costs(VI H, VI L, VI R) {
/*VL ans1 = TEST2::minimum_costs(H, L, R);*/
/*VL ans2 = TEST3::minimum_costs(H, L, R);*/
/*rep(i, L.size()) {*/
/* cout << ans1[i] << " " << ans2[i] << endl;*/
/*}*/
/*return VL();*/
if (H.size() <= 5000 && L.size() <= 5000) return TEST2::minimum_costs(H, L, R);
return TEST3::minimum_costs(H, L, R);
}
Compilation message (stderr)
meetings.cpp: In function 'VL TEST3::minimum_costs(VI, VI, VI)':
meetings.cpp:113:17: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
113 | auto[l, r] = make_tuple(L[i], R[i]);
| ^
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |