이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "robots.h"
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define f1 first
#define s2 second
using ii = pair<int, int>;
const int MAX = 5e4 + 69;
const int inf = 1e9 + 69;
struct Segtree
{
int n, st[1 << 17], lz[1 << 17];
Segtree() {}
Segtree (int n_, int ar[]) : n(n_)
{
memset(lz, 0, sizeof(lz));
const auto build = [&](const auto &self, int node, int l, int r) -> void
{
if (l == r)
{
st[node] = ar[l];
return;
}
int mid = (l + r) >> 1;
self(self, node << 1, l, mid);
self(self, node << 1 | 1, mid+1, r);
st[node] = min(st[node << 1], st[node << 1 | 1]);
};
build(build, 1, 0, n-1);
}
inline void propagate(int node, int l, int r)
{
st[node] += lz[node];
if (l < r)
{
lz[node << 1] += lz[node];
lz[node << 1 | 1] += lz[node];
}
lz[node] = 0;
}
inline void add(int p, int q, int val)
{
const auto add_ = [&](const auto &self, int node, int l, int r) -> void
{
propagate(node, l, r);
if (l > q || r < p)
return;
if (p <= l && r <= q)
{
lz[node] += val;
propagate(node, l, r);
return;
}
int mid = (l + r) >> 1;
self(self, node << 1, l, mid);
self(self, node << 1 | 1, mid+1, r);
st[node] = min(st[node << 1], st[node << 1 | 1]);
};
add_(add_, 1, 0, n-1);
}
inline int query(int p, int q)
{
const auto query_ = [&](const auto &self, int node, int l, int r) -> int
{
propagate(node, l, r);
if (l > q || r < p)
return inf;
if (p <= l && r <= q)
return st[node];
int mid = (l + r) >> 1;
return min(self(self, node << 1, l, mid), self(self, node << 1 | 1, mid+1, r));
};
return query_(query_, 1, 0, n-1);
}
} st;
int putaway(int A, int B, int T, int X[], int Y[], int W[], int S[])
{
if (A > B)
swap(A, B), swap(X, Y), swap(W, S);
sort(X, X+A);
sort(Y, Y+B);
for (int i = 0; i < T; ++i)
{
if ((A == 0 || X[A-1] <= W[i]) && (B == 0 || Y[B-1] <= S[i]))
return -1;
}
vector<ii> vec;
for (int i = 0; i < T; ++i)
{
int p = (int)(upper_bound(X, X+A, W[i]) - X);
int q = (int)(upper_bound(Y, Y+B, S[i]) - Y);
vec.pb({p, q});
}
sort(vec.rbegin(), vec.rend());
int ar[MAX];
const auto check = [&](int val) -> bool
{
// ar[A] = 0;
// for (int i = A-1; i >= 0; --i)
// ar[i] = min(inf, ar[i+1] + val);
// st = Segtree(A+1, ar);
for (int i = 0; i <= B; ++i)
ar[i] = 0;
for (int i = 0, ctr = 0; i < T; ++i)
{
// if (st.query(0, vec[i].f1) > 0)
// st.add(0, vec[i].f1, -1);
if (ctr < 1ll * (A - vec[i].f1) * val)
ctr++;
else ar[0]++, ar[vec[i].s2 + 1]--;
}
for (int i = 1; i <= B; ++i)
ar[i] += ar[i-1];
for (int i = 0; i <= B; ++i)
if (ar[i] > 1ll * (B-i) * val)
return false;
return true;
};
int l = 1, r = T;
while (l < r)
{
int mid = (l + r) >> 1;
if (check(mid)) r = mid;
else l = mid + 1;
}
return l;
}
# | 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... |