QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#647288#5466. Permutation CompressioncrychicRE 1ms3668kbC++202.6kb2024-10-17 13:13:312024-10-17 13:13:31

Judging History

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

  • [2024-10-17 13:13:31]
  • 评测
  • 测评结果:RE
  • 用时:1ms
  • 内存:3668kb
  • [2024-10-17 13:13:31]
  • 提交

answer

#include<bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;

const int N = 2e5 + 10;

int tr[N];

int lowbit(int x) {
    return x & -x;
}

void add(int pos, int d) {
    if(pos <= 0) return ;
    for(int i = pos; i < N; i += lowbit(i)) {
        tr[i] += d;
    }
}

int query(int pos) {
    int res = 0;
    if(pos <= 0) return 0;
    for(int i = pos; i; i -= lowbit(i)) {
        res += tr[i];
    }
    return res;
}

void solve() {
    int n, m, k;
    cin >> n >> m >> k;
    std::vector<int> pos(n + 1), has(n + 1);
    for(int i = 1, x; i <= n; i ++ ) {
        cin >> x;
        pos[x] = i;
    }
    vector<int> a(m + 1);
    for(int i = 1, x; i <= m; i ++ ) {
        cin >> x;
        has[x] = 1;
        a[i] = x;
    }
    for(int i = 1; i < m; i ++ ) {
        if(pos[a[i + 1]] < pos[a[i]]) {
            cout << "NO\n";
            return ;
        }
    }
    multiset<int> st;
    st.insert(0);
    st.insert(n + 1);
    for(int i = 1, x; i <= k; i ++ ) {
        cin >> x;
        st.insert(x);
    }
    set<int> p;
    p.insert(0);
    p.insert(n + 1);
    bool fg = 0;
    vector<int> vis(n + 2);
    vis[n + 1] = vis[0] = 1;
    vector<int> need_del(n + 1);
    for(int i = n; i >= 1; i -- ) {
        if(!has[i]) {
            // auto it = p.upper_bound(pos[i]);
            // int l = *(prev(it));
            // int r = (*it);
            int l = 0, r = 0;
            for(int j = pos[i]; j <= n + 1; j ++ ) {
                if(vis[j]) {
                    r = j;
                    break;
                }
            }
            for(int j = pos[i]; j >= 0; j -- ) {
                if(vis[j]) {
                    l = j;
                    break;
                }
            }
            int w = r - l - 1 - (query(r) - query(l));
            // cout << i << ' ' << l << ' ' << r << ' ' << w << '\n';
            auto it2 = prev(st.upper_bound(w));
            if((*it2) == 0) {
                fg = 1;
                break;
            } else {
                st.erase(it2);
                add(pos[i], 1);
                need_del[pos[i]] = 1;
            }
        } else {
            vis[pos[i]] = 1;
            // p.insert(pos[i]);
        }
    }
    if(fg) {
        cout << "NO\n";
    } else {
        cout << "YES\n";
    }
    for(int i = 1; i <= n; i ++ ) {
        if(need_del[i]) {
            add(i, -1);
        }
    }
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);
    
    int t = 1;
    cin >> t;
    while(t -- ) {
        solve();
    }

    return 0;
}

详细

Test #1:

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

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
Runtime Error

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:


result: