QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#153287 | #5466. Permutation Compression | inverno | WA | 2ms | 5472kb | C++14 | 2.2kb | 2023-08-29 20:37:36 | 2023-08-29 20:37:37 |
Judging History
answer
#include<bits/stdc++.h>
#define wr(a,b) cout << a << " " << b << endl
using namespace std;
const int N = 2e5+4;
int n, m, k;
int a[N], b[N], mp[N];
int tr[N];
bool bp[N];
set<int> tools, larg;
void add(int x, int w){
for (;x <= n;x+=(x&-x)) {
tr[x] += w;
}
return ;
}
int sum(int x) {
int w = 0;
for (;x > 0;x-=(x&-x)) {
w += tr[x];
}
return w;
}
int main(){
ios::sync_with_stdio(false); cin.tie(0);
int tcase = 0;
cin >> tcase;
while(tcase --) {
tools.clear(); larg.clear();
bool boo = false;
cin >> n >> m >> k;
for (int i = 1;i <= n;++ i) {
bp[i] = tr[i] = 0;
cin >> a[i];
mp[a[i]] = i;
}
for (int i = 1;i <= m;++ i) {
cin >> b[i];
bp[b[i]] = 1;
if (i > 1) {
if (mp[b[i]] < mp[b[i-1]]) {
boo = true;
}
}
}
for (int i = 1;i <= k;++ i) {
int t;
cin >> t;
tools.insert(t);
}
larg.insert(0); larg.insert(n+1);
for (int w = n;w >= 1;-- w){
int p = mp[w], l, r, num;
if (!bp[w]) {
auto it0 = larg.lower_bound(p);
l = *(prev(it0)); r = *it0;
num = sum(r-1) - sum(l) + (r-1) - l;
auto it = tools.upper_bound(num);
if (it == tools.begin()) {
boo = 1;
break;
}
tools.erase(--it);
add(p, -1);
}
else {
larg.insert(p);
}
}
if (!boo) {
cout << "YES\n";
}
else {
cout << "NO\n";
}
}
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 1ms
memory: 5472kb
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: 2ms
memory: 5452kb
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 NO NO YES YES YES YES YES YES YES YES YES YES YES YES YES NO YES YES YES NO YES YES YES YES NO YES YES YES YES YES NO NO YES YES YES NO NO NO NO YES NO NO YES YES YES YES YES NO YES NO YES NO YES NO NO YES YES YES YES YES YES NO YES YES YES YES YES YES YES NO YES YES YES YES YES YES YES ...
result:
wrong answer 4th lines differ - expected: 'YES', found: 'NO'