Codeforces Round 985 (Div. 3)

A. Twice

    #include<bits/stdc++.h>
    #define endl '\n'
    #define int int long long
    #define pb push_back
    #define bs bitset
    #define val(a) (a<'a' ? (a-'A'+'a') : a)
    #define fast() ios::sync_with_stdio(false),cin.tie(nullptr),cout.tie(nullptr)
    using namespace std;

    typedef pair<char,int> PCI;
    typedef pair<int,int> PII;
    typedef pair<long long, long long> PLL;
    typedef priority_queue<int> PQ;
    typedef priority_queue<int, vector<int>, greater<int>> Q;
    const int N = 2e5+10, MAX = 1e9, INF = -1e9;

    void solve(){
        int n,e;
        cin>>n;
        map<int,int> mp;
        for(int i=1;i<=n;i++){
            cin>>e;
            mp[e]++;
        }
        int ans=0;
        for(auto i:mp){
            ans+=i.second/2;
        }
        cout<<ans<<endl;
        return ;
    }

    signed main()
    {
        fast();
        
        int t=1;
        cin>>t;
        while(t--){
            solve();
        }
        return 0;
    }

B. Intercepted Inputs

    #include<bits/stdc++.h>
    #define endl '\n'
    #define int int long long
    #define pb push_back
    #define bs bitset
    #define val(a) (a<'a' ? (a-'A'+'a') : a)
    #define fast() ios::sync_with_stdio(false),cin.tie(nullptr),cout.tie(nullptr)
    using namespace std;

    typedef pair<char,int> PCI;
    typedef pair<int,int> PII;
    typedef pair<long long, long long> PLL;
    typedef priority_queue<int> PQ;
    typedef priority_queue<int, vector<int>, greater<int>> Q;
    const int N = 2e5+10, MAX = 1e9, INF = -1e9;

    void solve(){
        int k;
        cin>>k;
        int e;
        map<int,int> mp;
        for(int i=1;i<=k;i++){
            cin>>e;
            mp[e]++;
        }
        for(auto i:mp){
            if(mp.find((k-2)/i.first)!=mp.end()&&(k-2)%i.first==0){
                cout<<i.first<<" "<<(k-2)/i.first<<endl;
                return ;
            }
        }
        return ;

    }

    signed main()
    {
        fast();
        
        int t=1;
        cin>>t;
        while(t--){
            solve();
        }
        return 0;
    }

C. Superultra's Favorite Permutation

    #include<bits/stdc++.h>
    #define endl '\n'
    #define int int long long
    #define pb push_back
    #define bs bitset
    #define val(a) (a<'a' ? (a-'A'+'a') : a)
    #define fast() ios::sync_with_stdio(false),cin.tie(nullptr),cout.tie(nullptr)
    using namespace std;

    typedef pair<char,int> PCI;
    typedef pair<int,int> PII;
    typedef pair<long long, long long> PLL;
    typedef priority_queue<int> PQ;
    typedef priority_queue<int, vector<int>, greater<int>> Q;
    const int N = 2e5+10, MAX = 1e9, INF = -1e9;

    void solve(){
        int n;
        cin>>n;
        if(n<=4)cout<<"-1"<<endl;
        else{
            for(int i=1;i<=n;i+=2){
                if(i!=5)cout<<i<<" ";
            }
            cout<<5<<" "<<4<<" ";
            for(int i=2;i<=n;i+=2){
                if(i!=4)cout<<i<<" ";
            }
            cout<<endl;
        }
        return  ;
    }

    signed main()
    {
        fast();
        
        int t=1;
        cin>>t;
        while(t--){
            solve();
        }
        return 0;
    }

D. Sharky Surfing

    #include<bits/stdc++.h>
    #define endl '\n'
    #define int int long long
    #define pb push_back
    #define bs bitset
    #define val(a) (a<'a' ? (a-'A'+'a') : a)
    #define fast() ios::sync_with_stdio(false),cin.tie(nullptr),cout.tie(nullptr)
    using namespace std;

    typedef pair<char,int> PCI;
    typedef pair<int,int> PII;
    typedef pair<long long, long long> PLL;
    typedef priority_queue<int> PQ;
    typedef priority_queue<int, vector<int>, greater<int>> Q;
    const int N = 2e5+10, MAX = 1e9, INF = -1e9;

    void solve(){
        int n,m,l;
        int ne=1;
        cin>>n>>m>>l;
        int a,b;
        int ans=0;
        PQ q;
        vector<PII> v;  
        vector<PII> e;
        for(int i=1;i<=n;i++){
            cin>>a>>b;
            v.pb({a,b-a+2});
        }
        for(int i=1;i<=m;i++){
            cin>>a>>b;
            e.pb({a,b});
        }
        int p=0;
        for(auto i:v){
            if(i.first>l){
                break;
            }
            while(e[p].first<i.first&&p<e.size()){
                q.push(e[p].second);
                p++;
            }
            bool fg=false;
            if(ne>=i.second)fg=true;
            while(!q.empty()&&ne<i.second){
                ne+=q.top();
                q.pop();
                ans++;  
                if(ne>=i.second){
                    fg=true;
                    break;
                } 
            }
            if(!fg){
                cout<<"-1"<<endl;
                return ;
            }
        }
        cout<<ans<<endl;
        return ;

    }

    signed main()
    {
        fast();
        
        int t=1;
        cin>>t;
        while(t--){
            solve();
        }
        return 0;
    }
posted @ 2025-02-07 15:01  Oaths  阅读(16)  评论(0)    收藏  举报