Submission #908044

# Submission time Handle Problem Language Result Execution time Memory
908044 2024-01-16T07:27:56 Z Trisanu_Das New Home (APIO18_new_home) C++17
100 / 100
1606 ms 66092 KB
#include<bits/stdc++.h>
#define ll long long
const int inf = 1e8;
using namespace std;

int x[310005], t[610005], st[1210005], ans[310005];
vector<array<int, 2>> v1[310005];
array<int, 4> v2[1210005];
array<int, 3> qa[310005];

struct comp {
    bool operator () (const int &a, const int &b) const {
        if (x[a] == x[b])
            return a < b;
        return x[a] < x[b];
    }
};

map<int, int, comp> mp;
int u2 = 0, n, k, q;

void calc() {
    int i;
    for (i = 0; i < k; i++) {
        mp[n + 1] = 0;
        for (auto it : v1[i]) {
            auto it1 = mp.upper_bound(it[1]), it2 = it1--;
            v2[u2++] = {(x[it1->first] + x[it2->first] + 1) / 2, x[it2->first], it2->second, it[0]};
            it2->second = it[0];
            if (it1->first == it[1]) {
                it2 = it1--;
                v2[u2++] = {(x[it1->first] + x[it[1]] + 1) / 2, x[it[1]], it2->second, it[0]};
                mp.erase(it2);
            } else
                mp[it[1]] = it[0];
        }
        v2[u2++] = {0, 2 * inf, mp[n + 1], 2 * n + 1};
    }
    sort(v2, v2 + u2);
    int j = 0, e;
    for (i = 0; i < q; i++) {
        while (j < u2 && v2[j][0] <= qa[i][0]) {
            int l = v2[j][2] + 2 * n + 1;
            int r = v2[j][3] + 2 * n + 1;
            while (l < r) {
                if (l % 2 == 1)
                    st[l] = max(v2[j][1], st[l]);
                if (r % 2 == 1)
                    st[r - 1] = max(v2[j][1], st[r - 1]);
                ++l /= 2;
                r = r / 2;
            }
            ++j;
        }
        for (e = qa[i][2] + 2 * n + 1; e >= 1; e = e / 2)
            ans[qa[i][1]] = max(ans[qa[i][1]], st[e] - qa[i][0]);
    }
}

int main() {
    scanf("%d%d%d", &n, &k, &q);
    int i;
    for (i = 0; i < n; i++) {
        int aux;
        scanf("%d%d%d%d", &x[i], &aux, &t[2 * i], &t[2 * i + 1]);
        --aux;
        ++t[2 * i + 1];
        v1[aux].push_back({t[2 * i], i});
        v1[aux].push_back({t[2 * i + 1], i});
    }
    x[n] = -2 * inf;
    x[n + 1] = 2 * inf;
    sort(t, t + 2 * n + 1);
    for (i = 0; i < k; i++) {
        for (auto &it : v1[i])
            it[0] = lower_bound(t, t + 2 * n + 1, it[0]) - t;
        sort(v1[i].begin(), v1[i].end());
    }
    for (i = 0; i < q; i++) {
        scanf("%d%d", &qa[i][0], &qa[i][2]);
        qa[i][2] = upper_bound(t, t + 2 * n + 1, qa[i][2]) - t - 1;
        qa[i][1] = i;
    }
    sort(qa, qa + q);
    mp[n] = 0;
    calc();
    for (i = 0; i < n; i++)
        x[i] = inf - x[i];
    for (i = 0; i < q; i++)
        qa[i][0] = inf - qa[i][0];
    reverse(qa, qa + q);
    u2 = 0;
    memset(st, 0, sizeof(st));
    calc();
    for (i = 0; i < q; i++)
        if (ans[i] >= inf)
            printf("-1\n");
        else
            printf("%d\n", ans[i]);
    return 0;
}

Compilation message

