답안 #261017

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
261017 2020-08-11T09:57:31 Z emanIaicepsa 새 집 (APIO18_new_home) C++14
12 / 100
2397 ms 37368 KB
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pii pair<ll,ll>
#define vi vector<int>
#define pb emplace_back
#define fi first
#define se second
#define all(n) (n).begin(),(n).end()
#define mem(n,m) memset(n,m,sizeof(n))
#define IOS ios::sync_with_stdio(0), cin.tie(0)
#define dbg(...) cerr<<#__VA_ARGS__<<" = ";_do(__VA_ARGS__);
template<typename A> void _do(A x){cerr<<x<<'\n';}
template<typename A,typename ...B> void _do(A x,B ...y){cerr<<x<<", ";_do(y...);}

int n,k,q;

struct shop{
    int x,t,a,b;
}arr[300005];

struct query{
    int x,t,id;
    bool operator<(const query &b){
        return t<b.t;
    }
}que[300005];

deque<pii> in, out;

multiset<ll> s[405];

void add(ll x){
    int type = arr[x].t, pos = arr[x].x;
    s[type].insert(pos);
}

void sub(ll x){
    int type = arr[x].t, pos = arr[x].x;
    s[type].erase(s[type].find(pos));
}

ll Query(ll k,ll pos){
    if(s[k].empty()) return 1e15;
    auto iter = s[k].lower_bound(pos);
    ll ans = 1e15;
    if(iter != s[k].end()) ans = min(ans, *iter - pos);
    if(iter != s[k].begin()){
        iter--;
        ans = min(ans, pos - *iter);
    }
    return ans;
}

ll ans[300005];

signed main(){
	IOS;
    cin>>n>>k>>q;
    for(int i=1;i<=n;i++){
        cin>>arr[i].x>>arr[i].t>>arr[i].a>>arr[i].b;
        in.pb(arr[i].a, i);
        out.pb(arr[i].b+1, i);
    }

    sort(all(in)); sort(all(out));
    for(int i=1;i<=q;i++){
        cin>>que[i].x>>que[i].t;
        que[i].id = i;
    }

    sort(que+1,que+1+q);

    for(int i=1;i<=q;i++){
        //dbg(i, que[i].t);
        while(!in.empty() && in[0].fi <= que[i].t ){
            //dbg(in[0].fi, in[0].se);
            add(in[0].se);
            in.pop_front();
        }
        while(!out.empty() && out[0].fi <= que[i].t){
            //dbg(out[0].fi, out[0].se);
            sub(out[0].se);
            out.pop_front();
        }
        ll ta = 0;
        for(int j=1;j<=k;j++){
            ta = max(ta, Query(j,que[i].x));
        }
        if(ta > 1e10) ta = -1;
        ans[que[i].id] = ta;
    }

    for(int i=1;i<=q;i++){
        cout<<ans[i]<<"\n";
    }

}

