답안 #259709

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
259709 2020-08-08T11:32:21 Z Kastanda 새 집 (APIO18_new_home) C++11
47 / 100
5000 ms 293192 KB
// M
#include<bits/stdc++.h>
using namespace std;
const int N = 300005, INF = 1e9 + 9;
int n, q, k, X[N], T[N], L[N], R[N], Y[N], Z[N], RS[N];
vector < int > U;
multiset < int > ST[N];
struct Set {
        priority_queue < int > PQ, DL;
        inline void Insert(int val) {
                PQ.push(val);
        }
        inline void Delete(int val) {
                DL.push(val);
        }
        inline int GetMax() {
                while (DL.size() && DL.top() == PQ.top())
                        DL.pop(), PQ.pop();
                return PQ.size() ? PQ.top() : INT_MIN;
        }
};
Set D[N * 2][2];
inline int GetId(int val)
{
        return (int)(lower_bound(U.begin(), U.end(), val) - U.begin());
}
inline void Add(int l, int r, int a, int b)
{
        l += (int)U.size();
        r += (int)U.size();
        for (; l < r; l >>= 1, r >>= 1)
        {
                if (l & 1) D[l][a].Insert(b), l ++;
                if (r & 1) r --, D[r][a].Insert(b);
        }
}
inline void Del(int l, int r, int a, int b)
{
        l += (int)U.size();
        r += (int)U.size();
        for (; l < r; l >>= 1, r >>= 1)
        {
                if (l & 1) D[l][a].Delete(b), l ++;
                if (r & 1) r --, D[r][a].Delete(b);
        }
}
inline pair < int , int > Get(int i)
{
        pair < int , int > rt = {-INF, -INF};
        for (i += (int)U.size(); i; i >>= 1)
        {
                rt.first = max(rt.first, D[i][0].GetMax());
                rt.second = max(rt.second, D[i][1].GetMax());
        }
        return rt;
}
inline void Adder(int l, int r, int a, int b)
{
        l = GetId(l);
        r = GetId(r);
        Add(l, r, a, b);
}
inline void Deler(int l, int r, int a, int b)
{
        l = GetId(l);
        r = GetId(r);
        Del(l, r, a, b);
}
inline void Do(int l, int r)
{
        int mid = (l + r + 1) >> 1;
        // [l, mid)
        Adder(l, mid, 1, -l);
        // [mid, r]
        Adder(mid, r + 1, 0, r);
}
inline void Undo(int l, int r)
{
        int mid = (l + r + 1) >> 1;
        // [l, mid)
        Deler(l, mid, 1, -l);
        // [mid, r]
        Deler(mid, r + 1, 0, r);
}
inline void Add(int tp, int x)
{
        auto it = ST[tp].lower_bound(x);
        assert(it != ST[tp].end());
        if (* it == x)
                return void(ST[tp].insert(x));
        int r = * it; it --;
        int l = * it;
        Undo(l, r);
        Do(l, x);
        Do(x, r);
        ST[tp].insert(x);
}
inline void Del(int tp, int x)
{
        auto it = ST[tp].lower_bound(x);
        assert(* it == x);
        it = ST[tp].erase(it);
        if (* it == x)
                return ;
        int r = * it; it --;
        int l = * it;
        Undo(l, x);
        Undo(x, r);
        Do(l, r);
}
int main()
{
        scanf("%d%d%d", &n, &k, &q);
        vector < pair < int , int > > E;
        for (int i = 1; i <= n; i ++)
        {
                scanf("%d%d%d%d", &X[i], &T[i], &L[i], &R[i]);
                E.push_back({L[i], -i});
                E.push_back({R[i] + 1, -i});
        }
        for (int i = 1; i <= q; i ++)
        {
                scanf("%d%d", &Y[i], &Z[i]);
                E.push_back({Z[i], i});
                U.push_back(Y[i]);
        }
        sort(E.begin(), E.end());
        sort(U.begin(), U.end());
        U.resize(unique(U.begin(), U.end()) - U.begin());
        for (int i = 1; i <= k; i ++)
        {
                ST[i].insert(-INF);
                ST[i].insert(INF);
                Do(-INF, INF);
        }
        for (auto e : E)
        {
                int i = e.second;
                if (i < 0)
                {
                        i = -i;
                        if (e.first == L[i])
                                Add(T[i], X[i]);
                        else
                                Del(T[i], X[i]);
                        continue;
                }
                int y = GetId(Y[i]);
                pair < int , int> rt = Get(y);
                RS[i] = max(rt.first - Y[i], rt.second + Y[i]);
                if (RS[i] > (int)1e8)
                        RS[i] = -1;
        }
        for (int i = 1; i <= q; i ++)
                printf("%d\n", RS[i]);
        return 0;
}