new_home.cpp: In function 'int main()':
new_home.cpp:61:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   61 |     scanf("%d%d%d", &n, &k, &q);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~~~~
new_home.cpp:65:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   65 |         scanf("%d%d%d%d", &x[i], &aux, &t[2 * i], &t[2 * i + 1]);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
new_home.cpp:80:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   80 |         scanf("%d%d", &qa[i][0], &qa[i][2]);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 5 ms 20828 KB Output is correct
2 Correct 7 ms 20808 KB Output is correct
3 Correct 6 ms 20828 KB Output is correct
4 Correct 6 ms 20684 KB Output is correct
5 Correct 6 ms 20824 KB Output is correct
6 Correct 6 ms 20828 KB Output is correct
7 Correct 6 ms 20828 KB Output is correct
8 Correct 7 ms 20828 KB Output is correct
9 Correct 6 ms 20668 KB Output is correct
10 Correct 7 ms 20824 KB Output is correct
11 Correct 6 ms 20824 KB Output is correct
12 Correct 7 ms 20828 KB Output is correct
13 Correct 6 ms 20872 KB Output is correct
14 Correct 6 ms 20828 KB Output is correct
15 Correct 7 ms 21080 KB Output is correct
16 Correct 6 ms 20828 KB Output is correct
17 Correct 6 ms 20828 KB Output is correct
18 Correct 6 ms 20828 KB Output is correct
19 Correct 6 ms 20828 KB Output is correct
20 Correct 6 ms 20828 KB Output is correct
21 Correct 6 ms 20656 KB Output is correct
22 Correct 6 ms 21028 KB Output is correct
23 Correct 7 ms 21080 KB Output is correct
24 Correct 6 ms 20828 KB Output is correct
25 Correct 6 ms 20828 KB Output is correct
26 Correct 6 ms 20828 KB Output is correct
27 Correct 7 ms 20828 KB Output is correct
28 Correct 6 ms 21080 KB Output is correct
29 Correct 7 ms 20672 KB Output is correct
30 Correct 6 ms 20824 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 20828 KB Output is correct
2 Correct 7 ms 20808 KB Output is correct
3 Correct 6 ms 20828 KB Output is correct
4 Correct 6 ms 20684 KB Output is correct
5 Correct 6 ms 20824 KB Output is correct
6 Correct 6 ms 20828 KB Output is correct
7 Correct 6 ms 20828 KB Output is correct
8 Correct 7 ms 20828 KB Output is correct
9 Correct 6 ms 20668 KB Output is correct
10 Correct 7 ms 20824 KB Output is correct
11 Correct 6 ms 20824 KB Output is correct
12 Correct 7 ms 20828 KB Output is correct
13 Correct 6 ms 20872 KB Output is correct
14 Correct 6 ms 20828 KB Output is correct
15 Correct 7 ms 21080 KB Output is correct
16 Correct 6 ms 20828 KB Output is correct
17 Correct 6 ms 20828 KB Output is correct
18 Correct 6 ms 20828 KB Output is correct
19 Correct 6 ms 20828 KB Output is correct
20 Correct 6 ms 20828 KB Output is correct
21 Correct 6 ms 20656 KB Output is correct
22 Correct 6 ms 21028 KB Output is correct
23 Correct 7 ms 21080 KB Output is correct
24 Correct 6 ms 20828 KB Output is correct
25 Correct 6 ms 20828 KB Output is correct
26 Correct 6 ms 20828 KB Output is correct
27 Correct 7 ms 20828 KB Output is correct
28 Correct 6 ms 21080 KB Output is correct
29 Correct 7 ms 20672 KB Output is correct
30 Correct 6 ms 20824 KB Output is correct
31 Correct 184 ms 30980 KB Output is correct
32 Correct 153 ms 28984 KB Output is correct
33 Correct 193 ms 30476 KB Output is correct
34 Correct 182 ms 31168 KB Output is correct
35 Correct 186 ms 30488 KB Output is correct
36 Correct 214 ms 30604 KB Output is correct
37 Correct 171 ms 30544 KB Output is correct
38 Correct 182 ms 30140 KB Output is correct
39 Correct 156 ms 30136 KB Output is correct
40 Correct 160 ms 30468 KB Output is correct
41 Correct 140 ms 30272 KB Output is correct
42 Correct 140 ms 30544 KB Output is correct
43 Correct 100 ms 30804 KB Output is correct
44 Correct 132 ms 30544 KB Output is correct
45 Correct 128 ms 30544 KB Output is correct
46 Correct 116 ms 30560 KB Output is correct
47 Correct 112 ms 30136 KB Output is correct
48 Correct 105 ms 27836 KB Output is correct
49 Correct 119 ms 30124 KB Output is correct
50 Correct 132 ms 30800 KB Output is correct
51 Correct 120 ms 30228 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 654 ms 57288 KB Output is correct
2 Correct 778 ms 51620 KB Output is correct
3 Correct 820 ms 58876 KB Output is correct
4 Correct 667 ms 57180 KB Output is correct
5 Correct 1146 ms 65520 KB Output is correct
6 Correct 823 ms 52944 KB Output is correct
7 Correct 580 ms 58900 KB Output is correct
8 Correct 542 ms 56392 KB Output is correct
9 Correct 541 ms 53828 KB Output is correct
10 Correct 618 ms 52416 KB Output is correct
11 Correct 616 ms 51392 KB Output is correct
12 Correct 600 ms 53236 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 822 ms 53588 KB Output is correct
2 Correct 886 ms 46672 KB Output is correct
3 Correct 1038 ms 51864 KB Output is correct
4 Correct 988 ms 56876 KB Output is correct
5 Correct 826 ms 55376 KB Output is correct
6 Correct 883 ms 55140 KB Output is correct
7 Correct 1606 ms 64184 KB Output is correct
8 Correct 1127 ms 53396 KB Output is correct
9 Correct 770 ms 58360 KB Output is correct
10 Correct 720 ms 56200 KB Output is correct
11 Correct 816 ms 53672 KB Output is correct
12 Correct 844 ms 52308 KB Output is correct
13 Correct 712 ms 51340 KB Output is correct
14 Correct 714 ms 52664 KB Output is correct
15 Correct 766 ms 51312 KB Output is correct
16 Correct 762 ms 52700 KB Output is correct
17 Correct 763 ms 51468 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 20828 KB Output is correct
2 Correct 7 ms 20808 KB Output is correct
3 Correct 6 ms 20828 KB Output is correct
4 Correct 6 ms 20684 KB Output is correct
5 Correct 6 ms 20824 KB Output is correct
6 Correct 6 ms 20828 KB Output is correct
7 Correct 6 ms 20828 KB Output is correct
8 Correct 7 ms 20828 KB Output is correct
9 Correct 6 ms 20668 KB Output is correct
10 Correct 7 ms 20824 KB Output is correct
11 Correct 6 ms 20824 KB Output is correct
12 Correct 7 ms 20828 KB Output is correct
13 Correct 6 ms 20872 KB Output is correct
14 Correct 6 ms 20828 KB Output is correct
15 Correct 7 ms 21080 KB Output is correct
16 Correct 6 ms 20828 KB Output is correct
17 Correct 6 ms 20828 KB Output is correct
18 Correct 6 ms 20828 KB Output is correct
19 Correct 6 ms 20828 KB Output is correct
20 Correct 6 ms 20828 KB Output is correct
21 Correct 6 ms 20656 KB Output is correct
22 Correct 6 ms 21028 KB Output is correct
23 Correct 7 ms 21080 KB Output is correct
24 Correct 6 ms 20828 KB Output is correct
25 Correct 6 ms 20828 KB Output is correct
26 Correct 6 ms 20828 KB Output is correct
27 Correct 7 ms 20828 KB Output is correct
28 Correct 6 ms 21080 KB Output is correct
29 Correct 7 ms 20672 KB Output is correct
30 Correct 6 ms 20824 KB Output is correct
31 Correct 184 ms 30980 KB Output is correct
32 Correct 153 ms 28984 KB Output is correct
33 Correct 193 ms 30476 KB Output is correct
34 Correct 182 ms 31168 KB Output is correct
35 Correct 186 ms 30488 KB Output is correct
36 Correct 214 ms 30604 KB Output is correct
37 Correct 171 ms 30544 KB Output is correct
38 Correct 182 ms 30140 KB Output is correct
39 Correct 156 ms 30136 KB Output is correct
40 Correct 160 ms 30468 KB Output is correct
41 Correct 140 ms 30272 KB Output is correct
42 Correct 140 ms 30544 KB Output is correct
43 Correct 100 ms 30804 KB Output is correct
44 Correct 132 ms 30544 KB Output is correct
45 Correct 128 ms 30544 KB Output is correct
46 Correct 116 ms 30560 KB Output is correct
47 Correct 112 ms 30136 KB Output is correct
48 Correct 105 ms 27836 KB Output is correct
49 Correct 119 ms 30124 KB Output is correct
50 Correct 132 ms 30800 KB Output is correct
51 Correct 120 ms 30228 KB Output is correct
52 Correct 213 ms 30912 KB Output is correct
53 Correct 198 ms 29332 KB Output is correct
54 Correct 184 ms 28624 KB Output is correct
55 Correct 147 ms 29024 KB Output is correct
56 Correct 164 ms 29220 KB Output is correct
57 Correct 137 ms 28788 KB Output is correct
58 Correct 147 ms 29008 KB Output is correct
59 Correct 153 ms 29008 KB Output is correct
60 Correct 156 ms 28964 KB Output is correct
61 Correct 104 ms 29528 KB Output is correct
62 Correct 188 ms 29268 KB Output is correct
63 Correct 164 ms 28812 KB Output is correct
64 Correct 167 ms 28832 KB Output is correct
65 Correct 150 ms 28752 KB Output is correct
66 Correct 155 ms 28884 KB Output is correct
67 Correct 143 ms 28552 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 20828 KB Output is correct
2 Correct 7 ms 20808 KB Output is correct
3 Correct 6 ms 20828 KB Output is correct
4 Correct 6 ms 20684 KB Output is correct
5 Correct 6 ms 20824 KB Output is correct
6 Correct 6 ms 20828 KB Output is correct
7 Correct 6 ms 20828 KB Output is correct
8 Correct 7 ms 20828 KB Output is correct
9 Correct 6 ms 20668 KB Output is correct
10 Correct 7 ms 20824 KB Output is correct
11 Correct 6 ms 20824 KB Output is correct
12 Correct 7 ms 20828 KB Output is correct
13 Correct 6 ms 20872 KB Output is correct
14 Correct 6 ms 20828 KB Output is correct
15 Correct 7 ms 21080 KB Output is correct
16 Correct 6 ms 20828 KB Output is correct
17 Correct 6 ms 20828 KB Output is correct
18 Correct 6 ms 20828 KB Output is correct
19 Correct 6 ms 20828 KB Output is correct
20 Correct 6 ms 20828 KB Output is correct
21 Correct 6 ms 20656 KB Output is correct
22 Correct 6 ms 21028 KB Output is correct
23 Correct 7 ms 21080 KB Output is correct
24 Correct 6 ms 20828 KB Output is correct
25 Correct 6 ms 20828 KB Output is correct
26 Correct 6 ms 20828 KB Output is correct
27 Correct 7 ms 20828 KB Output is correct
28 Correct 6 ms 21080 KB Output is correct
29 Correct 7 ms 20672 KB Output is correct
30 Correct 6 ms 20824 KB Output is correct
31 Correct 184 ms 30980 KB Output is correct
32 Correct 153 ms 28984 KB Output is correct
33 Correct 193 ms 30476 KB Output is correct
34 Correct 182 ms 31168 KB Output is correct
35 Correct 186 ms 30488 KB Output is correct
36 Correct 214 ms 30604 KB Output is correct
37 Correct 171 ms 30544 KB Output is correct
38 Correct 182 ms 30140 KB Output is correct
39 Correct 156 ms 30136 KB Output is correct
40 Correct 160 ms 30468 KB Output is correct
41 Correct 140 ms 30272 KB Output is correct
42 Correct 140 ms 30544 KB Output is correct
43 Correct 100 ms 30804 KB Output is correct
44 Correct 132 ms 30544 KB Output is correct
45 Correct 128 ms 30544 KB Output is correct
46 Correct 116 ms 30560 KB Output is correct
47 Correct 112 ms 30136 KB Output is correct
48 Correct 105 ms 27836 KB Output is correct
49 Correct 119 ms 30124 KB Output is correct
50 Correct 132 ms 30800 KB Output is correct
51 Correct 120 ms 30228 KB Output is correct
52 Correct 654 ms 57288 KB Output is correct
53 Correct 778 ms 51620 KB Output is correct
54 Correct 820 ms 58876 KB Output is correct
55 Correct 667 ms 57180 KB Output is correct
56 Correct 1146 ms 65520 KB Output is correct
57 Correct 823 ms 52944 KB Output is correct
58 Correct 580 ms 58900 KB Output is correct
59 Correct 542 ms 56392 KB Output is correct
60 Correct 541 ms 53828 KB Output is correct
61 Correct 618 ms 52416 KB Output is correct
62 Correct 616 ms 51392 KB Output is correct
63 Correct 600 ms 53236 KB Output is correct
64 Correct 822 ms 53588 KB Output is correct
65 Correct 886 ms 46672 KB Output is correct
66 Correct 1038 ms 51864 KB Output is correct
67 Correct 988 ms 56876 KB Output is correct
68 Correct 826 ms 55376 KB Output is correct
69 Correct 883 ms 55140 KB Output is correct
70 Correct 1606 ms 64184 KB Output is correct
71 Correct 1127 ms 53396 KB Output is correct
72 Correct 770 ms 58360 KB Output is correct
73 Correct 720 ms 56200 KB Output is correct
74 Correct 816 ms 53672 KB Output is correct
75 Correct 844 ms 52308 KB Output is correct
76 Correct 712 ms 51340 KB Output is correct
77 Correct 714 ms 52664 KB Output is correct
78 Correct 766 ms 51312 KB Output is correct
79 Correct 762 ms 52700 KB Output is correct
80 Correct 763 ms 51468 KB Output is correct
81 Correct 213 ms 30912 KB Output is correct
82 Correct 198 ms 29332 KB Output is correct
83 Correct 184 ms 28624 KB Output is correct
84 Correct 147 ms 29024 KB Output is correct
85 Correct 164 ms 29220 KB Output is correct
86 Correct 137 ms 28788 KB Output is correct
87 Correct 147 ms 29008 KB Output is correct
88 Correct 153 ms 29008 KB Output is correct
89 Correct 156 ms 28964 KB Output is correct
90 Correct 104 ms 29528 KB Output is correct
91 Correct 188 ms 29268 KB Output is correct
92 Correct 164 ms 28812 KB Output is correct
93 Correct 167 ms 28832 KB Output is correct
94 Correct 150 ms 28752 KB Output is correct
95 Correct 155 ms 28884 KB Output is correct
96 Correct 143 ms 28552 KB Output is correct
97 Correct 1102 ms 49988 KB Output is correct
98 Correct 861 ms 48728 KB Output is correct
99 Correct 1212 ms 58800 KB Output is correct
100 Correct 1195 ms 65512 KB Output is correct
101 Correct 1006 ms 63696 KB Output is correct
102 Correct 1271 ms 59812 KB Output is correct
103 Correct 997 ms 59212 KB Output is correct
104 Correct 1063 ms 58356 KB Output is correct
105 Correct 873 ms 58264 KB Output is correct
106 Correct 902 ms 58052 KB Output is correct
107 Correct 810 ms 64420 KB Output is correct
108 Correct 844 ms 65304 KB Output is correct
109 Correct 791 ms 62836 KB Output is correct
110 Correct 823 ms 64880 KB Output is correct
111 Correct 885 ms 64960 KB Output is correct
112 Correct 802 ms 61724 KB Output is correct
113 Correct 534 ms 64212 KB Output is correct
114 Correct 965 ms 66092 KB Output is correct
115 Correct 964 ms 64444 KB Output is correct
116 Correct 882 ms 63696 KB Output is correct
117 Correct 860 ms 61984 KB Output is correct
118 Correct 782 ms 62128 KB Output is correct
119 Correct 685 ms 51476 KB Output is correct
120 Correct 539 ms 54712 KB Output is correct
121 Correct 577 ms 57760 KB Output is correct
122 Correct 537 ms 57592 KB Output is correct
123 Correct 600 ms 58304 KB Output is correct
124 Correct 690 ms 60304 KB Output is correct
125 Correct 612 ms 58672 KB Output is correct
126 Correct 753 ms 62488 KB Output is correct