QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#249105 | #5466. Permutation Compression | joelgun14 | WA | 0ms | 3788kb | C++14 | 2.8kb | 2023-11-12 00:53:49 | 2023-11-12 00:53:49 |
Judging History
answer
#include <bits/stdc++.h>
#define LL long long
#define fi first
#define se second
#define mp make_pair
using namespace std;
LL psum[200005];
LL n,m,k;
void ins(LL x)
{
for(LL a=x;a<=n;a+=(a&-a))psum[a]++;
}
LL query(LL x)
{
LL tot=0;
for(LL a=x;a>=1;a-=(a&-a))tot+=psum[a];
return tot;
}
LL query2(LL x,LL y)
{
return query(y)-query(x-1);
}
void solve(){
scanf("%lld %lld %lld",&n,&m,&k);
for(LL a=1;a<=n;a++)psum[a]=0;
LL pos[n+5],arr[n+5],brr[m+5],l[k+5];
bool temp[n+5];
memset(temp,0,sizeof(temp));
for(LL a=1;a<=n;a++)
{
scanf("%lld",&arr[a]);
pos[arr[a]]=a;
}
for(LL a=1;a<=m;a++)
{
scanf("%lld",&brr[a]);
temp[brr[a]]=1;
}
vector<LL>ada;
multiset<LL>line;
set<LL>isi;
for(LL a=1;a<=k;a++){
scanf("%lld",&l[a]);
line.insert(l[a]);
}
if(n-m>k){
printf("tidak\n");
return;
}
LL left=1;
for(LL a=1;a<=m;a++)
{
while(true){
if(left==n+1){
printf("tidak\n");
return;
}
if(arr[left]==brr[a]){
left++;
break;
}
left++;
}
}
for(LL a=n;a>=1;a--){
// printf("a=%lld\n",a);
// printf("line : ");
// for(LL v:line)cout<<v;
// cout<<endl;
// printf("isi :");
// for(LL v:isi)cout<<v;
// cout<<endl;
if(temp[a])isi.insert(pos[a]);
else{
if(line.size()==0){
printf("tidak\n");
return;
}
if(isi.size()==0){
// printf("SATU");
auto atas=line.upper_bound(a);
if(atas==line.begin())
{
printf("tidak\n");
return;
}
line.erase(line.find(*(--atas)));
ins(pos[a]);
// isi.insert(pos[a]);
continue;
}
auto atas = isi.lower_bound(pos[a]);
if(atas==isi.end()){
// printf("DUA\n");
LL jeje=*(--atas);
LL banyak=n-jeje;
banyak-=query2(jeje,n);
auto koko=line.upper_bound(banyak);
if(koko==line.begin()){
printf("tidak\n");
return;
}
--koko;
line.erase(line.find(*koko));
}
else if(atas==isi.begin()){
// printf("TIGA\n");
LL banyak=*atas;
banyak--;
banyak-=query2(1,banyak);
auto koko=line.upper_bound(banyak);
if(koko==line.begin()){
printf("tidak\n");
return;
}
--koko;
line.erase(line.find(*koko));
}
else
{
// printf("EMPAT\n");
LL banyak=*atas;
// printf("banyak=%lld\n",banyak);
LL astaga=*(--atas);
// printf("astaga=%lld\n",astaga);
banyak =banyak-astaga-1;
banyak-=query2(banyak,astaga);
// printf("Banyak=%lld\n",banyak);
auto koko=line.upper_bound(banyak);
if(koko==line.begin()){
printf("tidak\n");
return;
}
--koko;
line.erase(line.find(*koko));
}
ins(pos[a]);
}
}
printf("ya\n");
}
int main()
{
LL tc;
scanf("%lld",&tc);
while(tc--)
{
solve();
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 3788kb
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:
ya ya tidak
result:
wrong answer 1st lines differ - expected: 'YES', found: 'ya'