답안 #439917

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
439917 2021-07-01T08:16:16 Z VladM 새 집 (APIO18_new_home) C++14
12 / 100
2465 ms 42928 KB
#include <bits/stdc++.h>

using namespace std;

#define DIM 60007

#define KDIM 407

int n, m, k, ans[DIM], x, t, a, b, c, p, l, y, q;

pair<int, int> p1, p2;

struct event
{
    int x, p, t, c;
};

vector<event> Q;

set<pair<int, int> > s[KDIM];

bool cmp(event a, event b)
{
    if(a.t==b.t)
    {
        if(a.c==b.c) return a.x<b.x;
        return a.c<b.c;
    }
    return a.t<b.t;
}

int main()
{
    scanf("%d%d%d", &n, &k, &q);
    for(int i=1; i<=n; i++)
    {
        scanf("%d%d%d%d", &x, &t, &a, &b);
        Q.push_back({x, t, a, 0});
        Q.push_back({x, t, b, 2});
    }
    for(int i=1; i<=q; i++)
    {
        scanf("%d%d", &l, &y);
        Q.push_back({l, i, y, 1});
    }
    sort(Q.begin(), Q.end(), cmp);
    for(int i=0; i<Q.size(); i++)
    {
        x=Q[i].x;
        p=Q[i].p;
        t=Q[i].t;
        c=Q[i].c;
        //printf("%d %d %d %d\n", x, p, t, c);
        if(c==0) s[p].insert({x, i});
        if(c==2)
        {
            auto it=s[p].lower_bound({x, 0});
            s[p].erase(*it);
        }
        if(c==1)
        {
            if(s[1].empty())
            {
                ans[p]=-1;
                continue;
            }
            auto it=s[1].lower_bound({x, 0});
            auto it1=it;
            it1--;
            if(it==s[1].end())
            {
                p1=*it1;
                ans[p]=x-p1.first;
                //printf("%d\n", x-p1.first);
            }
            else if(it==s[1].begin())
            {
                p2=*it;
                ans[p]=p2.first-x;
                //printf("%d\n", p2.first-x);
            }
            else
            {
                p1=*it1;
                p2=*it;
                ans[p]=min(x-p1.first, p2.first-x);
                //printf("%d %d\n", x-p1.first, p2.first-x);
            }
            for(int i=2; i<=k; i++)
            {
                if(s[i].empty())
                {
                    ans[p]=-1;
                    break;
                }
                auto it=s[i].lower_bound({x, 0});
                auto it1=it;
                it1--;
                if(it==s[i].end())
                {
                    p1=*it1;
                    ans[p]=max(ans[p], x-p1.first);
                    //printf("%d\n", x-p1.first);
                }
                else if(it==s[i].begin())
                {
                    p2=*it;
                    ans[p]=max(ans[p], p2.first-x);
                    //printf("%d\n", p2.first-x);
                }
                else
                {
                    p1=*it1;
                    p2=*it;
                    ans[p]=max(ans[p], min(x-p1.first, p2.first-x));
                    //printf("%d %d\n", x-p1.first, p2.first-x);
                }
            }
        }
    }
    for(int i=1; i<=q; i++) printf("%d\n", ans[i]);
    return 0;
}

Compilation message

new_home.cpp: In function 'int main()':
new_home.cpp:47:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<event>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   47 |     for(int i=0; i<Q.size(); i++)
      |                  ~^~~~~~~~~
