QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#655024 | #5466. Permutation Compression | tz3528 | WA | 1ms | 3804kb | C++23 | 1.7kb | 2024-10-18 23:51:05 | 2024-10-18 23:51:06 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int N = 2e5 + 10;
int tr[N];
int n, m, k;
int lowbit(int x) {
return x & -x;
}
void add(int pos, int d) {
if(pos <= 0) return ;
for(int i = pos; i <= n; i += lowbit(i)) {
tr[i] += d;
}
}
int query(int pos) {
int res = 0;
if(pos <= 0) return 0;
for(int i = pos; i; i -= lowbit(i)) {
res += tr[i];
}
return res;
}
void solve() {
cin >> n >> m >> k;
std::vector<int> pos(n + 1), has(n + 1);
for(int i = 1, x; i <= n; i ++ ) {
cin >> x;
pos[x] = i;
}
vector<int> a(m + 1);
for(int i = 1, x; i <= m; i ++ ) {
cin >> x;
has[x] = 1;
a[i] = x;
}
int flag=0;
for(int i = 1; i < m; i ++ ) {
if(pos[a[i + 1]] < pos[a[i]]) {
flag=1;
}
}
multiset<int> st;
st.insert(0);
st.insert(n + 1);
for(int i = 1, x; i <= k; i ++ ) {
cin >> x;
st.insert(x);
}
if(flag){
cout<<"NO\n";
return ;
}
set<int> p;
p.insert(0);
p.insert(n + 1);
bool fg = 0;
vector<int> need_del(n + 1);
for(int i = n; i >= 1; i -- ) {
if(!has[i]) {
auto it = p.upper_bound(pos[i]);
int l = *prev(it), r = *it;
int w = r - l - 1-(query(r)-query(l));
auto it2 = prev(st.upper_bound(w));
if(*it2 == 0) {
fg = 1;
break;
} else {
// cout<<pos[i]<<endl;
add(pos[i],1);
st.erase(it2);
}
} else {
p.insert(pos[i]);
}
}
for(int i=1;i<=n+1;i++) tr[i]=0;
if(fg) {
cout << "NO\n";
} else {
cout << "YES\n";
}
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0), cout.tie(0);
int t = 1;
cin >> t;
while(t -- ) {
solve();
}
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3804kb
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: 0
Accepted
time: 1ms
memory: 3476kb
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 NO 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 YES NO YES YES YES YES YE...
result:
ok 100 lines
Test #3:
score: -100
Wrong Answer
time: 0ms
memory: 3624kb
input:
99 6 1 6 1 5 3 4 2 6 1 1 2 1 1 1 6 1 1 1 1 1 1 4 1 3 3 4 1 2 1 1 1 2 2 2 1 2 1 2 1 2 1 1 1 1 1 1 2 1 2 1 2 2 1 2 1 1 1 1 1 1 1 1 1 1 1 1 3 2 2 3 2 1 2 1 1 2 3 3 1 2 3 1 2 3 1 1 6 1 5 3 4 2 5 6 1 3 4 2 1 1 1 6 4 4 1 6 5 2 3 4 1 2 3 4 5 4 4 6 2 1 1 1 2 1 1 6 5 1 2 1 4 5 6 3 2 1 4 6 3 2 6 3 6 5 6 2 1 3...
output:
YES YES YES YES YES YES YES YES YES YES YES YES YES YES NO NO YES YES YES YES YES YES YES YES YES NO YES YES YES YES YES YES YES YES YES YES YES YES YES YES NO YES YES YES YES YES YES YES YES NO YES YES YES NO YES YES YES NO YES YES NO YES NO YES NO YES YES YES YES YES YES NO YES NO NO YES YES YES Y...
result:
wrong answer 49th lines differ - expected: 'NO', found: 'YES'