이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "teams.h"
#include<bits/stdc++.h>
using namespace std;
#ifdef DEBUG
#include "/home/ioi/codes/ioi15_d1/debug.h"
#else
#define debug(...) void(37)
#endif
template<typename T>
vector<T> inverse_fuck(T* a, int N) {
vector<T> res(N);
for (int i = 0; i < N; ++i) {
res[i] = a[i];
}
return res;
}
namespace PST {
struct node {
node* l = NULL;
node* r = NULL;
int sum = 0;
};
node* modify(node* prev, int l, int r, int p) {
debug(l, r);
node* v = new node();
if (prev != NULL) {
v->l = prev->l;
v->r = prev->r;
v->sum = prev->sum;
}
v->sum += 1;
if (l < r) {
int mid = (l + r) >> 1;
if (p <= mid) {
v->l = modify(v->l, l, mid, p);
} else {
v->r = modify(v->r, mid + 1, r, p);
}
}
return v;
}
int get(node* v, int l, int r, int ll) {
if (v == NULL) {
return 0;
}
if (l >= ll) {
return v->sum;
}
int mid = (l + r) >> 1;
int res = 0;
if (ll <= mid) {
res += get(v->l, l, mid, ll);
}
res += get(v->r, mid + 1, r, ll);
return res;
}
}
struct SegTree {
int n;
vector<PST::node*> roots;
SegTree(int _n) : n(_n) {
roots.resize(1);
roots[0] = new PST::node();
}
SegTree() { }
PST::node* modify(int x) {
roots.push_back(PST::modify(roots.back(), 0, n - 1, x));
return roots.back();
}
int get(PST::node* v, int ll) {
return PST::get(v, 0, n - 1, ll);
}
};
int N;
vector<array<int, 2>> A;
SegTree st;
vector<PST::node*> vers;
vector<int> pt;
void init(int __N, int __A[], int __B[]) {
N = __N;
auto L = inverse_fuck(__A, N);
auto R = inverse_fuck(__B, N);
debug(N, L, R);
A.resize(N);
for (int i = 0; i < N; ++i) {
A[i] = array<int, 2>{L[i], R[i]};
}
sort(A.begin(), A.end());
debug(A);
st = SegTree(N + 1);
for (int i = 0; i < N; ++i) {
debug(i);
auto v = st.modify(A[i][1]);
if (i == N - 1|| A[i + 1][0] != A[i][0]) {
pt.push_back(A[i][0]);
vers.push_back(v);
}
}
}
int can(int M, int __K[]) {
auto K = inverse_fuck(__K, M);
sort(K.begin(), K.end());
debug(M, K);
vector<array<int, 2>> comp;
for (int i = 0; i < M; ++i) {
if (i == 0 || comp.back()[0] != K[i]) {
comp.push_back({K[i], 0});
}
comp.back()[1] += K[i];
}
auto Contains = [&](int l, int r) {
int from = int(lower_bound(pt.begin(), pt.end(), l + 1) - pt.begin()) - 1;
return (from == -1 ? 0 : st.get(vers[from], r));
};
debug(comp);
int mn = 0;
bool bad = false;
for (int i = 0; i < int(comp.size()); ++i) {
auto[x, s] = comp[i];
int me = Contains(x, x) - s;
bad |= me < 0;
if (i > 0) {
int prev = comp[i - 1][0];
mn += me - Contains(prev, x);
}
bad |= mn < 0;
}
return !bad;
}
# | 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... |