QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#793399 | #5466. Permutation Compression | guodong# | RE | 0ms | 3564kb | C++14 | 3.6kb | 2024-11-29 19:28:28 | 2024-11-29 19:28:30 |
Judging History
answer
#include <bits/stdc++.h>
#define int long long
using namespace std;
class sgt{
#define ls (pos << 1)
#define rs (ls | 1)
#define mid ((l + r) >> 1)
public:
int n;
vector<int> a;
sgt(int _n){
n = _n;
a.resize(4 * n + 4);
}
void pu(int pos){
a[pos] = a[ls] + a[rs];
}
void update(int pos,int l,int r,int x,int v){
if(l == r){
a[pos] += v;
return;
}
if(x <= mid){
update(ls,l,mid,x,v);
}
if(x > mid)
update(rs,mid + 1,r,x,v);
pu(pos);
}
int query(int pos,int l,int r,int ql,int qr){
if(ql > qr) return 0;
if(ql <= l && r <= qr)
return a[pos];
int ans = 0;
if(ql <= mid)
ans += query(ls,l,mid,ql,qr);
if(qr > mid)
ans += query(rs,mid + 1,r,ql,qr);
return ans;
}
void fix(int pos,int v){
update(1,1,n,pos,v);
}
};
#define For(i,a,b) for(int i = a; i <= b; ++i)
signed main(){
#ifndef ONLINE_JUDGE
freopen("data.in","r",stdin);
#endif
int T;
ios::sync_with_stdio(false);
cin >> T;
while(T--){
int n,m,k;
cin >> n >> m >> k;
vector<pair<int,int>> p(n);
vector<int> t(n + 1);
vector<int> loc(n + 1), tar(n + 1);
For(i,0,n - 1){
cin >> p[i].first;
p[i].second = i + 1;
loc[p[i].first] = i + 1;
}
int wtf = 0;
For(i,1,m){
int x;
cin >> x;
tar[i] = x;
if(loc[x] <= loc[tar[i - 1]]){
wtf =1;
break;
}
t[x] = 1;
}
if(wtf){
cout << "NO" << '\n';
continue;
}
multiset<int> L;
For(i,1,k){
int x;
cin >> x;
L.insert(x);
}
if(n - m > k){
cout << "NO" << '\n';
continue;
}
sort(p.begin(),p.end(),[&](auto a,auto b){return a.first > b.first;});
sgt st = sgt(n);
For(i,1,n)
st.fix(i,1);
set<int> S;
int flag = 0;
For(i,0,n - 1){
int x = p[i].first;
if(t[x]){
S.insert(p[i].second);
st.fix(p[i].second,-1);
}
else{
auto it = S.lower_bound(p[i].second);
int l,r;
if(it == S.end())
r = n;
else
r = *it;
if(it == S.begin()){
l = 1;
}
else{
it--;
l = *it;
}
int maxx = st.query(1,1,n,l,r);
// cout << p[i].second << " " << maxx << '\n';
it = L.upper_bound(maxx);
if(it == L.begin()){
flag = 1;
break;
}
else{
it--;
if(*it > maxx){
flag = 1;
break;
}
L.erase(it);
}
st.fix(p[i].second,-1);
}
}
if(!flag)
cout << "YES" << '\n';
else
cout << "NO" << '\n';
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3564kb
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
Runtime Error
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 NO NO