QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#429515#5466. Permutation Compression36champWA 2ms6952kbC++203.1kb2024-06-02 16:21:522024-06-02 16:21:53

Judging History

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

  • [2024-06-02 16:21:53]
  • 评测
  • 测评结果:WA
  • 用时:2ms
  • 内存:6952kb
  • [2024-06-02 16:21:52]
  • 提交

answer

#include <bits/stdc++.h>
#define ll long long
#define pb push_back

using namespace std;

int MAXN = 2e5, n;
vector<int> t(4 * MAXN + 5);
vector<int> a(MAXN);

void build(vector<int> &a, int v, int tl, int tr)
{
    if(tl == tr)
    {
        t[v] = tl;
        return;
    }

    int tm = (tl + tr) / 2;
    build(a, 2 * v, tl, tm);
    build(a, 2 * v + 1, tm + 1, tr);

    if(a[t[2 * v]] > a[t[2 * v+  1]]) t[v] = t[2 * v];
    else t[v] = t[2 * v + 1];
}

int query(int v, int tl, int tr, int l, int r)
{
    if (l > r)
        return -1;
    if (l == tl && r == tr) {
        return t[v];
    }
    int tm = (tl + tr) / 2;

    int x1 = query(v*2, tl, tm, l, min(r, tm)), x2 = query(v*2+1, tm+1, tr, max(l, tm+1), r);

    if(x1 == -1 || x2 == -1) return x1 + x2 + 1;

    if(a[x1] > a[x2]) return x1;
    else return x2;
}

void build_graph(vector<vector<int>> & adj, int p, int l, int r)
{
    //cout << "Build " << p << " " << l << " " << r << " ";

    if(l >= r) return;
    int x = query(1, 0, n - 1, l, p - 1);
    int y = query(1, 0, n - 1, p + 1, r);

    //cout << " = " << x << " " << y << "\n";
    //getchar();

    if(x != -1)
    {
        adj[p].pb(x);
        build_graph(adj, x, l, p - 1);
    }
    if(y != -1)
    {
        adj[p].pb(y);
        build_graph(adj, y, p + 1, r);
    }
}

void dfs(int p, vector<vector<int>> &adj, vector<int> & v)
{
    for(int c: adj[p])
    {
        dfs(c, adj, v);
        v[p] += v[c];
    }
}

int main()
{
    ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);

	int T = 1;
	cin >> T;
    while(T-->0)
    {
        int m, k;
        cin >> n >> m >> k;

        vector<int> b(m);
        vector<int> d(k);
        vector<int> pos(n + 1);
        vector<vector<int>> adj(n + 1);

        for(int i=0; i<n; i++)
        {
            cin >> a[i];
            pos[a[i]] = i;
        }
        for(int i=0; i<m; i++) cin >> b[i];
        for(int i=0; i<k; i++) cin >> d[i];

        build(a, 1, 0, n - 1);

        /*for(int i = 0; i < 4 * n + 1; i++) cout << t[i] << " ";
        cout << "\n";*/

        build_graph(adj, pos[n], 0, n - 1);

        /*for(vector<int> x: adj)
        {
            for(int y: x) cout << y << " ";
            cout << "\n";
        }*/

        vector<int> v(n, 1);
        dfs(pos[n], adj, v);

        vector<int> c;
        int index = 0;
        for(int i=0; i<n; i++)
        {
            if(index != m && a[i] == b[index]) index++;
            else c.pb(v[pos[a[i]]]);
        }

        if(index != m)
        {
            cout << "NO\n";
            continue;
        }

        /*for(int x: c) cout << x << " ";
        cout << " ->\n";*/

        sort(c.begin(), c.end());
        sort(d.begin(), d.end());

        if(c.size() < n - m)
        {
            cout << "NO\n";
            continue;
        }

        bool ans = true;
        for(int i=0; i<n - m; i++)
        {
            if(c[i] < d[i]) ans = false;
        }

        if(ans) cout << "YES\n";
        else cout << "NO\n";
    }
}
/*
1
5 2 3
5 1 3 2 4
5 2
1 2 4
*/

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 2ms
memory: 6916kb

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: 0ms
memory: 6952kb

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'