Submission #401986

# Submission time Handle Problem Language Result Execution time Memory
401986 2021-05-11T06:13:10 Z teehandsome New Home (APIO18_new_home) C++17
12 / 100
5000 ms 51532 KB
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define endl '\n'
#define INF 1e9+7
#define all(x) x.begin(),x.end()
using namespace std;
using namespace __gnu_pbds;
using ll=long long;
using pii=pair<int,int>;
using ppi=pair<int,pii>;
using oset=tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>;

template<typename T>
void _print(vector<T> x) {cerr<<"{"; for(auto e:x) cerr<<e<<","; cerr<<"}";}
void _print(pii x) {cerr<<"{"<<x.first<<","<<x.second<<"}";}
template<typename T>
void _print(T x) {cerr<<x;}

void dbg() {cerr<<endl;}
template<typename Head,typename... Tail>
void dbg(Head H,Tail... T) {
    _print(H);
    if(sizeof...(T)) cerr<<",";
    else cerr<<"\"]";
    dbg(T...);
}
#define debug(...) cerr<<"["<<#__VA_ARGS__<<"]:[\"",dbg(__VA_ARGS__)

//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

struct dt {
    int s,t,x;
    dt(int S,int T,int X) {
        s=S,t=T,x=X;
    }
};
bool operator<(const dt &l,const dt &r) {
    if(l.x==r.x) {
        if(l.s==r.s) return l.t<r.t;
        return l.s<r.s;
    }
    return l.x<r.x;
}

const int mxn=3e5+10;
int n,q,k;
vector<dt> a[mxn];
vector<dt> av[mxn];

#define fi first
#define se second

void deebug(vector<dt> ar) {
    int len=ar.size();
    cout<<"------"<<endl;
    for(int i=0;i<len;i++) {
        cout<<ar[i].s<<" "<<ar[i].t<<" "<<ar[i].x<<endl;
    }
    cout<<"====="<<endl;
}

int main () {
    ios::sync_with_stdio(false); cin.tie(0);
    cin>>n>>k>>q;
    for(int i=0;i<n;i++) {
        int x,tt,u,v;
        cin>>x>>tt>>u>>v;
        a[tt].push_back({u,v,x});
    }
    for(int i=1;i<=k;i++) {
        av[i]=a[i];
        sort(all(a[i]),[&](const dt &l,const dt &r) {
                if(l.s==r.s) return l.t<r.t;
                return l.s<r.s;
             });
        sort(all(av[i]),[&](const dt &l,const dt &r) {
                return l.t<r.t;
             });
    }

    vector<int> ans(q);
    vector<ppi> que(q);
    // {time , {pos,idx}}
    for(int i=0;i<q;i++) {
        cin>>que[i].se.fi>>que[i].fi;
        que[i].se.se=i;
    }
    sort(all(que));
    vector<int> lu(k+1,0),lv(k+1,0);
    multiset<dt> s[k+1];
//    for(int i=1;i<=k;i++) {
//        deebug(a[i]);
//        deebug(av[i]);
//    }

    for(int i=0;i<q;i++) {
        int t=que[i].fi;
        int idx=que[i].se.se;
        int pos=que[i].se.fi;
//        debug(i,t,pos,idx);
        int mx=0;
        bool ok=true;

        for(int j=1;j<=k;j++) {
            int sz=a[j].size();
            while(lu[j]<sz and a[j][lu[j]].s<=t) {
                s[j].insert(a[j][lu[j]]);
                lu[j]++;
            }
            while(lv[j]<sz and av[j][lv[j]].t<t) {
                auto temp=s[j].find(av[j][lv[j]]);
                if(temp!=s[j].end()) s[j].erase(s[j].find(av[j][lv[j]]));
                else assert(false);
                lv[j]++;
            }
//            debug(j,lu[j],lv[j]);
            if(s[j].empty()) ok=false;
            else {
//                for(auto e:s[j]) {
//                    cout<<"# "<<e.x<<" "<<e.s<<" "<<e.t<<endl;
//                }
                dt temp(-1,-1,pos);
                auto pp1=s[j].lower_bound(temp);
                auto pp2=pp1; --pp2;
                dt p1(0,0,INF),p2(0,0,INF);
                if(pp1!=s[j].end()) p1=*pp1;
                if(pp2!=s[j].end()) p2=*pp2;
//                cout<<"% "<<p1.x<<" "<<p1.s<<" "<<p1.t<<endl;
//                cout<<"% "<<p2.x<<" "<<p2.s<<" "<<p2.t<<endl;
//                cout<<p1.x<<","<<p2.x<<endl;
                int d=min(abs(p1.x-pos),abs(p2.x-pos));
//                debug(j,d);
                mx=max(mx,d);
            }
        }
        if(!ok) ans[idx]=-1;
        else ans[idx]=mx;
    }
    for(int i=0;i<q;i++) {
        cout<<ans[i]<<endl;
    }
}