/*
4 2 4
3 1 1 10
9 2 2 4
7 2 5 7
4 1 8 10
5 3
5 6
5 9
1 10

1 1 1
100000000 1 1 1
1 1
*/
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 2 ms 384 KB Output is correct
8 Correct 2 ms 384 KB Output is correct
9 Correct 2 ms 384 KB Output is correct
10 Correct 2 ms 384 KB Output is correct
11 Correct 2 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 2 ms 384 KB Output is correct
16 Correct 2 ms 384 KB Output is correct
17 Correct 1 ms 384 KB Output is correct
18 Correct 2 ms 384 KB Output is correct
19 Correct 3 ms 384 KB Output is correct
20 Correct 2 ms 384 KB Output is correct
21 Correct 2 ms 384 KB Output is correct
22 Correct 3 ms 384 KB Output is correct
23 Correct 3 ms 384 KB Output is correct
24 Correct 2 ms 384 KB Output is correct
25 Correct 2 ms 384 KB Output is correct
26 Correct 1 ms 384 KB Output is correct
27 Correct 1 ms 384 KB Output is correct
28 Correct 1 ms 384 KB Output is correct
29 Correct 1 ms 512 KB Output is correct
30 Correct 1 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 2 ms 384 KB Output is correct
8 Correct 2 ms 384 KB Output is correct
9 Correct 2 ms 384 KB Output is correct
10 Correct 2 ms 384 KB Output is correct
11 Correct 2 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 2 ms 384 KB Output is correct
16 Correct 2 ms 384 KB Output is correct
17 Correct 1 ms 384 KB Output is correct
18 Correct 2 ms 384 KB Output is correct
19 Correct 3 ms 384 KB Output is correct
20 Correct 2 ms 384 KB Output is correct
21 Correct 2 ms 384 KB Output is correct
22 Correct 3 ms 384 KB Output is correct
23 Correct 3 ms 384 KB Output is correct
24 Correct 2 ms 384 KB Output is correct
25 Correct 2 ms 384 KB Output is correct
26 Correct 1 ms 384 KB Output is correct
27 Correct 1 ms 384 KB Output is correct
28 Correct 1 ms 384 KB Output is correct
29 Correct 1 ms 512 KB Output is correct
30 Correct 1 ms 384 KB Output is correct
31 Correct 2397 ms 9732 KB Output is correct
32 Correct 135 ms 6160 KB Output is correct
33 Correct 205 ms 8184 KB Output is correct
34 Correct 1850 ms 8380 KB Output is correct
35 Correct 1102 ms 9680 KB Output is correct
36 Correct 261 ms 9592 KB Output is correct
37 Correct 190 ms 7928 KB Output is correct
38 Correct 119 ms 7720 KB Output is correct
39 Correct 134 ms 7672 KB Output is correct
40 Correct 114 ms 7672 KB Output is correct
41 Correct 365 ms 8184 KB Output is correct
42 Correct 464 ms 7804 KB Output is correct
43 Correct 389 ms 9208 KB Output is correct
44 Correct 323 ms 7928 KB Output is correct
45 Correct 144 ms 7928 KB Output is correct
46 Correct 131 ms 7928 KB Output is correct
47 Correct 87 ms 7416 KB Output is correct
48 Correct 87 ms 7416 KB Output is correct
49 Correct 102 ms 7544 KB Output is correct
50 Correct 303 ms 7792 KB Output is correct
51 Correct 87 ms 7544 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Runtime error 417 ms 37296 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 350 ms 37368 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 2 ms 384 KB Output is correct
8 Correct 2 ms 384 KB Output is correct
9 Correct 2 ms 384 KB Output is correct
10 Correct 2 ms 384 KB Output is correct
11 Correct 2 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 2 ms 384 KB Output is correct
16 Correct 2 ms 384 KB Output is correct
17 Correct 1 ms 384 KB Output is correct
18 Correct 2 ms 384 KB Output is correct
19 Correct 3 ms 384 KB Output is correct
20 Correct 2 ms 384 KB Output is correct
21 Correct 2 ms 384 KB Output is correct
22 Correct 3 ms 384 KB Output is correct
23 Correct 3 ms 384 KB Output is correct
24 Correct 2 ms 384 KB Output is correct
25 Correct 2 ms 384 KB Output is correct
26 Correct 1 ms 384 KB Output is correct
27 Correct 1 ms 384 KB Output is correct
28 Correct 1 ms 384 KB Output is correct
29 Correct 1 ms 512 KB Output is correct
30 Correct 1 ms 384 KB Output is correct
31 Correct 2397 ms 9732 KB Output is correct
32 Correct 135 ms 6160 KB Output is correct
33 Correct 205 ms 8184 KB Output is correct
34 Correct 1850 ms 8380 KB Output is correct
35 Correct 1102 ms 9680 KB Output is correct
36 Correct 261 ms 9592 KB Output is correct
37 Correct 190 ms 7928 KB Output is correct
38 Correct 119 ms 7720 KB Output is correct
39 Correct 134 ms 7672 KB Output is correct
40 Correct 114 ms 7672 KB Output is correct
41 Correct 365 ms 8184 KB Output is correct
42 Correct 464 ms 7804 KB Output is correct
43 Correct 389 ms 9208 KB Output is correct
44 Correct 323 ms 7928 KB Output is correct
45 Correct 144 ms 7928 KB Output is correct
46 Correct 131 ms 7928 KB Output is correct
47 Correct 87 ms 7416 KB Output is correct
48 Correct 87 ms 7416 KB Output is correct
49 Correct 102 ms 7544 KB Output is correct
50 Correct 303 ms 7792 KB Output is correct
51 Correct 87 ms 7544 KB Output is correct
52 Runtime error 79 ms 11000 KB Execution killed with signal 11 (could be triggered by violating memory limits)
53 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 2 ms 384 KB Output is correct
8 Correct 2 ms 384 KB Output is correct
9 Correct 2 ms 384 KB Output is correct
10 Correct 2 ms 384 KB Output is correct
11 Correct 2 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 2 ms 384 KB Output is correct
16 Correct 2 ms 384 KB Output is correct
17 Correct 1 ms 384 KB Output is correct
18 Correct 2 ms 384 KB Output is correct
19 Correct 3 ms 384 KB Output is correct
20 Correct 2 ms 384 KB Output is correct
21 Correct 2 ms 384 KB Output is correct
22 Correct 3 ms 384 KB Output is correct
23 Correct 3 ms 384 KB Output is correct
24 Correct 2 ms 384 KB Output is correct
25 Correct 2 ms 384 KB Output is correct
26 Correct 1 ms 384 KB Output is correct
27 Correct 1 ms 384 KB Output is correct
28 Correct 1 ms 384 KB Output is correct
29 Correct 1 ms 512 KB Output is correct
30 Correct 1 ms 384 KB Output is correct
31 Correct 2397 ms 9732 KB Output is correct
32 Correct 135 ms 6160 KB Output is correct
33 Correct 205 ms 8184 KB Output is correct
34 Correct 1850 ms 8380 KB Output is correct
35 Correct 1102 ms 9680 KB Output is correct
36 Correct 261 ms 9592 KB Output is correct
37 Correct 190 ms 7928 KB Output is correct
38 Correct 119 ms 7720 KB Output is correct
39 Correct 134 ms 7672 KB Output is correct
40 Correct 114 ms 7672 KB Output is correct
41 Correct 365 ms 8184 KB Output is correct
42 Correct 464 ms 7804 KB Output is correct
43 Correct 389 ms 9208 KB Output is correct
44 Correct 323 ms 7928 KB Output is correct
45 Correct 144 ms 7928 KB Output is correct
46 Correct 131 ms 7928 KB Output is correct
47 Correct 87 ms 7416 KB Output is correct
48 Correct 87 ms 7416 KB Output is correct
49 Correct 102 ms 7544 KB Output is correct
50 Correct 303 ms 7792 KB Output is correct
51 Correct 87 ms 7544 KB Output is correct
52 Runtime error 417 ms 37296 KB Execution killed with signal 11 (could be triggered by violating memory limits)
53 Halted 0 ms 0 KB -