QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#212841 | #5466. Permutation Compression | zzzyzzz# | WA | 1ms | 7972kb | C++17 | 2.5kb | 2023-10-13 21:06:55 | 2023-10-13 21:06:55 |
Judging History
answer
#include<bits/stdc++.h>
#include<sstream>
#include<cassert>
#define fi first
#define se second
#define i128 __int128
using namespace std;
typedef long long ll;
typedef double db;
typedef pair<int,int> PII;
const double eps=1e-7;
const int N=5e5+7 ,M=5e5+7, INF=0x3f3f3f3f,mod=1e9+7,mod1=998244353;
const long long int llINF=0x3f3f3f3f3f3f3f3f;
inline ll read() {ll x=0,f=1;char c=getchar();while(c<'0'||c>'9') {if(c=='-') f=-1;c=getchar();}
while(c>='0'&&c<='9') {x=(ll)x*10+c-'0';c=getchar();} return x*f;}
inline void write(ll x) {if(x < 0) {putchar('-'); x = -x;}if(x >= 10) write(x / 10);putchar(x % 10 + '0');}
inline void write(ll x,char ch) {write(x);putchar(ch);}
void stin() {freopen("in_put.txt","r",stdin);freopen("my_out_put.txt","w",stdout);}
bool cmp0(int a,int b) {return a>b;}
template<typename T> T gcd(T a,T b) {return b==0?a:gcd(b,a%b);}
template<typename T> T lcm(T a,T b) {return a*b/gcd(a,b);}
void hack() {printf("\n----------------------------------\n");}
int T,hackT;
int n,m,k;
int w[N];
bool b[N];
struct Node{
int l,r;
int idx;
};
Node tr[N*4];
void pushup(int u) {
if(w[tr[u<<1].idx]>=w[tr[u<<1|1].idx]) tr[u].idx=tr[u<<1].idx;
else tr[u].idx=tr[u<<1|1].idx;
}
void build(int u,int l,int r) {
if(l==r) tr[u]={l,r,l};
else {
tr[u]={l,r};
int mid=l+r>>1;
build(u<<1,l,mid),build(u<<1|1,mid+1,r);
pushup(u);
}
}
int query(int u,int l,int r) {
if(tr[u].l>=l&&tr[u].r<=r) return tr[u].idx;
else {
int mid=tr[u].l+tr[u].r>>1;
if(l<=mid&&r>mid) {
int s1=query(u<<1,l,r),s2=query(u<<1|1,l,r);
if(w[s1]>=w[s2]) return s1;
else return s2;
}else if(l<=mid) return query(u<<1,l,r);
else return query(u<<1|1,l,r);
}
}
multiset<int> s;
bool flag;
void dfs(int l,int r) {
if(l>r) return ;
int ck=query(1,l,r);
if(!b[w[ck]]) {
int len=r-l+1;
auto it=s.lower_bound(-len);
if(it==s.end()) {
flag=false;
return ;
}else s.erase(it);
}
dfs(l,ck-1);
if(!flag) return ;
dfs(ck+1,r);
if(!flag) return ;
}
void solve() {
n=read(),m=read(),k=read();
for(int i=1;i<=n;i++) w[i]=read(),b[i]=false;
for(int i=1;i<=m;i++) b[read()]=true;
s.clear();
for(int i=1;i<=k;i++) s.insert(-read());
build(1,1,n);
flag=true;
dfs(1,n);
if(!flag) printf("NO\n");
else printf("YES\n");
}
int main() {
// init();
// stin();
// ios::sync_with_stdio(false);
scanf("%d",&T);
// T=1;
while(T--) hackT++,solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 7972kb
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: 1ms
memory: 5856kb
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 YES 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 Y...
result:
wrong answer 45th lines differ - expected: 'NO', found: 'YES'