# Verdict Execution time Memory Grader output
1 Correct 8 ms 14284 KB Output is correct
2 Correct 8 ms 14284 KB Output is correct
3 Correct 8 ms 14284 KB Output is correct
4 Correct 9 ms 14284 KB Output is correct
5 Correct 9 ms 14404 KB Output is correct
6 Correct 9 ms 14440 KB Output is correct
7 Correct 11 ms 14472 KB Output is correct
8 Correct 10 ms 14416 KB Output is correct
9 Correct 11 ms 14416 KB Output is correct
10 Correct 9 ms 14412 KB Output is correct
11 Correct 9 ms 14412 KB Output is correct
12 Correct 9 ms 14368 KB Output is correct
13 Correct 9 ms 14412 KB Output is correct
14 Correct 9 ms 14412 KB Output is correct
15 Correct 10 ms 14412 KB Output is correct
16 Correct 10 ms 14412 KB Output is correct
17 Correct 9 ms 14416 KB Output is correct
18 Correct 10 ms 14444 KB Output is correct
19 Correct 10 ms 14412 KB Output is correct
20 Correct 9 ms 14444 KB Output is correct
21 Correct 11 ms 14412 KB Output is correct
22 Correct 11 ms 14420 KB Output is correct
23 Correct 10 ms 14412 KB Output is correct
24 Correct 10 ms 14392 KB Output is correct
25 Correct 9 ms 14412 KB Output is correct
26 Correct 9 ms 14416 KB Output is correct
27 Correct 9 ms 14420 KB Output is correct
28 Correct 9 ms 14412 KB Output is correct
29 Correct 9 ms 14456 KB Output is correct
30 Correct 9 ms 14440 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 14284 KB Output is correct
2 Correct 8 ms 14284 KB Output is correct
3 Correct 8 ms 14284 KB Output is correct
4 Correct 9 ms 14284 KB Output is correct
5 Correct 9 ms 14404 KB Output is correct
6 Correct 9 ms 14440 KB Output is correct
7 Correct 11 ms 14472 KB Output is correct
8 Correct 10 ms 14416 KB Output is correct
9 Correct 11 ms 14416 KB Output is correct
10 Correct 9 ms 14412 KB Output is correct
11 Correct 9 ms 14412 KB Output is correct
12 Correct 9 ms 14368 KB Output is correct
13 Correct 9 ms 14412 KB Output is correct
14 Correct 9 ms 14412 KB Output is correct
15 Correct 10 ms 14412 KB Output is correct
16 Correct 10 ms 14412 KB Output is correct
17 Correct 9 ms 14416 KB Output is correct
18 Correct 10 ms 14444 KB Output is correct
19 Correct 10 ms 14412 KB Output is correct
20 Correct 9 ms 14444 KB Output is correct
21 Correct 11 ms 14412 KB Output is correct
22 Correct 11 ms 14420 KB Output is correct
23 Correct 10 ms 14412 KB Output is correct
24 Correct 10 ms 14392 KB Output is correct
25 Correct 9 ms 14412 KB Output is correct
26 Correct 9 ms 14416 KB Output is correct
27 Correct 9 ms 14420 KB Output is correct
28 Correct 9 ms 14412 KB Output is correct
29 Correct 9 ms 14456 KB Output is correct
30 Correct 9 ms 14440 KB Output is correct
31 Correct 3029 ms 22036 KB Output is correct
32 Correct 114 ms 18900 KB Output is correct
33 Correct 186 ms 18956 KB Output is correct
34 Correct 2618 ms 19536 KB Output is correct
35 Correct 1199 ms 21384 KB Output is correct
36 Correct 221 ms 21372 KB Output is correct
37 Correct 193 ms 17968 KB Output is correct
38 Correct 108 ms 17668 KB Output is correct
39 Correct 97 ms 17732 KB Output is correct
40 Correct 94 ms 17484 KB Output is correct
41 Correct 481 ms 17676 KB Output is correct
42 Correct 677 ms 17820 KB Output is correct
43 Correct 1991 ms 21952 KB Output is correct
44 Correct 412 ms 18072 KB Output is correct
45 Correct 165 ms 17860 KB Output is correct
46 Correct 82 ms 17692 KB Output is correct
47 Correct 78 ms 17476 KB Output is correct
48 Correct 73 ms 17584 KB Output is correct
49 Correct 95 ms 17552 KB Output is correct
50 Correct 384 ms 17952 KB Output is correct
51 Correct 81 ms 17620 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 5011 ms 51532 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 5048 ms 47080 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 8 ms 14284 KB Output is correct
2 Correct 8 ms 14284 KB Output is correct
3 Correct 8 ms 14284 KB Output is correct
4 Correct 9 ms 14284 KB Output is correct
5 Correct 9 ms 14404 KB Output is correct
6 Correct 9 ms 14440 KB Output is correct
7 Correct 11 ms 14472 KB Output is correct
8 Correct 10 ms 14416 KB Output is correct
9 Correct 11 ms 14416 KB Output is correct
10 Correct 9 ms 14412 KB Output is correct
11 Correct 9 ms 14412 KB Output is correct
12 Correct 9 ms 14368 KB Output is correct
13 Correct 9 ms 14412 KB Output is correct
14 Correct 9 ms 14412 KB Output is correct
15 Correct 10 ms 14412 KB Output is correct
16 Correct 10 ms 14412 KB Output is correct
17 Correct 9 ms 14416 KB Output is correct
18 Correct 10 ms 14444 KB Output is correct
19 Correct 10 ms 14412 KB Output is correct
20 Correct 9 ms 14444 KB Output is correct
21 Correct 11 ms 14412 KB Output is correct
22 Correct 11 ms 14420 KB Output is correct
23 Correct 10 ms 14412 KB Output is correct
24 Correct 10 ms 14392 KB Output is correct
25 Correct 9 ms 14412 KB Output is correct
26 Correct 9 ms 14416 KB Output is correct
27 Correct 9 ms 14420 KB Output is correct
28 Correct 9 ms 14412 KB Output is correct
29 Correct 9 ms 14456 KB Output is correct
30 Correct 9 ms 14440 KB Output is correct
31 Correct 3029 ms 22036 KB Output is correct
32 Correct 114 ms 18900 KB Output is correct
33 Correct 186 ms 18956 KB Output is correct
34 Correct 2618 ms 19536 KB Output is correct
35 Correct 1199 ms 21384 KB Output is correct
36 Correct 221 ms 21372 KB Output is correct
37 Correct 193 ms 17968 KB Output is correct
38 Correct 108 ms 17668 KB Output is correct
39 Correct 97 ms 17732 KB Output is correct
40 Correct 94 ms 17484 KB Output is correct
41 Correct 481 ms 17676 KB Output is correct
42 Correct 677 ms 17820 KB Output is correct
43 Correct 1991 ms 21952 KB Output is correct
44 Correct 412 ms 18072 KB Output is correct
45 Correct 165 ms 17860 KB Output is correct
46 Correct 82 ms 17692 KB Output is correct
47 Correct 78 ms 17476 KB Output is correct
48 Correct 73 ms 17584 KB Output is correct
49 Correct 95 ms 17552 KB Output is correct
50 Correct 384 ms 17952 KB Output is correct
51 Correct 81 ms 17620 KB Output is correct
52 Execution timed out 5060 ms 23604 KB Time limit exceeded
53 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 8 ms 14284 KB Output is correct
2 Correct 8 ms 14284 KB Output is correct
3 Correct 8 ms 14284 KB Output is correct
4 Correct 9 ms 14284 KB Output is correct
5 Correct 9 ms 14404 KB Output is correct
6 Correct 9 ms 14440 KB Output is correct
7 Correct 11 ms 14472 KB Output is correct
8 Correct 10 ms 14416 KB Output is correct
9 Correct 11 ms 14416 KB Output is correct
10 Correct 9 ms 14412 KB Output is correct
11 Correct 9 ms 14412 KB Output is correct
12 Correct 9 ms 14368 KB Output is correct
13 Correct 9 ms 14412 KB Output is correct
14 Correct 9 ms 14412 KB Output is correct
15 Correct 10 ms 14412 KB Output is correct
16 Correct 10 ms 14412 KB Output is correct
17 Correct 9 ms 14416 KB Output is correct
18 Correct 10 ms 14444 KB Output is correct
19 Correct 10 ms 14412 KB Output is correct
20 Correct 9 ms 14444 KB Output is correct
21 Correct 11 ms 14412 KB Output is correct
22 Correct 11 ms 14420 KB Output is correct
23 Correct 10 ms 14412 KB Output is correct
24 Correct 10 ms 14392 KB Output is correct
25 Correct 9 ms 14412 KB Output is correct
26 Correct 9 ms 14416 KB Output is correct
27 Correct 9 ms 14420 KB Output is correct
28 Correct 9 ms 14412 KB Output is correct
29 Correct 9 ms 14456 KB Output is correct
30 Correct 9 ms 14440 KB Output is correct
31 Correct 3029 ms 22036 KB Output is correct
32 Correct 114 ms 18900 KB Output is correct
33 Correct 186 ms 18956 KB Output is correct
34 Correct 2618 ms 19536 KB Output is correct
35 Correct 1199 ms 21384 KB Output is correct
36 Correct 221 ms 21372 KB Output is correct
37 Correct 193 ms 17968 KB Output is correct
38 Correct 108 ms 17668 KB Output is correct
39 Correct 97 ms 17732 KB Output is correct
40 Correct 94 ms 17484 KB Output is correct
41 Correct 481 ms 17676 KB Output is correct
42 Correct 677 ms 17820 KB Output is correct
43 Correct 1991 ms 21952 KB Output is correct
44 Correct 412 ms 18072 KB Output is correct
45 Correct 165 ms 17860 KB Output is correct
46 Correct 82 ms 17692 KB Output is correct
47 Correct 78 ms 17476 KB Output is correct
48 Correct 73 ms 17584 KB Output is correct
49 Correct 95 ms 17552 KB Output is correct
50 Correct 384 ms 17952 KB Output is correct
51 Correct 81 ms 17620 KB Output is correct
52 Execution timed out 5011 ms 51532 KB Time limit exceeded
53 Halted 0 ms 0 KB -