QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#217740#5466. Permutation Compressiontien_noobWA 1ms5492kbC++202.6kb2023-10-17 11:43:032023-10-17 11:43:04

Judging History

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

  • [2023-10-17 11:43:04]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:5492kb
  • [2023-10-17 11:43:03]
  • 提交

answer

//Make CSP great again
//Vengeance
#include <bits/stdc++.h>
#define TASK "TESTCODE"
using namespace std;
const int N = 2e5;
int a[N + 1], b[N + 1], pos[N + 1], n, m, k;
bool del[N + 1];
multiset<int> f;
set<pair<int, int> > pivot;
struct FenwickTree
{
    int tree[N + 1];
    void reset()
    {
        fill(tree, tree + n + 1, 0);
    }
    void add(int pos, int val)
    {
        for (; pos <= n; pos |= pos + 1)
        {
            tree[pos] += val;
        }
    }
    int sum(int pos)
    {
        int ret = 0;
        for (; pos >= 0; pos = (pos & (pos + 1)) - 1)
        {
            ret += tree[pos];
        }
        return ret;
    }
    int sum(int l, int r)
    {
        return sum(r) - sum(l - 1);
    }
} tree;
void read()
{
    f.clear();
    pivot.clear();
    cin >> n >> m >> k;
    for (int i = 1; i <= n; ++ i)
    {
        cin >> a[i];
        pos[a[i]] = i;
        del[i] = true;
        tree.add(i, 1);
    }
    for (int i = 1; i <= m; ++ i)
    {
        cin >> b[i];
        del[b[i]] = false;
    }
    for (int i = 1; i <= k; ++ i)
    {
        int x;
        cin >> x;
        f.insert(x);
    }
}
void solve()
{
    for (int i = 2; i <= m; ++ i)
    {
        if (pos[b[i]] < pos[b[i - 1]])
        {
            cout << "NO" << '\n';
            return ;
        }
    }
    pivot.insert({1, n});
    for (int i = n; i >= 1; -- i)
    {
        auto it = pivot.upper_bound({pos[i], 1e9});
        --it;
        int l = it->first, r = it->second;
        if (!del[i])
        {
            pivot.erase(it);
            if (l < pos[i])
            {
                pivot.insert({l, pos[i] - 1});
            }
            if (r > pos[i])
            {
                pivot.insert({pos[i] + 1, r});
            }
        }
        else
        {
            int sum = tree.sum(l, r);
            auto it2 = f.upper_bound(sum);
            if (f.empty() || it2 == f.begin())
            {
                cout << "NO" << '\n';
                return ;
            }
            --it2;
            f.erase(it2);
        }
        tree.add(pos[i], -1);
    }
    cout << "YES" << '\n';
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    if (fopen(TASK".INP", "r"))
    {
        freopen(TASK".INP", "r", stdin);
        //freopen(TASK".OUT", "w", stdout);
    }
    int t = 1;
    bool typetest = true;
    if (typetest)
    {
        cin >> t;
    }
    for (int __ = 1; __ <= t; ++ __)
    {
        //cout << "Case " << __ << ": ";
        read();
        solve();
    }
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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

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
YES
NO
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
...

result:

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