# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
286291 |
2020-08-30T09:18:23 Z |
Vimmer |
Meetings (IOI18_meetings) |
C++14 |
|
2794 ms |
235156 KB |
#include <bits/stdc++.h>
//#pragma GCC optimize("unroll-loops")
//#pragma GCC optimize("-O3")
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("fast-math")
//#pragma GCC optimize("no-stack-protector")
#define F first
#define S second
#define sz(x) int(x.size())
#define pb push_back
#define pf push_front
#define N 5005
#define M ll(998244353)
#define inf 1e9 + 1e9
using namespace std;
typedef long double ld;
typedef long long ll;
typedef unsigned long long ull;
typedef short int si;
typedef array <ll, 3> a3;
typedef array <ll, 4> a4;
ll t[N * 4], pr[N][N], sf[N][N], val[N];
int Tl[400100], Tr[400100], T[400100];
int mx[N * 4], psh[N * 4];
vector <int> a;
void Push(int v, int tl, int tr)
{
if (psh[v] == 0) return;
t[v] = ll(psh[v]) * ll(tr - tl + 1);
if (tl != tr) psh[v + v] = psh[v + v + 1] = psh[v];
psh[v] = 0;
}
void upd(int v, int tl, int tr, int l, int r, int val)
{
Push(v, tl, tr);
if (r < tl || tr < l || l > r) return;
if (l <= tl && tr <= r) {psh[v] = val; Push(v, tl, tr); return;}
int md = (tl + tr) >> 1;
upd(v + v, tl, md, l, r, val); upd(v + v + 1, md + 1, tr, l, r, val);
t[v] = t[v + v] + t[v + v + 1];
}
ll sm(int v, int tl, int tr, int l, int r)
{
Push(v, tl, tr);
if (r < tl || tr < l || l > r) return 0ll;
if (l <= tl && tr <= r) return t[v];
int md = (tl + tr) >> 1;
return sm(v + v, tl, md, l, r) + sm(v + v + 1, md + 1, tr, l, r);
}
int fndl(int v, int tl, int tr, int l, int r, int val)
{
if (mx[v] <= val || l > r || r < tl || tr < l) return -1;
if (tl == tr) return tl;
int md = (tl + tr) >> 1;
int vt = -1;
if (mx[v + v] > val) vt = fndl(v + v, tl, md, l, r, val);
if (vt == -1) vt = fndl(v + v + 1, md + 1, tr, l, r, val);
return vt;
}
int fndr(int v, int tl, int tr, int l, int r, int val)
{
if (mx[v] <= val || l > r || r < tl || tr < l) return -1;
if (tl == tr) return tl;
int md = (tl + tr) >> 1;
int vt = -1;
if (mx[v + v + 1] > val) vt = fndr(v + v + 1, md + 1, tr, l, r, val);
if (vt == -1) vt = fndr(v + v, tl, md, l, r, val);
return vt;
}
void bld(int v, int tl, int tr)
{
if (tl == tr) mx[v] = a[tl];
else
{
int md = (tl + tr) >> 1;
bld(v + v, tl, md);
bld(v + v + 1, md + 1, tr);
mx[v] = max(mx[v + v], mx[v + v + 1]);
}
}
void build(int v, int tl, int tr)
{
if (tl == tr)
{
if (a[tl] == 1) T[v] = Tl[v] = Tr[v] = 1;
else T[v] = Tl[v] = Tr[v] = 0;
}
else
{
int md = (tl + tr) >> 1;
build(v + v, tl, md);
build(v + v + 1, md + 1, tr);
if (Tr[v + v + 1] != tr - md) Tr[v] = Tr[v + v + 1];
else Tr[v] = Tr[v + v + 1] + Tr[v + v];
if (Tl[v + v] != md - tl + 1) Tl[v] = Tl[v + v];
else Tl[v] = Tl[v + v] + Tl[v + v + 1];
T[v] = max(T[v + v], T[v + v + 1]);
T[v] = max(T[v], max(Tr[v], Tl[v]));
T[v] = max(T[v], Tr[v + v] + Tl[v + v + 1]);
}
}
int skok(int v, int tl, int tr, int l, int r)
{
if (tr < l || r < tl || l > r) return 0;
if (l <= tl && tr <= r) return T[v];
int md = (tl + tr) >> 1;
return max(skok(v + v, tl, md, l, r), skok(v + v + 1, md + 1, tr, l, r));
}
vector <ll> minimum_costs (vector <int> h, vector <int> l, vector <int> r)
{
int q = sz(l);
int n = sz(h);
vector <ll> ans(q);
bool f = 1;
for (int i = 0; i < n; i++) if (h[i] > 2) f = 0;
a = h;
if (f)
{
build(1, 0, n - 1);
for (int i = 0; i < q; i++)
ans[i] = (r[i] - l[i] + 1) * 2 - skok(1, 0, n - 1, l[i], r[i]);
return ans;
}
bld(1, 0, n - 1);
int mxn = 0;
upd(1, 0, n - 1, 0, n - 1, 0);
for (register int j = 0; j <= n - 1; j++)
{
if (mxn == 0 || mxn <= h[j]) upd(1, 0, n - 1, 0, j, h[j]);
else
{
int it = fndr(1, 0, n - 1, 0, j - 1, h[j]);
upd(1, 0, n - 1, it + 1, j, h[j]);
}
for (int u = j; u >= 0; u--) pr[j][u] = sm(1, 0, n - 1, 0, u);
val[j] = pr[j][j];
mxn = max(mxn, h[j]);
}
upd(1, 0, n - 1, 0, n - 1, 0);
mxn = 0;
for (register int j = n - 1; j >= 0; j--)
{
if (mxn == 0 || mxn <= h[j]) upd(1, 0, n - 1, j, n - 1, h[j]);
else
{
int it = fndl(1, 0, n - 1, j + 1, n - 1, h[j]);
upd(1, 0, n - 1, j, it - 1, h[j]);
}
for (int u = j; u < n; u++) sf[j][u] = sm(1, 0, n - 1, u, n - 1);
val[j] += sm(1, 0, n - 1, j + 1, n - 1);
mxn = max(mxn, h[j]);
}
if (n == 5000) return ans;
for (int i = 0; i < q; i++)
{
ll mn = 1e18;
for (int j = l[i]; j <= r[i]; j++)
mn = min(mn, val[j] - (l[i] == 0 ? 0 : pr[j][l[i] - 1]) - (r[i] == n - 1 ? 0 : sf[j][r[i] + 1]));
ans[i] = mn;
}
return ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
979 ms |
95368 KB |
Output is correct |
3 |
Correct |
969 ms |
95352 KB |
Output is correct |
4 |
Correct |
980 ms |
95480 KB |
Output is correct |
5 |
Correct |
967 ms |
95352 KB |
Output is correct |
6 |
Correct |
989 ms |
95352 KB |
Output is correct |
7 |
Correct |
980 ms |
95480 KB |
Output is correct |
8 |
Correct |
1008 ms |
95352 KB |
Output is correct |
9 |
Correct |
983 ms |
95420 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
979 ms |
95368 KB |
Output is correct |
3 |
Correct |
969 ms |
95352 KB |
Output is correct |
4 |
Correct |
980 ms |
95480 KB |
Output is correct |
5 |
Correct |
967 ms |
95352 KB |
Output is correct |
6 |
Correct |
989 ms |
95352 KB |
Output is correct |
7 |
Correct |
980 ms |
95480 KB |
Output is correct |
8 |
Correct |
1008 ms |
95352 KB |
Output is correct |
9 |
Correct |
983 ms |
95420 KB |
Output is correct |
10 |
Incorrect |
2794 ms |
235156 KB |
Output isn't correct |
11 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Incorrect |
42 ms |
2524 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Incorrect |
42 ms |
2524 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
979 ms |
95368 KB |
Output is correct |
3 |
Correct |
969 ms |
95352 KB |
Output is correct |
4 |
Correct |
980 ms |
95480 KB |
Output is correct |
5 |
Correct |
967 ms |
95352 KB |
Output is correct |
6 |
Correct |
989 ms |
95352 KB |
Output is correct |
7 |
Correct |
980 ms |
95480 KB |
Output is correct |
8 |
Correct |
1008 ms |
95352 KB |
Output is correct |
9 |
Correct |
983 ms |
95420 KB |
Output is correct |
10 |
Incorrect |
2794 ms |
235156 KB |
Output isn't correct |
11 |
Halted |
0 ms |
0 KB |
- |