QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#804632#9873. Last Chance: Threads of Despairucup-team1134#WA 1ms3868kbC++233.9kb2024-12-08 01:23:162024-12-08 01:23:16

Judging History

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

  • [2024-12-08 01:23:16]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3868kb
  • [2024-12-08 01:23:16]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return true; } return false; }
#define vi vector<int>
#define vl vector<ll>
#define vii vector<pair<int,int>>
#define vll vector<pair<ll,ll>>
#define vvi vector<vector<int>>
#define vvl vector<vector<ll>>
#define vvii vector<vector<pair<int,int>>>
#define vvll vector<vector<pair<ll,ll>>>
#define vst vector<string>
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define mkunique(x) sort(all(x));(x).erase(unique(all(x)),(x).end())
#define fi first
#define se second
#define mp make_pair
#define si(x) int(x.size())
const int mod=998244353,MAX=300005,INF=15<<26;

int main(){
    
    std::ifstream in("text.txt");
    std::cin.rdbuf(in.rdbuf());
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int Q;cin>>Q;
    while(Q--){
        ll N,M;cin>>N>>M;
        ll buf=0;
        multiset<ll> A,B,C,svA,svB;
        vl Z;
        for(int i=0;i<N;i++){
            ll x;cin>>x;
            A.insert(x);
        }
        for(int i=0;i<M;i++){
            ll x;cin>>x;
            B.insert(x);
            Z.pb(x);
        }
        sort(all(Z));
        svA=A;
        svB=B;
        int q=0,la=0;
        
        while(si(A)&&si(B)){
            ll x=*A.begin();
            assert(x>buf);
            A.erase(A.begin());
            C.insert(x-1);
            
            ll y=*B.rbegin();
            B.erase(B.find(y));
            B.insert(y-1);
            
            while(1){
                if(si(A)&&*A.begin()<=buf){
                    la=q+1;
                    A.erase(A.begin());
                    buf++;
                }else if(si(B)&&*B.begin()<=buf){
                    la=q+1;
                    B.erase(B.begin());
                    buf++;
                }else if(si(C)&&*C.begin()<=buf){
                    la=q+1;
                    C.erase(C.begin());
                    buf++;
                }else{
                    break;
                }
            }
            q++;
        }
        
        if(si(B)==0){
            cout<<"Yes\n";
            continue;
        }
        
        A=svA;
        B=svB;
        C.clear();
        
        q=0;
        buf=0;
        ll ata=0;
        while(si(A)&&si(B)){
            if(la==q) break;
            ll x=*A.begin();
            assert(x>buf);
            A.erase(A.begin());
            C.insert(x-1);
            
            ll y=*B.rbegin();
            B.erase(B.find(y));
            B.insert(y-1);
            
            ata++;
            
            while(1){
                if(si(A)&&*A.begin()<=buf){
                    A.erase(A.begin());
                    buf++;
                }else if(si(B)&&*B.begin()<=buf){
                    B.erase(B.begin());
                    buf++;
                }else if(si(C)&&*C.begin()<=buf){
                    C.erase(C.begin());
                    buf++;
                }else{
                    break;
                }
            }
            q++;
        }
        deque<ll> X,Y;
        for(ll a:A) X.pb((a-1-buf));
        for(int t=0;t<si(B);t++) Y.pb(Z[si(Z)-si(B)+t]-buf);
        
        ll rem=si(X)+ata;
        
        for(ll t=0;;t++){
            if(si(X)&&X[0]<=t){
                X.pop_front();
            }else if(si(Y)==0){
                break;
            }else{
                if(Y[0]<=t){
                    Y.pop_front();
                }else{
                    rem-=(Y[0]-t);
                    Y.pop_front();
                }
            }
        }
        
        if(rem>=0) cout<<"Yes\n";
        else cout<<"No\n";
    }
}



Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

3
3 2
1 1 4
2 6
3 2
1 1 4
2 7
2 1
100 100
2

output:

Yes
No
Yes

result:

ok 3 token(s): yes count is 2, no count is 1

Test #2:

score: 0
Accepted
time: 0ms
memory: 3868kb

input:

3
7 1
1 1 1 1 1 1 1
9
5 2
3 4 5 6 7
1 6
5 3
3 4 5 6 7
1 5 7

output:

No
No
Yes

result:

ok 3 token(s): yes count is 1, no count is 2

Test #3:

score: 0
Accepted
time: 0ms
memory: 3864kb

input:

4
1 1
1
1
1 1
1
2
1 1
2
1
1 1
2
2

output:

Yes
Yes
Yes
No

result:

ok 4 token(s): yes count is 3, no count is 1

Test #4:

score: 0
Accepted
time: 0ms
memory: 3608kb

input:

18
1 2
1
1 1
1 2
1
2 1
1 2
1
1 3
1 2
1
2 2
1 2
1
3 2
1 2
1
3 3
1 2
2
1 1
1 2
2
1 2
1 2
2
1 3
1 2
2
2 2
1 2
2
2 3
1 2
2
3 3
1 2
3
1 1
1 2
3
1 2
1 2
3
1 3
1 2
3
2 2
1 2
3
3 2
1 2
3
3 3

output:

Yes
Yes
Yes
Yes
No
No
Yes
Yes
No
No
No
No
Yes
No
No
No
No
No

result:

ok 18 token(s): yes count is 7, no count is 11

Test #5:

score: 0
Accepted
time: 0ms
memory: 3636kb

input:

18
2 1
1 1
1
2 1
1 1
2
2 1
1 1
3
2 1
1 2
1
2 1
2 1
2
2 1
2 1
3
2 1
1 3
1
2 1
1 3
2
2 1
3 1
3
2 1
2 2
1
2 1
2 2
2
2 1
2 2
3
2 1
2 3
1
2 1
3 2
2
2 1
2 3
3
2 1
3 3
1
2 1
3 3
2
2 1
3 3
3

output:

Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
No
Yes
Yes
No
Yes
Yes
No

result:

ok 18 token(s): yes count is 15, no count is 3

Test #6:

score: -100
Wrong Answer
time: 1ms
memory: 3584kb

input:

525
2 3
1 1
1 1 1
2 3
1 1
1 2 1
2 3
1 1
1 3 1
2 3
1 1
1 4 1
2 3
1 1
5 1 1
2 3
1 1
2 2 1
2 3
1 1
3 1 2
2 3
1 1
1 2 4
2 3
1 1
2 1 5
2 3
1 1
3 3 1
2 3
1 1
4 3 1
2 3
1 1
3 5 1
2 3
1 1
4 4 1
2 3
1 1
4 5 1
2 3
1 1
1 5 5
2 3
1 1
2 2 2
2 3
1 1
2 3 2
2 3
1 1
2 2 4
2 3
1 1
2 5 2
2 3
1 1
3 2 3
2 3
1 1
3 2 4
2 ...

output:

Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
No
No
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
No
No
Yes
Yes
No
No
No
No
No
No
No
No
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
No
No
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
No
Yes
Yes
Yes
Yes
No
No
No
No
No
No
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Y...

result:

wrong answer expected YES, found NO [49th token]