QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#725241#5466. Permutation CompressionsyhyydsWA 1ms5940kbC++142.5kb2024-11-08 16:47:582024-11-08 16:48:03

Judging History

你现在查看的是最新测评结果

  • [2024-11-08 16:48:03]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:5940kb
  • [2024-11-08 16:47:58]
  • 提交

answer

#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <string>
#include <cstring>
#include <cmath>
#include <ctime>
#include <algorithm>
#include <utility>
#include <stack>
#include <queue>
#include <vector>
#include <set>
#include <math.h>
#include <map>
#include <sstream>
#include <deque>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <stdio.h>
#include <iostream>
#include <vector>
#include <queue>
#include <array>
#include <climits>
using namespace std;
#define   LL long long
#define ls o<<1
#define rs o<<1|1
#define PII pair<int,int>
#define PPI pair<pair<int,int>,int >
const int N=2e5+1000;
const LL  mod=998244353;
const LL MAX=1e9;
int n, m, k;
int a[N], b[N],pos[N],v[N];
set<int> p;
priority_queue<int> q1, q2;
int num[N];
int lowbit(int x) 
{
    return x & (-x);
}
void add(int x, int val)
{
    if (!x) return;
    while (x <= n)
    { 
        num[x] += val;
        x += lowbit(x);
    }
}
int sum(int x) 
{
    int ans = 0;
    while (x > 0) 
    {
        ans += num[x];
        x -= lowbit(x);
    }
    return ans;
}

void solve() 
{   
    p.clear();
    while (!q1.empty()) q1.pop();
    while (!q2.empty()) q2.pop();
    scanf("%d%d%d", &n, &m, &k);
    for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
    for (int i = 1; i <= m; i++) scanf("%d", &b[i]);
    for (int i = 1, x; i <= k; i++) scanf("%d", &x),q2.push(x);
    for (int i = 1; i <= n; i++) v[i] = 0,num[i] = 0,pos[a[i]] = i;
    for (int i = 1; i <= n; i++) add(i,1);
    int cx = 1;
    for (int i = 1; i <= n; i++)
        if (a[i] == b[cx]) cx++;
        else v[i] = 1;
    if (cx <= m) 
    {
        printf("NO\n");
        return;
    }
    p.insert(0);
    p.insert(n+1);
    for (int i = n; i >= 1; i--) 
    {
        int pp = pos[i];
        if (v[pp]) 
        {  
            auto it = p.lower_bound(pp);
            //cout << i << " " << pp << " " << *it - 1 << " " << *prev(it) <<" "<< sum(*it - 1) - sum(*prev(it)) << endl;
            q1.push(sum(*it-1)-sum(*prev(it)));
            add(pp, -1);
        }
        else  p.insert(pp);
    }
  /* while (!q1.empty())
        cout << q1.top()<<"******"<< endl, q1.pop();*/
    while (!q1.empty() && !q2.empty())
    {    int w=q2.top();
          q2.pop();
          if (q1.top()>= w) q1.pop();
    }
    if (!q1.empty())
        printf("NO\n");
    else 
        printf("YES\n");
    return;
}
int main()    
{ 
    
    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: 1ms
memory: 5816kb

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: 0
Accepted
time: 1ms
memory: 5868kb

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
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
YE...

result:

ok 100 lines

Test #3:

score: -100
Wrong Answer
time: 0ms
memory: 5940kb

input:

99
6 1 6
1 5 3 4 2 6
1
1 2 1 1 1 6
1 1 1
1
1
1
4 1 3
3 4 1 2
1
1 1 2
2 2 1
2 1
2 1
2
1 1 1
1
1
1
2 1 2
1 2
2
1 2
1 1 1
1
1
1
1 1 1
1
1
1
3 2 2
3 2 1
2 1
1 2
3 3 1
2 3 1
2 3 1
1
6 1 5
3 4 2 5 6 1
3
4 2 1 1 1
6 4 4
1 6 5 2 3 4
1 2 3 4
5 4 4 6
2 1 1
1 2
1
1
6 5 1
2 1 4 5 6 3
2 1 4 6 3
2
6 3 6
5 6 2 1 3...

output:

YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
NO
NO
YES
YES
YES
YES
YES
YES
YES
YES
YES
NO
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
NO
YES
YES
YES
YES
YES
YES
YES
YES
NO
YES
YES
YES
NO
YES
YES
YES
NO
YES
YES
NO
YES
NO
YES
NO
YES
YES
YES
YES
YES
YES
NO
YES
NO
NO
YES
YES
YES
Y...

result:

wrong answer 49th lines differ - expected: 'NO', found: 'YES'