QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#187787#5466. Permutation CompressionCokeWA 1ms3492kbC++142.1kb2023-09-24 22:31:582023-09-24 22:31:58

Judging History

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

  • [2023-09-24 22:31:58]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3492kb
  • [2023-09-24 22:31:58]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#define int long long
#define debug(x) cerr<<#x<<' '<<x<<endl;
typedef pair<int, int>PII;
typedef long long LL;
constexpr int N = 200010, mod = 1e9 + 7;
int a[N], b[N], l[N], pre[N], pos[N];
int tr[N];
int lowbit(int x)
{
    return x & -x;
}
void add(int x, int va)
{
    for(int i = x; i < N; i += lowbit(i))tr[i] += va;
}
int sum(int x)
{
    int res = 0;
    for(int i = x; i; i -= lowbit(i))res += tr[i];
    return res;
}


signed main()
{
    //freopen(".in","r",stdin);freopen(".out","w",stdout);
    ios::sync_with_stdio(0);
    cin.tie(0), cout.tie(0);
    int t;
    cin >> t;
    while(t--)
    {
        int n, m, k;
        cin >> n >> m >> k;
        for(int i=1;i<=n;i++)tr[i]=0;
        for(int i = 1; i <= n; i++)cin >> a[i], pos[a[i]] = i, add(i, 1);
        set<int>s1;
        multiset<int>s2;
        for(int i = 1; i <= m; i++)cin >> b[i], s1.insert(b[i]);

        for(int i = 1; i <= k; i++)cin >> l[i], s2.insert(l[i]);
        set<int>s;
        s.insert(0);
        s.insert(n + 1);
        int flag = 1;
        for(int i = 1, j = 1; i <= m; i++)
        {
            while(j <= n && a[j] != b[i])j++;
            if(j > n)
            {
                flag = 0;
                break;
            }
        }
        if(flag == 0)
        {
            cout << "NO" << endl;
            continue;
        }
        int f = 1;
        for(int i = n; i >= 1; i--)
        {
            if(s1.count(i))
            {
                s.insert(pos[i]);
                continue;
            }
            auto p = s.lower_bound(pos[i]);
            int l = *(prev(p)), r = *p;
            int len = sum(r - 1) - sum(l);
            auto it = s2.upper_bound(len);
            add(pos[i], -1);
            if(it == s2.begin())
            {
                f = 0;
                break;
            }
            it--;

            s2.erase(it);
            s.insert(pos[i]);
        }
        if(f)cout << "YES" << endl;
        else cout << "NO" << endl;



    }

}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 3460kb

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: 3492kb

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:

wrong answer 82nd lines differ - expected: 'YES', found: 'NO'