답안 #394005

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
394005 2021-04-25T07:53:16 Z 79brue 새 집 (APIO18_new_home) C++14
12 / 100
2380 ms 43960 KB
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

struct Mart{
    int x, y, t; bool on; /// location, type, time
    Mart(int x, int y, int t, bool on): x(x), y(y), t(t), on(on){}
    bool operator<(const Mart &r)const{
        return t<r.t;
    }
};

struct Query{
    int x, t, idx;
    Query(){}
    Query(int x, int t, int idx): x(x), t(t), idx(idx){}
    bool operator<(const Query &r)const{
        return t<r.t;
    }
};

int n, q, k;
vector<Mart> vec;
vector<Query> qvec;
multiset<int> mst[402];

int ans[300002];

int main(){
    scanf("%d %d %d", &n, &k, &q);
    for(int i=1; i<=n; i++){
        int x, t, a, b;
        scanf("%d %d %d %d", &x, &t, &a, &b);
        vec.push_back(Mart(x, t, a, 1));
        vec.push_back(Mart(x, t, b+1, 0));
    }
    sort(vec.begin(), vec.end());

    for(int i=1; i<=q; i++){
        int l, y;
        scanf("%d %d", &l, &y);
        qvec.push_back(Query(l, y, i));
    }
    sort(qvec.begin(), qvec.end());

    int pnt = 0;
    for(int i=0; i<q; i++){
        while(pnt < 2*n && vec[pnt].t <= qvec[i].t){
            Mart tmp = vec[pnt++];
            if(tmp.on) mst[tmp.y].insert(tmp.x);
            else mst[tmp.y].erase(mst[tmp.y].find(tmp.x));
        }

        for(int j=1; j<=k; j++){
            auto it = mst[j].lower_bound(qvec[i].x);
            int tmp = INT_MAX;
            if(it != mst[j].end()) tmp = min(tmp, *it - qvec[i].x);
            if(it != mst[j].begin()) tmp = min(tmp, qvec[i].x - *prev(it));
            ans[qvec[i].idx] = max(ans[qvec[i].idx], tmp);
        }
    }

    for(int i=1; i<=q; i++) printf("%d\n", ans[i] == INT_MAX ? -1 : ans[i]);
}

Compilation message

new_home.cpp: In function 'int main()':
new_home.cpp:32:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   32 |     scanf("%d %d %d", &n, &k, &q);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
new_home.cpp:35:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   35 |         scanf("%d %d %d %d", &x, &t, &a, &b);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
new_home.cpp:43:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   43 |         scanf("%d %d", &l, &y);
      |         ~~~~~^~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 2 ms 332 KB Output is correct
