QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#429577#5466. Permutation Compression36champWA 1ms6916kbC++203.7kb2024-06-02 17:28:242024-06-02 17:28:25

Judging History

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

  • [2024-06-02 17:28:25]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:6916kb
  • [2024-06-02 17:28:24]
  • 提交

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), c;
vector<int> s, S;

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_decomp(vector<bool> &seen)
{
    s = vector<int>(seen.size(), 0);
    S = vector<int>((seen.size() + 499) / 500, 0);

    for(int i=0; i<seen.size(); i++)
    {
        s[i] += !seen[i];
        S[i / 500] += !seen[i];
    }
}

int cnt(int l, int r)
{
    int x = (l + 499) / 500, y = r / 500, ret = 0;

    if(x <= y)
    {
        for(int i = l; i < 500 * x; i++) ret += s[i];
        for(int i = x; i <= y; i++) ret += S[i];
        for(int i = 500 * y; i < r; i++) ret += s[i];
    }
    else
    {
        for(int i = l; i <= r; i++) ret += s[i];
    }

    //cout << "cnt " << l << " " << r << " " << ret << "\n";

    return ret;
}

void build_vector(vector<vector<int>> &adj, int p, int l, int r, vector<bool> &seen)
{
    //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(!seen[p])
    {
        c.pb(cnt(l, r));
        s[p]--;
        S[p / 500]--;
    }

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

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";*/

        vector<bool> p(n + 1, false);
        build_decomp(p);
        for(int i=0; i<m; i++) p[pos[b[i]]] = true;
        c.clear();
        build_vector(adj, pos[n], 0, n - 1, p);

        int index = 0;
        for(int i=0; i<n; i++)
        {
            if(index != m && a[i] == b[index]) index++;
        }

        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());

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

        if(d.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";
    }
}

詳細信息

Test #1:

score: 100
Accepted
time: 1ms
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: 6916kb

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'