new_home.cpp:34:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   34 |     scanf("%d%d%d", &n, &k, &q);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~~~~
new_home.cpp:37:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   37 |         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 328 KB Output is correct
3 Correct 1 ms 324 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 2 ms 328 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 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 3 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 2 ms 332 KB Output is correct
16 Correct 2 ms 332 KB Output is correct
17 Correct 2 ms 336 KB Output is correct
18 Correct 2 ms 324 KB Output is correct
19 Correct 2 ms 332 KB Output is correct
20 Correct 2 ms 332 KB Output is correct
21 Correct 3 ms 332 KB Output is correct
22 Correct 3 ms 332 KB Output is correct
23 Correct 3 ms 332 KB Output is correct
24 Correct 2 ms 332 KB Output is correct
25 Correct 2 ms 332 KB Output is correct
26 Correct 1 ms 460 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 328 KB Output is correct
3 Correct 1 ms 324 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 2 ms 328 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 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 3 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 2 ms 332 KB Output is correct
16 Correct 2 ms 332 KB Output is correct
17 Correct 2 ms 336 KB Output is correct
18 Correct 2 ms 324 KB Output is correct
19 Correct 2 ms 332 KB Output is correct
20 Correct 2 ms 332 KB Output is correct
21 Correct 3 ms 332 KB Output is correct
22 Correct 3 ms 332 KB Output is correct
23 Correct 3 ms 332 KB Output is correct
24 Correct 2 ms 332 KB Output is correct
25 Correct 2 ms 332 KB Output is correct
26 Correct 1 ms 460 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 2465 ms 9528 KB Output is correct
32 Correct 94 ms 5516 KB Output is correct
33 Correct 199 ms 7596 KB Output is correct
34 Correct 1793 ms 7748 KB Output is correct
35 Correct 1090 ms 9564 KB Output is correct
36 Correct 244 ms 9328 KB Output is correct
37 Correct 187 ms 6828 KB Output is correct
38 Correct 121 ms 6684 KB Output is correct
39 Correct 108 ms 6688 KB Output is correct
40 Correct 107 ms 6792 KB Output is correct
41 Correct 383 ms 6928 KB Output is correct
42 Correct 256 ms 6808 KB Output is correct
43 Correct 666 ms 9128 KB Output is correct
44 Correct 288 ms 6952 KB Output is correct
45 Correct 154 ms 7016 KB Output is correct
46 Correct 105 ms 6840 KB Output is correct
47 Correct 83 ms 6712 KB Output is correct
48 Correct 84 ms 6708 KB Output is correct
49 Correct 107 ms 6608 KB Output is correct
50 Correct 239 ms 6704 KB Output is correct
51 Correct 88 ms 6700 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Runtime error 386 ms 42928 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 380 ms 42300 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 328 KB Output is correct
3 Correct 1 ms 324 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 2 ms 328 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 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 3 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 2 ms 332 KB Output is correct
16 Correct 2 ms 332 KB Output is correct
17 Correct 2 ms 336 KB Output is correct
18 Correct 2 ms 324 KB Output is correct
19 Correct 2 ms 332 KB Output is correct
20 Correct 2 ms 332 KB Output is correct
21 Correct 3 ms 332 KB Output is correct
22 Correct 3 ms 332 KB Output is correct
23 Correct 3 ms 332 KB Output is correct
24 Correct 2 ms 332 KB Output is correct
25 Correct 2 ms 332 KB Output is correct
26 Correct 1 ms 460 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 2465 ms 9528 KB Output is correct
32 Correct 94 ms 5516 KB Output is correct
33 Correct 199 ms 7596 KB Output is correct
34 Correct 1793 ms 7748 KB Output is correct
35 Correct 1090 ms 9564 KB Output is correct
36 Correct 244 ms 9328 KB Output is correct
37 Correct 187 ms 6828 KB Output is correct
38 Correct 121 ms 6684 KB Output is correct
39 Correct 108 ms 6688 KB Output is correct
40 Correct 107 ms 6792 KB Output is correct
41 Correct 383 ms 6928 KB Output is correct
42 Correct 256 ms 6808 KB Output is correct
43 Correct 666 ms 9128 KB Output is correct
44 Correct 288 ms 6952 KB Output is correct
45 Correct 154 ms 7016 KB Output is correct
46 Correct 105 ms 6840 KB Output is correct
47 Correct 83 ms 6712 KB Output is correct
48 Correct 84 ms 6708 KB Output is correct
49 Correct 107 ms 6608 KB Output is correct
50 Correct 239 ms 6704 KB Output is correct
51 Correct 88 ms 6700 KB Output is correct
52 Runtime error 72 ms 9396 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 328 KB Output is correct
3 Correct 1 ms 324 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 2 ms 328 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 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 3 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 2 ms 332 KB Output is correct
16 Correct 2 ms 332 KB Output is correct
17 Correct 2 ms 336 KB Output is correct
18 Correct 2 ms 324 KB Output is correct
19 Correct 2 ms 332 KB Output is correct
20 Correct 2 ms 332 KB Output is correct
21 Correct 3 ms 332 KB Output is correct
22 Correct 3 ms 332 KB Output is correct
23 Correct 3 ms 332 KB Output is correct
24 Correct 2 ms 332 KB Output is correct
25 Correct 2 ms 332 KB Output is correct
26 Correct 1 ms 460 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 2465 ms 9528 KB Output is correct
32 Correct 94 ms 5516 KB Output is correct
33 Correct 199 ms 7596 KB Output is correct
34 Correct 1793 ms 7748 KB Output is correct
35 Correct 1090 ms 9564 KB Output is correct
36 Correct 244 ms 9328 KB Output is correct
37 Correct 187 ms 6828 KB Output is correct
38 Correct 121 ms 6684 KB Output is correct
39 Correct 108 ms 6688 KB Output is correct
40 Correct 107 ms 6792 KB Output is correct
41 Correct 383 ms 6928 KB Output is correct
42 Correct 256 ms 6808 KB Output is correct
43 Correct 666 ms 9128 KB Output is correct
44 Correct 288 ms 6952 KB Output is correct
45 Correct 154 ms 7016 KB Output is correct
46 Correct 105 ms 6840 KB Output is correct
47 Correct 83 ms 6712 KB Output is correct
48 Correct 84 ms 6708 KB Output is correct
49 Correct 107 ms 6608 KB Output is correct
50 Correct 239 ms 6704 KB Output is correct
51 Correct 88 ms 6700 KB Output is correct
52 Runtime error 386 ms 42928 KB Execution killed with signal 11
53 Halted 0 ms 0 KB -