QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#648199 | #5466. Permutation Compression | Repeater# | WA | 0ms | 3680kb | C++20 | 2.2kb | 2024-10-17 17:37:58 | 2024-10-17 17:37:58 |
Judging History
answer
#include<iostream>
using namespace std;
#include<vector>
#include<algorithm>
#include<set>
using i64 = long long;
vector<int> arr;
void update(int p){
for(int i = p; i < arr.size(); i += i & -i){
arr[i]++;
}
return;
}
int getsum(int p){
int sum = 0;
for(int i = p; i > 0; i -= i & -i){
sum += arr[i];
}
return sum;
}
int getsum(int l, int r){
return getsum(r) - getsum(l - 1);
}
void solve(){
int n, m, k;
cin >> n >> m >> k;
arr.resize(n + 2);
vector<int> a(n + 2), b(m + 1), p(n + 1);
a[0] = a[n + 1] = 1e9;
for(int i = 1; i <= n; ++i) {
cin >> a[i];
p[a[i]] = i;
arr[i] = 0;
}
for(int i = 1; i <= m; ++i) cin >> b[i];
multiset<int> s;
for(int i = 1; i <= k; ++i) {
int v = 0;
cin >> v;
s.insert(v);
}
if(k < n - m) {
cout << "NO\n";
return;
}
int tp = 1;
for(int i = 1; i <= m; ++i){
while(tp <= n && a[tp] != b[i]) ++tp;
}
if(tp == n + 1){
cout << "NO\n";
return;
}
s.insert(0), s.insert(1e9);
vector<bool> vis(n + 2);
for(int i = 1; i <= m; ++i){
vis[b[i]] = true;
}
vector<int> l(n + 2), r(n + 2, n + 1), stk(n + 2);
int t = -1;
for(int i = 0; i <= n + 1; ++i){
while(t != -1 && a[i] > a[stk[t]]) --t;
if(t != -1) l[i] = stk[t];
stk[++t] = i;
}
t = -1;
for(int i = n + 1; i >= 0; --i){
while(t != -1 && a[i] > a[stk[t]]) --t;
if(t != -1) r[i] = stk[i];
stk[++t] = i;
}
for(int i = 0; i <= n + 1; ++i){
if(vis[i]) l[p[i]] = r[p[i]] = p[i];
}
// for(int i = 0; i <= n + 1; ++i){
// cout << i << " " << l[i] << " " << r[i] << "\n";
// }
for(int i = n; i >= 1; --i){
if(!vis[i]){
int j = p[i];
l[j] = l[l[j]];
r[j] = r[r[j]];
int q = getsum(l[j] + 1, r[j] - 1);
auto t = prev(s.upper_bound(r[j] - l[j] - 1 - q));
//cout << i << " " << l[i] << " " << r[i] << " " << q << " " << (*t) << "\n";
if(*t == 0){
cout << "NO\n";
return;
}
else{
s.extract(*t);
update(j);
}
}
}
cout << "YES\n";
return;
}
int main(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
int t = 1;
cin >> t;
while(t--) solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3580kb
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: 0ms
memory: 3680kb
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:
NO YES YES YES YES YES YES YES NO YES YES NO 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 YES NO NO YES YES NO NO YES YES YES NO NO 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 NO YES YES YES...
result:
wrong answer 1st lines differ - expected: 'YES', found: 'NO'