QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#648822 | #5466. Permutation Compression | Repeater | WA | 1ms | 3588kb | C++20 | 4.1kb | 2024-10-17 20:33:03 | 2024-10-17 20:33:09 |
Judging History
answer
#include <bits/stdc++.h>
constexpr int INF = 1e9;
template<class Info>
struct SegmentTree
{
int n;
std::vector<Info> info;
SegmentTree() : n(0) {}
SegmentTree(int n_, Info v_ = Info())
{
init(n_, v_);
}
template<class T>
SegmentTree(std::vector<T> init_)
{
init(init_);
}
void init(int n_, Info v_ = Info())
{
init(std::vector(n_, v_));
}
template<class T>
void init(std::vector<T> init_)
{
n = init_.size();
info.assign(4 << std::__lg(n), Info());
std::function<void(int, int, int)> build = [&](int p, int l, int r)
{
if(r - l == 1)
{
info[p] = init_[l];
return;
}
int mid = (l + r) >> 1;
build(p << 1, l, mid);
build(p << 1 | 1, mid, r);
pull(p);
};
build(1, 0, n);
}
void pull(int p)
{
info[p] = info[p << 1] + info[p << 1 | 1];
}
void modify(int p, int l, int r, int x, const Info &v)
{
if(r - l == 1)
{
info[p] = v;
return;
}
int mid = (l + r) >> 1;
if(x < mid) modify(p << 1, l, mid, x, v);
else modify(p << 1 | 1, mid, r, x, v);
pull(p);
}
void modify(int p, const Info &v)
{
modify(1, 0, n, p, v);
}
Info rangeQuery(int p, int l, int r, int x, int y)
{
if(l >= y || r <= x) return Info();
if(l >= x && r <= y) return info[p];
int mid = (l + r) >> 1;
return rangeQuery(p << 1, l, mid, x, y) + rangeQuery(p << 1 | 1, mid, r, x, y);
}
Info rangeQuery(int l, int r)
{
return rangeQuery(1, 0, n, l, r);
}
template<class F>
int findFirst(int p, int l, int r, int x, int y, F pred)
{
if(l >= y || r <= x || !pred(info[p])) return -1;
if(r - l == 1) return l;
int mid = (l + r) >> 1;
int res = findFirst(p << 1, l, mid, x, y, pred);
if(res == -1) res = findFirst(p << 1 | 1, mid, r, x, y, pred);
return res;
}
template<class F>
int findFirst(int l, int r, F pred)
{
return findFirst(1, 0, n, l, r, pred);
}
template<class F>
int findLast(int p, int l, int r, int x, int y, F pred)
{
if(l >= y || r <= x || !pred(info[p])) return -1;
if(r - l == 1) return l;
int mid = (l + r) >> 1;
int res = findLast(p << 1 | 1, mid, r, x, y, pred);
if(res == -1) res = findLast(p << 1, l, mid, x, y, pred);
return res;
}
template<class F>
int findLast(int l, int r, F pred)
{
return findLast(1, 0, n, l, r, pred);
}
};
struct Info
{
int max = 0;
int cnt = 0;
};
Info operator+(Info a, Info b)
{
return {std::max(a.max, b.max), a.cnt + b.cnt};
}
int cnt;
void solve()
{
cnt++;
int n, m, k; std::cin >> n >> m >> k;
std::vector<int> a(n + 2), b(m), vis(n + 1);
for(int i = 1; i <= n; i++) std::cin >> a[i];
for(int i = 0; i < m; i++) std::cin >> b[i], vis[b[i]] = 1;
std::vector<std::pair<int, int>> v;
for(int i = 1; i <= n; i++) if(!vis[a[i]])
v.emplace_back(a[i], i);
std::ranges::sort(v, std::greater());
a[0] = a[n + 1] = INF;
std::vector<Info> init(n + 2);
for(int i = 0; i <= n + 1; i++) init[i] = {a[i], 0};
SegmentTree<Info> segt(init);
std::multiset<int> L;
L.emplace(0);
for(int i = 0; i < k; i++)
{
int x; std::cin >> x;
L.emplace(x);
}
if(cnt == 45)
{
std::cout << n << " " << m << " " << k << "\n";
for(int i = 1; i <= n; i++) std::cout << a[i] << " \n"[i == n];
for(int i = 0; i < m; i++) std::cout << b[i] << " \n"[i == m - 1];
for(auto i : L) if(i) std::cout << i << " ";
std::cout << "\n";
}
for(auto [x, pos] : v)
{
int r = segt.findFirst(pos, n + 2, [&](Info info) -> bool
{
return info.max > x;
});
int l = segt.findLast(0, pos, [&](Info info) -> bool
{
return info.max > x;
});
int len = r - l - 1 - segt.rangeQuery(l, r).cnt;
if(L.empty())
{
std::cout << "NO\n";
return;
}
auto it = *std::prev(L.upper_bound(len));
if(it == 0)
{
std::cout << "NO\n";
return;
}
L.extract(it);
segt.modify(pos, {0, 1});
}
std::cout << "YES\n";
}
int main()
{
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
int t; std::cin >> t;
while(t--) solve();
return 0;
}
/*
1
2 1 1
1 2
1
2
*/
詳細信息
Test #1:
score: 100
Accepted
time: 1ms
memory: 3584kb
input:
3 5 2 3 5 1 3 2 4 5 2 1 2 4 5 5 5 1 2 3 4 5 1 2 3 4 5 1 2 3 4 5 3 2 2 3 1 2 3 2 2 3
output:
YES YES NO
result:
ok 3 lines
Test #2:
score: -100
Wrong Answer
time: 1ms
memory: 3588kb
input:
100 2 1 2 2 1 2 1 1 2 1 2 1 2 1 2 2 2 1 1 1 2 1 2 6 1 5 3 4 2 5 6 1 3 5 2 1 1 1 6 1 6 2 1 3 6 4 5 1 4 1 2 2 1 4 3 3 2 2 1 3 2 1 3 2 2 1 1 1 1 1 1 1 1 1 1 1 1 2 1 2 2 1 2 1 2 4 4 3 2 1 3 4 2 1 3 4 4 3 1 1 1 1 1 1 1 6 5 1 6 2 5 4 3 1 6 2 4 3 1 4 1 1 1 1 1 1 6 5 3 3 6 1 4 5 2 3 6 1 4 2 3 3 4 4 3 4 3 4 ...
output:
YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES NO YES YES YES YES NO YES YES YES YES YES YES YES YES YES YES NO NO NO YES YES NO 3 3 2 3 2 1 2 3 1 3 3 YES YES YES YES YES YES YES YES YES YES YES YES YES NO YES YES YES YES YES YES NO YES YES YES YES YES YES Y...
result:
wrong answer 45th lines differ - expected: 'NO', found: '3 3 2'