QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#793376#5466. Permutation Compressionguodong#WA 1ms3628kbC++173.2kb2024-11-29 19:10:222024-11-29 19:10:22

Judging History

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

  • [2024-11-29 19:10:22]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3628kb
  • [2024-11-29 19:10:22]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
class sgt{
    #define ls (pos << 1)
    #define rs (ls | 1)
    #define mid ((l + r) >> 1)
    public:
        int n;
        vector<int> a;
        sgt(int _n){
            n = _n;
            a.resize(4 * n + 4);
        }
        void pu(int pos){
            a[pos] = a[ls] + a[rs];
        }
        void update(int pos,int l,int r,int x,int v){
            if(l == r){
                a[pos] += v;
                return;
            }
            if(x <= mid){
                update(ls,l,mid,x,v);
            }
            if(x > mid)
                update(rs,mid + 1,r,x,v);
            pu(pos);
        }
        int query(int pos,int l,int r,int ql,int qr){
            if(ql > qr) return 0;
            if(ql <= l && r <= qr)
                return a[pos];
            int ans = 0;
            if(ql <= mid)
                ans += query(ls,l,mid,ql,qr);
            if(qr > mid)
                ans += query(rs,mid + 1,r,ql,qr);
            return ans;
        }
        void fix(int pos,int v){
            update(1,1,n,pos,v);
        }
};
#define For(i,a,b) for(int i = a; i <= b; ++i)
signed main(){
    #ifndef ONLINE_JUDGE
        freopen("data.in","r",stdin);
    #endif
    int T;
     ios::sync_with_stdio(false);
    cin >> T;
    while(T--){
        int n,m,k;
        cin >> n >> m >> k;
        vector<pair<int,int>> p(n);
        vector<int> t(n + 1);
        For(i,0,n - 1){
            cin >> p[i].first;
            p[i].second = i + 1;
        }
        For(i,1,m){
            int x;
            cin >> x;
            t[x] = 1;
        }
        multiset<int> L;
        For(i,1,k){
            int x;
            cin >> x;
            L.insert(x);
        }
        if(n - m > k){
            cout << "NO" << '\n';
            continue;
        }
        sort(p.begin(),p.end(),[&](auto a,auto b){return a.first > b.first;});
        sgt st = sgt(n);
        For(i,1,n) 
            st.fix(i,1);
        set<int> S;
        int flag = 0;
        For(i,0,n - 1){
            int x = p[i].first;
            if(t[x]){
                S.insert(p[i].second);
                st.fix(p[i].second,-1);
            }
            else{
                auto it = S.lower_bound(p[i].second);
                int l,r; 
                if(it == S.end())
                    r = n + 1;
                else 
                    r = *it;
                if(it == S.begin()){
                    l = 0;
                }
                else{
                    it--;
                    l = *it;
                }
                ++l, --r;
                int maxx = st.query(1,1,n,l,r);
                // cout << p[i].second << " " << maxx << '\n';
                it = L.upper_bound(maxx);
                if(it == L.begin()){
                    flag = 1;
                    break;
                }
                else{
                    it--;
                    L.erase(it);
                }
                st.fix(p[i].second,-1);
            }
        }
        if(!flag)
            cout << "YES" << '\n';
        else
            cout << "NO" << '\n';
    }
    return 0;
}

详细

Test #1:

score: 100
Accepted
time: 0ms
memory: 3568kb

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

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

result:

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