QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#627948 | #5466. Permutation Compression | laonongmin | WA | 1ms | 5704kb | C++17 | 2.2kb | 2024-10-10 17:47:19 | 2024-10-10 17:47:19 |
Judging History
answer
#pragma GCC optimize(3)
#include <bits/stdc++.h>
#define ll long long
#define pii pair<int,int>
#define N 200005
#define MOD 998244353
using namespace std;
int n,m,k;
int a[N],l[N];
int nxt[N], pre[N];
void del(int i)
{
pre[nxt[i]] = pre[i];
nxt[pre[i]] = nxt[i];
}
void solve()
{
cin>>n>>m>>k;
priority_queue<pii> q;
multiset<int> s;
bool ok = true;
for(int i=1;i<=n;++i) {cin>>a[i]; l[i]=1; nxt[i]=i+1; pre[i]=i-1;}
for(int i=1,j=1;i<=m;++i,++j)
{
int b; cin>>b;
while(j<=n && b!=a[j])
{
q.push({a[j], j});
++j;
}
if(j>n) ok = false;
}
for(int i=1;i<=k;++i)
{
int x; cin>>x;
s.insert(x);
}
if(!ok) {cout<<"NO\n"; return;}
stack<pii> stk;
a[n+1] = a[0] = n+1;
for(int i=1;i<=n+1;++i)
{
while(!stk.empty() && stk.top().first<a[i])
{
int j = stk.top().second;
l[j] += i-j-1;
stk.pop();
}
stk.push({a[i], i});
}
while(!stk.empty()) stk.pop();
for(int i=n;i>=0;--i)
{
while(!stk.empty() && stk.top().first<a[i])
{
int j = stk.top().second;
l[j] += j-i-1;
stk.pop();
}
stk.push({a[i], i});
}
while(!stk.empty()) stk.pop();
while(!q.empty())
{
auto [x,i] = q.top();
q.pop();
auto it = s.upper_bound(l[i]);
if(it == s.begin()) {cout<<"NO\n"; return;}
s.erase(--it);
del(i);
if(pre[i] && nxt[i])
{
if(a[pre[i]] < a[nxt[i]])
{
int pos=nxt[i];
int j=pos;
while(pre[j] && a[pre[j]]<a[pos]) ++l[pos], j=pre[j];
}
else
{
int pos=pre[i];
int j=pos;
while(nxt[j] && a[nxt[j]]<a[pos]) ++l[pos], j=nxt[j];
}
}
}
cout<<"YES\n";
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
int T;
cin>>T;
while(T--)
{
solve();
}
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 3520kb
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: 5704kb
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 YES YES YES YES YES YES YES YES YES YES YES NO YES 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 YES YES YES YES YES...
result:
wrong answer 28th lines differ - expected: 'NO', found: 'YES'