8 Correct 2 ms 336 KB Output is correct
9 Correct 2 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 460 KB Output is correct
14 Correct 1 ms 312 KB Output is correct
15 Correct 2 ms 332 KB Output is correct
16 Correct 2 ms 332 KB Output is correct
17 Correct 1 ms 332 KB Output is correct
18 Correct 2 ms 332 KB Output is correct
19 Correct 2 ms 340 KB Output is correct
20 Correct 1 ms 332 KB Output is correct
21 Correct 2 ms 332 KB Output is correct
22 Correct 3 ms 332 KB Output is correct
23 Correct 2 ms 336 KB Output is correct
24 Correct 2 ms 460 KB Output is correct
25 Correct 1 ms 332 KB Output is correct
26 Correct 1 ms 332 KB Output is correct
27 Correct 1 ms 332 KB Output is correct
28 Correct 1 ms 336 KB Output is correct
29 Correct 1 ms 332 KB Output is correct
30 Correct 1 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 2 ms 332 KB Output is correct
8 Correct 2 ms 336 KB Output is correct
9 Correct 2 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 460 KB Output is correct
14 Correct 1 ms 312 KB Output is correct
15 Correct 2 ms 332 KB Output is correct
16 Correct 2 ms 332 KB Output is correct
17 Correct 1 ms 332 KB Output is correct
18 Correct 2 ms 332 KB Output is correct
19 Correct 2 ms 340 KB Output is correct
20 Correct 1 ms 332 KB Output is correct
21 Correct 2 ms 332 KB Output is correct
22 Correct 3 ms 332 KB Output is correct
23 Correct 2 ms 336 KB Output is correct
24 Correct 2 ms 460 KB Output is correct
25 Correct 1 ms 332 KB Output is correct
26 Correct 1 ms 332 KB Output is correct
27 Correct 1 ms 332 KB Output is correct
28 Correct 1 ms 336 KB Output is correct
29 Correct 1 ms 332 KB Output is correct
30 Correct 1 ms 332 KB Output is correct
31 Correct 2380 ms 9284 KB Output is correct
32 Correct 110 ms 5296 KB Output is correct
33 Correct 186 ms 7520 KB Output is correct
34 Correct 1789 ms 7640 KB Output is correct
35 Correct 1004 ms 9264 KB Output is correct
36 Correct 217 ms 9136 KB Output is correct
37 Correct 181 ms 7196 KB Output is correct
38 Correct 110 ms 7088 KB Output is correct
39 Correct 97 ms 7108 KB Output is correct
40 Correct 94 ms 7088 KB Output is correct
41 Correct 317 ms 7468 KB Output is correct
42 Correct 437 ms 7212 KB Output is correct
43 Correct 402 ms 8780 KB Output is correct
44 Correct 274 ms 7344 KB Output is correct
45 Correct 133 ms 7328 KB Output is correct
46 Correct 79 ms 7216 KB Output is correct
47 Correct 76 ms 6828 KB Output is correct
48 Correct 70 ms 6816 KB Output is correct
49 Correct 92 ms 6960 KB Output is correct
50 Correct 249 ms 7092 KB Output is correct
51 Correct 79 ms 6960 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Runtime error 305 ms 43936 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 332 ms 43960 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 2 ms 332 KB Output is correct
8 Correct 2 ms 336 KB Output is correct
9 Correct 2 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 460 KB Output is correct
14 Correct 1 ms 312 KB Output is correct
15 Correct 2 ms 332 KB Output is correct
16 Correct 2 ms 332 KB Output is correct
17 Correct 1 ms 332 KB Output is correct
18 Correct 2 ms 332 KB Output is correct
19 Correct 2 ms 340 KB Output is correct
20 Correct 1 ms 332 KB Output is correct
21 Correct 2 ms 332 KB Output is correct
22 Correct 3 ms 332 KB Output is correct
23 Correct 2 ms 336 KB Output is correct
24 Correct 2 ms 460 KB Output is correct
25 Correct 1 ms 332 KB Output is correct
26 Correct 1 ms 332 KB Output is correct
27 Correct 1 ms 332 KB Output is correct
28 Correct 1 ms 336 KB Output is correct
29 Correct 1 ms 332 KB Output is correct
30 Correct 1 ms 332 KB Output is correct
31 Correct 2380 ms 9284 KB Output is correct
32 Correct 110 ms 5296 KB Output is correct
33 Correct 186 ms 7520 KB Output is correct
34 Correct 1789 ms 7640 KB Output is correct
35 Correct 1004 ms 9264 KB Output is correct
36 Correct 217 ms 9136 KB Output is correct
37 Correct 181 ms 7196 KB Output is correct
38 Correct 110 ms 7088 KB Output is correct
39 Correct 97 ms 7108 KB Output is correct
40 Correct 94 ms 7088 KB Output is correct
41 Correct 317 ms 7468 KB Output is correct
42 Correct 437 ms 7212 KB Output is correct
43 Correct 402 ms 8780 KB Output is correct
44 Correct 274 ms 7344 KB Output is correct
45 Correct 133 ms 7328 KB Output is correct
46 Correct 79 ms 7216 KB Output is correct
47 Correct 76 ms 6828 KB Output is correct
48 Correct 70 ms 6816 KB Output is correct
49 Correct 92 ms 6960 KB Output is correct
50 Correct 249 ms 7092 KB Output is correct
51 Correct 79 ms 6960 KB Output is correct
52 Runtime error 69 ms 10264 KB Execution killed with signal 11
53 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 2 ms 332 KB Output is correct
8 Correct 2 ms 336 KB Output is correct
9 Correct 2 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 460 KB Output is correct
14 Correct 1 ms 312 KB Output is correct
15 Correct 2 ms 332 KB Output is correct
16 Correct 2 ms 332 KB Output is correct
17 Correct 1 ms 332 KB Output is correct
18 Correct 2 ms 332 KB Output is correct
19 Correct 2 ms 340 KB Output is correct
20 Correct 1 ms 332 KB Output is correct
21 Correct 2 ms 332 KB Output is correct
22 Correct 3 ms 332 KB Output is correct
23 Correct 2 ms 336 KB Output is correct
24 Correct 2 ms 460 KB Output is correct
25 Correct 1 ms 332 KB Output is correct
26 Correct 1 ms 332 KB Output is correct
27 Correct 1 ms 332 KB Output is correct
28 Correct 1 ms 336 KB Output is correct
29 Correct 1 ms 332 KB Output is correct
30 Correct 1 ms 332 KB Output is correct
31 Correct 2380 ms 9284 KB Output is correct
32 Correct 110 ms 5296 KB Output is correct
33 Correct 186 ms 7520 KB Output is correct
34 Correct 1789 ms 7640 KB Output is correct
35 Correct 1004 ms 9264 KB Output is correct
36 Correct 217 ms 9136 KB Output is correct
37 Correct 181 ms 7196 KB Output is correct
38 Correct 110 ms 7088 KB Output is correct
39 Correct 97 ms 7108 KB Output is correct
40 Correct 94 ms 7088 KB Output is correct
41 Correct 317 ms 7468 KB Output is correct
42 Correct 437 ms 7212 KB Output is correct
43 Correct 402 ms 8780 KB Output is correct
44 Correct 274 ms 7344 KB Output is correct
45 Correct 133 ms 7328 KB Output is correct
46 Correct 79 ms 7216 KB Output is correct
47 Correct 76 ms 6828 KB Output is correct
48 Correct 70 ms 6816 KB Output is correct
49 Correct 92 ms 6960 KB Output is correct
50 Correct 249 ms 7092 KB Output is correct
51 Correct 79 ms 6960 KB Output is correct
52 Runtime error 305 ms 43936 KB Execution killed with signal 11
53 Halted 0 ms 0 KB -