Submission #743554

# Submission time Handle Problem Language Result Execution time Memory
743554 2023-05-17T13:43:12 Z alvingogo New Home (APIO18_new_home) C++14
0 / 100
405 ms 72444 KB
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#define AquA cin.tie(0);ios_base::sync_with_stdio(0);
#define fs first
#define sc second
#define p_q priority_queue
#define int long long
using namespace std;

typedef pair<int,int> pii;
signed main(){
    AquA;
    int n,k,q;
    cin >> n >> k >> q;
    vector<pair<pii,pii> > vp(n);
    vector<pii> g;
    for(int i=0;i<n;i++){
        cin >> vp[i].fs.fs >> vp[i].fs.sc >> vp[i].sc.fs >> vp[i].sc.sc;
        vp[i].fs.sc--;
        g.push_back({vp[i].fs.fs,vp[i].fs.sc});
    }
    sort(g.begin(),g.end());
    vector<pii> sl;
    vector<int> s(k,-1);
    multiset<int> ms;
    vector<pair<int,pii> > eve;
    for(auto h:g){
        if(s[h.sc]==-1){
            ms.insert(h.fs);
        }    
        else{
            eve.push_back({(s[h.sc]+h.fs+1)/2,{s[h.sc],h.fs}});
        }
        s[h.sc]=h.fs;
    }
    for(int i=0;i<k;i++){
        if(s[i]==-1){
            for(int j=0;j<q;j++){
                cout << -1 << "\n";
            }
            return 0;
        }
    }
    vector<int> ans(q+1);
    for(int i=1;i<=q;i++){
        int l,y;
        cin >> l >> y;
        eve.push_back({l,{-1,i}});
    }
    sort(eve.begin(),eve.end());
    vector<pii> ins,que;
    int nw=-1;
    for(auto t:eve){
        if(t.fs!=nw){
            for(auto h:ins){
                ms.erase(ms.find(h.fs));
                ms.insert(h.sc);
            }
            for(auto h:que){
                auto y=*ms.rbegin();
                auto z=*ms.begin();
                ans[h.sc]=max(abs(y-h.fs),abs(z-h.fs));
            }
            ins.clear();
            que.clear();
        }
        if(t.sc.fs<0){
            que.push_back(t.sc);
        }
        else{
            ins.push_back({t.fs,t.sc.sc});
        }
        nw=t.fs;
    }
    for(auto h:ins){
        ms.erase(ms.find(h.fs));
        ms.insert(h.sc);
    }
    for(auto h:que){
        auto y=*ms.rbegin();
        auto z=*ms.begin();
        ans[h.sc]=max(abs(y-h.fs),abs(z-h.fs));
    }
    for(int i=1;i<=q;i++){
        cout << ans[i] << "\n";
    }
    return 0;
}
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 367 ms 72444 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 405 ms 72152 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -