답안 #1104502

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1104502 2024-10-24T01:09:00 Z Boycl07 새 집 (APIO18_new_home) C++17
100 / 100
2625 ms 118616 KB
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;


#define rep(i, n) for(int i = 1; (i) <= (n); ++i)
#define forn(i, l, r) for(int i = (l); i <= (r); ++i)
#define ford(i, r, l) for(int i = (r); i >= (l); --i)
#define FOR(i, n) for(int i = 0; i < (n); ++i)
#define FORD(i, n) for(int i = ((n) - 1); i >= 0; --i)
#define fi first
#define se second
#define pii pair<int, int>
#define pll pair<ll, ll>
#define pb push_back
#define endl "\n"
#define task "note"
#define sz(a) int(a.size())
#define C(x, y) make_pair(x, y)
#define all(a) (a).begin(), (a).end()
#define bit(i, mask) (mask >> i & 1)

template<typename T> bool maximize(T &res, const T &val) { if (res < val){ res = val; return true; }; return false; }
template<typename T> bool minimize(T &res, const T &val) { if (res > val){ res = val; return true; }; return false; }

inline int readInt()       {char c;while(c=getchar(),c!='-'&&(c<'0'||c>'9'));bool sign=(c=='-');if(sign)c=getchar();int n=c-'0';while(c=getchar(),c>='0'&&c<='9')n=10*n+c-'0';return(!sign)?n:-n;}
inline ll readLong()       {char c;while(c=getchar(),c!='-'&&(c<'0'||c>'9'));bool sign=(c=='-');if(sign)c=getchar();ll  n=c-'0';while(c=getchar(),c>='0'&&c<='9')n=10*n+c-'0';return(!sign)?n:-n;}
inline string readString() {char c;while(c=getchar(),c==' '||c=='\n'||c=='\t');string s({c});while(c=getchar(),c!=EOF&&c!=' '&&c!='\n'&&c!='\t')s+=c;return s;}

const int N = 6e5 + 3;
const int M = 5e3 + 100;
const int LIM = 5e5 + 3;
const int LOG = 16;
const int MOD = 1e9 + 7;
const int INF = 1e9 + 33;
const ll LINF = 2e16 + 33;


int n, k, q;

multiset<int> s[N];
int st[N << 1];

int X[N], T[N], A[N], B[N];
int lim;

void update(int id, int val)
{
    for(st[id += lim] = val; id >>= 1;) st[id] = max(st[id << 1], st[id << 1 | 1]);
}

int get(int l, int r)
{
    int res = -INF;
    for(l += lim, r += lim + 1; l < r; l >>= 1, r >>= 1)
    {
        if(l & 1) maximize(res, st[l++]);
        if(r & 1) maximize(res, st[--r]);
    }
    return res;
}

int ans[N];

void solve()
{

    cin >> n >> k >> q;

    vector<pii> zip;

    vector<array<int, 4>> lines;
    lim = n + k;
    rep(i, n) cin >> X[i] >> T[i] >> A[i] >> B[i], zip.pb({X[i], i});
    rep(i, k) s[i].insert(i), s[i].insert(INF), update(i, INF);

    sort(all(zip));
    rep(i, n)
    {
        X[i] = lower_bound(all(zip), make_pair(X[i], i)) - zip.begin() + 1;

        lines.pb({A[i], X[i] + k, T[i], 0});
        lines.pb({B[i] + 1, X[i] + k, T[i], 1});

    }
    rep(i, q)
    {
        int l, y;
        cin >> y >> l;
        lines.pb({l, INF, y, -i});
    }

    sort(all(lines));

    for(auto &[x, y, t, type] : lines)
    {
        if(type == 0)
        {
            auto it = s[t].upper_bound(y);
            int r = *it;
            int l = *(--it);

            update(l, y);
            update(y, r);
            s[t].insert(y);
        }
        else if(type < 0)
        {
            int lb = 0, rb = 1e9, res = -1;
            while(lb <= rb)
            {
                int mid = lb + rb >> 1;
                int l = lower_bound(all(zip), make_pair(t - mid, -INF)) - zip.begin() + k;
                int r = upper_bound(all(zip), make_pair(t + mid, INF)) - zip.begin() + k;

                if(get(1, l) <= r) res = mid, rb = mid - 1;
                else lb = mid + 1;
            }
            ans[-type] = res;
        }
        else
        {
            s[t].erase(s[t].find(y));
            auto it = s[t].upper_bound(y);
            int r = *it;
            int l = *(--it);
            update(l, r);
            update(y, -INF);
        }
    }
    rep(i, q) cout << ans[i] << endl;
}

signed main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);

    int TC = 1;

    if(fopen(task".inp", "r"))
    {
        freopen(task".inp", "r", stdin);
        freopen(task".out", "w", stdout);
    }



    while(TC--)
    {
        solve();
    }

    return 0;
}

Compilation message

new_home.cpp: In function 'void solve()':
new_home.cpp:114:30: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
  114 |                 int mid = lb + rb >> 1;
      |                           ~~~^~~~
new_home.cpp: In function 'int main()':
new_home.cpp:145:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  145 |         freopen(task".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
new_home.cpp:146:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  146 |         freopen(task".out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 40784 KB Output is correct
2 Correct 8 ms 40784 KB Output is correct
3 Correct 7 ms 40784 KB Output is correct
4 Correct 7 ms 40784 KB Output is correct
5 Correct 8 ms 40784 KB Output is correct
6 Correct 8 ms 40784 KB Output is correct
7 Correct 7 ms 40784 KB Output is correct
8 Correct 8 ms 40784 KB Output is correct
9 Correct 11 ms 40784 KB Output is correct
10 Correct 8 ms 40784 KB Output is correct
11 Correct 7 ms 40784 KB Output is correct
12 Correct 8 ms 40784 KB Output is correct
13 Correct 7 ms 40652 KB Output is correct
14 Correct 7 ms 40784 KB Output is correct
15 Correct 8 ms 40784 KB Output is correct
16 Correct 8 ms 40784 KB Output is correct
17 Correct 8 ms 40884 KB Output is correct
18 Correct 7 ms 40784 KB Output is correct
19 Correct 7 ms 40784 KB Output is correct
20 Correct 9 ms 30544 KB Output is correct
21 Correct 8 ms 40800 KB Output is correct
22 Correct 11 ms 40784 KB Output is correct
23 Correct 8 ms 40888 KB Output is correct
24 Correct 8 ms 40784 KB Output is correct
25 Correct 9 ms 40784 KB Output is correct
26 Correct 9 ms 40784 KB Output is correct
27 Correct 9 ms 40784 KB Output is correct
28 Correct 9 ms 40784 KB Output is correct
29 Correct 10 ms 40952 KB Output is correct
30 Correct 19 ms 30544 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 40784 KB Output is correct
2 Correct 8 ms 40784 KB Output is correct
3 Correct 7 ms 40784 KB Output is correct
4 Correct 7 ms 40784 KB Output is correct
5 Correct 8 ms 40784 KB Output is correct
6 Correct 8 ms 40784 KB Output is correct
7 Correct 7 ms 40784 KB Output is correct
8 Correct 8 ms 40784 KB Output is correct
9 Correct 11 ms 40784 KB Output is correct
10 Correct 8 ms 40784 KB Output is correct
11 Correct 7 ms 40784 KB Output is correct
12 Correct 8 ms 40784 KB Output is correct
13 Correct 7 ms 40652 KB Output is correct
14 Correct 7 ms 40784 KB Output is correct
15 Correct 8 ms 40784 KB Output is correct
16 Correct 8 ms 40784 KB Output is correct
17 Correct 8 ms 40884 KB Output is correct
18 Correct 7 ms 40784 KB Output is correct
19 Correct 7 ms 40784 KB Output is correct
20 Correct 9 ms 30544 KB Output is correct
21 Correct 8 ms 40800 KB Output is correct
22 Correct 11 ms 40784 KB Output is correct
23 Correct 8 ms 40888 KB Output is correct
24 Correct 8 ms 40784 KB Output is correct
25 Correct 9 ms 40784 KB Output is correct
26 Correct 9 ms 40784 KB Output is correct
27 Correct 9 ms 40784 KB Output is correct
28 Correct 9 ms 40784 KB Output is correct
29 Correct 10 ms 40952 KB Output is correct
30 Correct 19 ms 30544 KB Output is correct
31 Correct 423 ms 45108 KB Output is correct
32 Correct 176 ms 48832 KB Output is correct
33 Correct 412 ms 48960 KB Output is correct
34 Correct 345 ms 49724 KB Output is correct
35 Correct 418 ms 52540 KB Output is correct
36 Correct 452 ms 50668 KB Output is correct
37 Correct 419 ms 48188 KB Output is correct
38 Correct 380 ms 48704 KB Output is correct
39 Correct 309 ms 48748 KB Output is correct
40 Correct 308 ms 46652 KB Output is correct
41 Correct 222 ms 43992 KB Output is correct
42 Correct 200 ms 49736 KB Output is correct
43 Correct 150 ms 50920 KB Output is correct
44 Correct 223 ms 48820 KB Output is correct
45 Correct 239 ms 46132 KB Output is correct
46 Correct 289 ms 44152 KB Output is correct
47 Correct 194 ms 46392 KB Output is correct
48 Correct 216 ms 41544 KB Output is correct
49 Correct 236 ms 48696 KB Output is correct
50 Correct 243 ms 47488 KB Output is correct
51 Correct 257 ms 47420 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1335 ms 81792 KB Output is correct
2 Correct 2131 ms 88640 KB Output is correct
3 Correct 1498 ms 114172 KB Output is correct
4 Correct 1513 ms 100336 KB Output is correct
5 Correct 2244 ms 85060 KB Output is correct
6 Correct 2234 ms 78904 KB Output is correct
7 Correct 1315 ms 115536 KB Output is correct
8 Correct 1383 ms 96764 KB Output is correct
9 Correct 1771 ms 85480 KB Output is correct
10 Correct 2323 ms 89380 KB Output is correct
11 Correct 1862 ms 79104 KB Output is correct
12 Correct 1863 ms 86232 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1892 ms 89200 KB Output is correct
2 Correct 865 ms 78132 KB Output is correct
3 Correct 2625 ms 78164 KB Output is correct
4 Correct 1335 ms 106580 KB Output is correct
5 Correct 1274 ms 94248 KB Output is correct
6 Correct 1292 ms 87564 KB Output is correct
7 Correct 2515 ms 84616 KB Output is correct
8 Correct 2376 ms 79144 KB Output is correct
9 Correct 1460 ms 118088 KB Output is correct
10 Correct 1499 ms 97260 KB Output is correct
11 Correct 1894 ms 81448 KB Output is correct
12 Correct 2527 ms 79652 KB Output is correct
13 Correct 1498 ms 84932 KB Output is correct
14 Correct 1484 ms 85372 KB Output is correct
15 Correct 1791 ms 85464 KB Output is correct
16 Correct 1894 ms 89220 KB Output is correct
17 Correct 1939 ms 88208 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 40784 KB Output is correct
2 Correct 8 ms 40784 KB Output is correct
3 Correct 7 ms 40784 KB Output is correct
4 Correct 7 ms 40784 KB Output is correct
5 Correct 8 ms 40784 KB Output is correct
6 Correct 8 ms 40784 KB Output is correct
7 Correct 7 ms 40784 KB Output is correct
8 Correct 8 ms 40784 KB Output is correct
9 Correct 11 ms 40784 KB Output is correct
10 Correct 8 ms 40784 KB Output is correct
11 Correct 7 ms 40784 KB Output is correct
12 Correct 8 ms 40784 KB Output is correct
13 Correct 7 ms 40652 KB Output is correct
14 Correct 7 ms 40784 KB Output is correct
15 Correct 8 ms 40784 KB Output is correct
16 Correct 8 ms 40784 KB Output is correct
17 Correct 8 ms 40884 KB Output is correct
18 Correct 7 ms 40784 KB Output is correct
19 Correct 7 ms 40784 KB Output is correct
20 Correct 9 ms 30544 KB Output is correct
21 Correct 8 ms 40800 KB Output is correct
22 Correct 11 ms 40784 KB Output is correct
23 Correct 8 ms 40888 KB Output is correct
24 Correct 8 ms 40784 KB Output is correct
25 Correct 9 ms 40784 KB Output is correct
26 Correct 9 ms 40784 KB Output is correct
27 Correct 9 ms 40784 KB Output is correct
28 Correct 9 ms 40784 KB Output is correct
29 Correct 10 ms 40952 KB Output is correct
30 Correct 19 ms 30544 KB Output is correct
31 Correct 423 ms 45108 KB Output is correct
32 Correct 176 ms 48832 KB Output is correct
33 Correct 412 ms 48960 KB Output is correct
34 Correct 345 ms 49724 KB Output is correct
35 Correct 418 ms 52540 KB Output is correct
36 Correct 452 ms 50668 KB Output is correct
37 Correct 419 ms 48188 KB Output is correct
38 Correct 380 ms 48704 KB Output is correct
39 Correct 309 ms 48748 KB Output is correct
40 Correct 308 ms 46652 KB Output is correct
41 Correct 222 ms 43992 KB Output is correct
42 Correct 200 ms 49736 KB Output is correct
43 Correct 150 ms 50920 KB Output is correct
44 Correct 223 ms 48820 KB Output is correct
45 Correct 239 ms 46132 KB Output is correct
46 Correct 289 ms 44152 KB Output is correct
47 Correct 194 ms 46392 KB Output is correct
48 Correct 216 ms 41544 KB Output is correct
49 Correct 236 ms 48696 KB Output is correct
50 Correct 243 ms 47488 KB Output is correct
51 Correct 257 ms 47420 KB Output is correct
52 Correct 232 ms 58936 KB Output is correct
53 Correct 216 ms 57920 KB Output is correct
54 Correct 200 ms 52804 KB Output is correct
55 Correct 248 ms 51772 KB Output is correct
56 Correct 244 ms 53560 KB Output is correct
57 Correct 216 ms 49212 KB Output is correct
58 Correct 229 ms 53444 KB Output is correct
59 Correct 204 ms 54248 KB Output is correct
60 Correct 191 ms 48812 KB Output is correct
61 Correct 165 ms 60740 KB Output is correct
62 Correct 209 ms 58248 KB Output is correct
63 Correct 192 ms 54080 KB Output is correct
64 Correct 199 ms 52536 KB Output is correct
65 Correct 201 ms 51084 KB Output is correct
66 Correct 199 ms 48700 KB Output is correct
67 Correct 159 ms 48952 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 40784 KB Output is correct
2 Correct 8 ms 40784 KB Output is correct
3 Correct 7 ms 40784 KB Output is correct
4 Correct 7 ms 40784 KB Output is correct
5 Correct 8 ms 40784 KB Output is correct
6 Correct 8 ms 40784 KB Output is correct
7 Correct 7 ms 40784 KB Output is correct
8 Correct 8 ms 40784 KB Output is correct
9 Correct 11 ms 40784 KB Output is correct
10 Correct 8 ms 40784 KB Output is correct
11 Correct 7 ms 40784 KB Output is correct
12 Correct 8 ms 40784 KB Output is correct
13 Correct 7 ms 40652 KB Output is correct
14 Correct 7 ms 40784 KB Output is correct
15 Correct 8 ms 40784 KB Output is correct
16 Correct 8 ms 40784 KB Output is correct
17 Correct 8 ms 40884 KB Output is correct
18 Correct 7 ms 40784 KB Output is correct
19 Correct 7 ms 40784 KB Output is correct
20 Correct 9 ms 30544 KB Output is correct
21 Correct 8 ms 40800 KB Output is correct
22 Correct 11 ms 40784 KB Output is correct
23 Correct 8 ms 40888 KB Output is correct
24 Correct 8 ms 40784 KB Output is correct
25 Correct 9 ms 40784 KB Output is correct
26 Correct 9 ms 40784 KB Output is correct
27 Correct 9 ms 40784 KB Output is correct
28 Correct 9 ms 40784 KB Output is correct
29 Correct 10 ms 40952 KB Output is correct
30 Correct 19 ms 30544 KB Output is correct
31 Correct 423 ms 45108 KB Output is correct
32 Correct 176 ms 48832 KB Output is correct
33 Correct 412 ms 48960 KB Output is correct
34 Correct 345 ms 49724 KB Output is correct
35 Correct 418 ms 52540 KB Output is correct
36 Correct 452 ms 50668 KB Output is correct
37 Correct 419 ms 48188 KB Output is correct
38 Correct 380 ms 48704 KB Output is correct
39 Correct 309 ms 48748 KB Output is correct
40 Correct 308 ms 46652 KB Output is correct
41 Correct 222 ms 43992 KB Output is correct
42 Correct 200 ms 49736 KB Output is correct
43 Correct 150 ms 50920 KB Output is correct
44 Correct 223 ms 48820 KB Output is correct
45 Correct 239 ms 46132 KB Output is correct
46 Correct 289 ms 44152 KB Output is correct
47 Correct 194 ms 46392 KB Output is correct
48 Correct 216 ms 41544 KB Output is correct
49 Correct 236 ms 48696 KB Output is correct
50 Correct 243 ms 47488 KB Output is correct
51 Correct 257 ms 47420 KB Output is correct
52 Correct 1335 ms 81792 KB Output is correct
53 Correct 2131 ms 88640 KB Output is correct
54 Correct 1498 ms 114172 KB Output is correct
55 Correct 1513 ms 100336 KB Output is correct
56 Correct 2244 ms 85060 KB Output is correct
57 Correct 2234 ms 78904 KB Output is correct
58 Correct 1315 ms 115536 KB Output is correct
59 Correct 1383 ms 96764 KB Output is correct
60 Correct 1771 ms 85480 KB Output is correct
61 Correct 2323 ms 89380 KB Output is correct
62 Correct 1862 ms 79104 KB Output is correct
63 Correct 1863 ms 86232 KB Output is correct
64 Correct 1892 ms 89200 KB Output is correct
65 Correct 865 ms 78132 KB Output is correct
66 Correct 2625 ms 78164 KB Output is correct
67 Correct 1335 ms 106580 KB Output is correct
68 Correct 1274 ms 94248 KB Output is correct
69 Correct 1292 ms 87564 KB Output is correct
70 Correct 2515 ms 84616 KB Output is correct
71 Correct 2376 ms 79144 KB Output is correct
72 Correct 1460 ms 118088 KB Output is correct
73 Correct 1499 ms 97260 KB Output is correct
74 Correct 1894 ms 81448 KB Output is correct
75 Correct 2527 ms 79652 KB Output is correct
76 Correct 1498 ms 84932 KB Output is correct
77 Correct 1484 ms 85372 KB Output is correct
78 Correct 1791 ms 85464 KB Output is correct
79 Correct 1894 ms 89220 KB Output is correct
80 Correct 1939 ms 88208 KB Output is correct
81 Correct 232 ms 58936 KB Output is correct
82 Correct 216 ms 57920 KB Output is correct
83 Correct 200 ms 52804 KB Output is correct
84 Correct 248 ms 51772 KB Output is correct
85 Correct 244 ms 53560 KB Output is correct
86 Correct 216 ms 49212 KB Output is correct
87 Correct 229 ms 53444 KB Output is correct
88 Correct 204 ms 54248 KB Output is correct
89 Correct 191 ms 48812 KB Output is correct
90 Correct 165 ms 60740 KB Output is correct
91 Correct 209 ms 58248 KB Output is correct
92 Correct 192 ms 54080 KB Output is correct
93 Correct 199 ms 52536 KB Output is correct
94 Correct 201 ms 51084 KB Output is correct
95 Correct 199 ms 48700 KB Output is correct
96 Correct 159 ms 48952 KB Output is correct
97 Correct 1256 ms 118616 KB Output is correct
98 Correct 821 ms 73768 KB Output is correct
99 Correct 2498 ms 77756 KB Output is correct
100 Correct 1267 ms 105624 KB Output is correct
101 Correct 1182 ms 99564 KB Output is correct
102 Correct 2494 ms 79252 KB Output is correct
103 Correct 2067 ms 74316 KB Output is correct
104 Correct 2179 ms 73536 KB Output is correct
105 Correct 1862 ms 72624 KB Output is correct
106 Correct 1914 ms 65340 KB Output is correct
107 Correct 1359 ms 80204 KB Output is correct
108 Correct 1313 ms 87344 KB Output is correct
109 Correct 1255 ms 70436 KB Output is correct
110 Correct 1225 ms 91572 KB Output is correct
111 Correct 1260 ms 86596 KB Output is correct
112 Correct 1186 ms 77636 KB Output is correct
113 Correct 932 ms 109968 KB Output is correct
114 Correct 1307 ms 115032 KB Output is correct
115 Correct 1387 ms 90660 KB Output is correct
116 Correct 1352 ms 91932 KB Output is correct
117 Correct 1175 ms 71824 KB Output is correct
118 Correct 1165 ms 66664 KB Output is correct
119 Correct 990 ms 70340 KB Output is correct
120 Correct 1067 ms 65336 KB Output is correct
121 Correct 1281 ms 65340 KB Output is correct
122 Correct 1403 ms 72504 KB Output is correct
123 Correct 1432 ms 65336 KB Output is correct
124 Correct 1322 ms 65588 KB Output is correct
125 Correct 1595 ms 65832 KB Output is correct
126 Correct 1165 ms 65580 KB Output is correct