Compilation message

new_home.cpp: In function 'int main()':
new_home.cpp:113:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d%d%d", &n, &k, &q);
         ~~~~~^~~~~~~~~~~~~~~~~~~~~~
new_home.cpp:117:22: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
                 scanf("%d%d%d%d", &X[i], &T[i], &L[i], &R[i]);
                 ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
new_home.cpp:123:22: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
                 scanf("%d%d", &Y[i], &Z[i]);
                 ~~~~~^~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 50 ms 89600 KB Output is correct
2 Correct 49 ms 89592 KB Output is correct
3 Correct 50 ms 89592 KB Output is correct
4 Correct 49 ms 89600 KB Output is correct
5 Correct 50 ms 89592 KB Output is correct
6 Correct 52 ms 89720 KB Output is correct
7 Correct 51 ms 89720 KB Output is correct
8 Correct 52 ms 89848 KB Output is correct
9 Correct 51 ms 89720 KB Output is correct
10 Correct 58 ms 89720 KB Output is correct
11 Correct 52 ms 89724 KB Output is correct
12 Correct 51 ms 89720 KB Output is correct
13 Correct 53 ms 89848 KB Output is correct
14 Correct 51 ms 89720 KB Output is correct
15 Correct 51 ms 89720 KB Output is correct
16 Correct 51 ms 89720 KB Output is correct
17 Correct 52 ms 89720 KB Output is correct
18 Correct 52 ms 89720 KB Output is correct
19 Correct 52 ms 89720 KB Output is correct
20 Correct 52 ms 89720 KB Output is correct
21 Correct 49 ms 89664 KB Output is correct
22 Correct 51 ms 89720 KB Output is correct
23 Correct 51 ms 89848 KB Output is correct
24 Correct 52 ms 89724 KB Output is correct
25 Correct 53 ms 89720 KB Output is correct
26 Correct 53 ms 89720 KB Output is correct
27 Correct 50 ms 89720 KB Output is correct
28 Correct 52 ms 89720 KB Output is correct
29 Correct 52 ms 89848 KB Output is correct
30 Correct 50 ms 89728 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 50 ms 89600 KB Output is correct
2 Correct 49 ms 89592 KB Output is correct
3 Correct 50 ms 89592 KB Output is correct
4 Correct 49 ms 89600 KB Output is correct
5 Correct 50 ms 89592 KB Output is correct
6 Correct 52 ms 89720 KB Output is correct
7 Correct 51 ms 89720 KB Output is correct
8 Correct 52 ms 89848 KB Output is correct
9 Correct 51 ms 89720 KB Output is correct
10 Correct 58 ms 89720 KB Output is correct
11 Correct 52 ms 89724 KB Output is correct
12 Correct 51 ms 89720 KB Output is correct
13 Correct 53 ms 89848 KB Output is correct
14 Correct 51 ms 89720 KB Output is correct
15 Correct 51 ms 89720 KB Output is correct
16 Correct 51 ms 89720 KB Output is correct
17 Correct 52 ms 89720 KB Output is correct
18 Correct 52 ms 89720 KB Output is correct
19 Correct 52 ms 89720 KB Output is correct
20 Correct 52 ms 89720 KB Output is correct
21 Correct 49 ms 89664 KB Output is correct
22 Correct 51 ms 89720 KB Output is correct
23 Correct 51 ms 89848 KB Output is correct
24 Correct 52 ms 89724 KB Output is correct
25 Correct 53 ms 89720 KB Output is correct
26 Correct 53 ms 89720 KB Output is correct
27 Correct 50 ms 89720 KB Output is correct
28 Correct 52 ms 89720 KB Output is correct
29 Correct 52 ms 89848 KB Output is correct
30 Correct 50 ms 89728 KB Output is correct
31 Correct 1648 ms 132460 KB Output is correct
32 Correct 148 ms 95204 KB Output is correct
33 Correct 1116 ms 115720 KB Output is correct
34 Correct 1661 ms 133140 KB Output is correct
35 Correct 1468 ms 126692 KB Output is correct
36 Correct 1039 ms 114680 KB Output is correct
37 Correct 853 ms 117036 KB Output is correct
38 Correct 612 ms 110820 KB Output is correct
39 Correct 577 ms 112360 KB Output is correct
40 Correct 535 ms 110692 KB Output is correct
41 Correct 1390 ms 119528 KB Output is correct
42 Correct 1376 ms 120904 KB Output is correct
43 Correct 125 ms 98644 KB Output is correct
44 Correct 1159 ms 118628 KB Output is correct
45 Correct 1075 ms 115368 KB Output is correct
46 Correct 1008 ms 112740 KB Output is correct
47 Correct 555 ms 118500 KB Output is correct
48 Correct 522 ms 115496 KB Output is correct
49 Correct 665 ms 118464 KB Output is correct
50 Correct 778 ms 123260 KB Output is correct
51 Correct 683 ms 116068 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 5086 ms 293192 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 5073 ms 282076 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 50 ms 89600 KB Output is correct
2 Correct 49 ms 89592 KB Output is correct
3 Correct 50 ms 89592 KB Output is correct
4 Correct 49 ms 89600 KB Output is correct
5 Correct 50 ms 89592 KB Output is correct
6 Correct 52 ms 89720 KB Output is correct
7 Correct 51 ms 89720 KB Output is correct
8 Correct 52 ms 89848 KB Output is correct
9 Correct 51 ms 89720 KB Output is correct
10 Correct 58 ms 89720 KB Output is correct
11 Correct 52 ms 89724 KB Output is correct
12 Correct 51 ms 89720 KB Output is correct
13 Correct 53 ms 89848 KB Output is correct
14 Correct 51 ms 89720 KB Output is correct
15 Correct 51 ms 89720 KB Output is correct
16 Correct 51 ms 89720 KB Output is correct
17 Correct 52 ms 89720 KB Output is correct
18 Correct 52 ms 89720 KB Output is correct
19 Correct 52 ms 89720 KB Output is correct
20 Correct 52 ms 89720 KB Output is correct
21 Correct 49 ms 89664 KB Output is correct
22 Correct 51 ms 89720 KB Output is correct
23 Correct 51 ms 89848 KB Output is correct
24 Correct 52 ms 89724 KB Output is correct
25 Correct 53 ms 89720 KB Output is correct
26 Correct 53 ms 89720 KB Output is correct
27 Correct 50 ms 89720 KB Output is correct
28 Correct 52 ms 89720 KB Output is correct
29 Correct 52 ms 89848 KB Output is correct
30 Correct 50 ms 89728 KB Output is correct
31 Correct 1648 ms 132460 KB Output is correct
32 Correct 148 ms 95204 KB Output is correct
33 Correct 1116 ms 115720 KB Output is correct
34 Correct 1661 ms 133140 KB Output is correct
35 Correct 1468 ms 126692 KB Output is correct
36 Correct 1039 ms 114680 KB Output is correct
37 Correct 853 ms 117036 KB Output is correct
38 Correct 612 ms 110820 KB Output is correct
39 Correct 577 ms 112360 KB Output is correct
40 Correct 535 ms 110692 KB Output is correct
41 Correct 1390 ms 119528 KB Output is correct
42 Correct 1376 ms 120904 KB Output is correct
43 Correct 125 ms 98644 KB Output is correct
44 Correct 1159 ms 118628 KB Output is correct
45 Correct 1075 ms 115368 KB Output is correct
46 Correct 1008 ms 112740 KB Output is correct
47 Correct 555 ms 118500 KB Output is correct
48 Correct 522 ms 115496 KB Output is correct
49 Correct 665 ms 118464 KB Output is correct
50 Correct 778 ms 123260 KB Output is correct
51 Correct 683 ms 116068 KB Output is correct
52 Correct 807 ms 127076 KB Output is correct
53 Correct 803 ms 125280 KB Output is correct
54 Correct 1305 ms 136840 KB Output is correct
55 Correct 1042 ms 127224 KB Output is correct
56 Correct 919 ms 127584 KB Output is correct
57 Correct 1149 ms 123196 KB Output is correct
58 Correct 1144 ms 125840 KB Output is correct
59 Correct 1129 ms 127332 KB Output is correct
60 Correct 1269 ms 124272 KB Output is correct
61 Correct 156 ms 105188 KB Output is correct
62 Correct 836 ms 126564 KB Output is correct
63 Correct 1081 ms 132708 KB Output is correct
64 Correct 1256 ms 133860 KB Output is correct
65 Correct 1391 ms 131172 KB Output is correct
66 Correct 1362 ms 123076 KB Output is correct
67 Correct 310 ms 102268 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 50 ms 89600 KB Output is correct
2 Correct 49 ms 89592 KB Output is correct
3 Correct 50 ms 89592 KB Output is correct
4 Correct 49 ms 89600 KB Output is correct
5 Correct 50 ms 89592 KB Output is correct
6 Correct 52 ms 89720 KB Output is correct
7 Correct 51 ms 89720 KB Output is correct
8 Correct 52 ms 89848 KB Output is correct
9 Correct 51 ms 89720 KB Output is correct
10 Correct 58 ms 89720 KB Output is correct
11 Correct 52 ms 89724 KB Output is correct
12 Correct 51 ms 89720 KB Output is correct
13 Correct 53 ms 89848 KB Output is correct
14 Correct 51 ms 89720 KB Output is correct
15 Correct 51 ms 89720 KB Output is correct
16 Correct 51 ms 89720 KB Output is correct
17 Correct 52 ms 89720 KB Output is correct
18 Correct 52 ms 89720 KB Output is correct
19 Correct 52 ms 89720 KB Output is correct
20 Correct 52 ms 89720 KB Output is correct
21 Correct 49 ms 89664 KB Output is correct
22 Correct 51 ms 89720 KB Output is correct
23 Correct 51 ms 89848 KB Output is correct
24 Correct 52 ms 89724 KB Output is correct
25 Correct 53 ms 89720 KB Output is correct
26 Correct 53 ms 89720 KB Output is correct
27 Correct 50 ms 89720 KB Output is correct
28 Correct 52 ms 89720 KB Output is correct
29 Correct 52 ms 89848 KB Output is correct
30 Correct 50 ms 89728 KB Output is correct
31 Correct 1648 ms 132460 KB Output is correct
32 Correct 148 ms 95204 KB Output is correct
33 Correct 1116 ms 115720 KB Output is correct
34 Correct 1661 ms 133140 KB Output is correct
35 Correct 1468 ms 126692 KB Output is correct
36 Correct 1039 ms 114680 KB Output is correct
37 Correct 853 ms 117036 KB Output is correct
38 Correct 612 ms 110820 KB Output is correct
39 Correct 577 ms 112360 KB Output is correct
40 Correct 535 ms 110692 KB Output is correct
41 Correct 1390 ms 119528 KB Output is correct
42 Correct 1376 ms 120904 KB Output is correct
43 Correct 125 ms 98644 KB Output is correct
44 Correct 1159 ms 118628 KB Output is correct
45 Correct 1075 ms 115368 KB Output is correct
46 Correct 1008 ms 112740 KB Output is correct
47 Correct 555 ms 118500 KB Output is correct
48 Correct 522 ms 115496 KB Output is correct
49 Correct 665 ms 118464 KB Output is correct
50 Correct 778 ms 123260 KB Output is correct
51 Correct 683 ms 116068 KB Output is correct
52 Execution timed out 5086 ms 293192 KB Time limit exceeded
53 Halted 0 ms 0 KB -