Submission #1104501

# Submission time Handle Problem Language Result Execution time Memory
1104501 2024-10-24T01:08:28 Z Boycl07 New Home (APIO18_new_home) C++17
47 / 100
446 ms 114568 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 = 3e5 + 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);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 5 ms 22520 KB Output is correct
2 Correct 5 ms 22352 KB Output is correct
3 Correct 4 ms 22608 KB Output is correct
4 Correct 4 ms 22488 KB Output is correct
5 Correct 6 ms 22608 KB Output is correct
6 Correct 6 ms 22608 KB Output is correct
7 Correct 6 ms 22608 KB Output is correct
8 Correct 6 ms 22608 KB Output is correct
9 Correct 6 ms 22712 KB Output is correct
10 Correct 7 ms 22608 KB Output is correct
11 Correct 7 ms 22712 KB Output is correct
12 Correct 7 ms 22776 KB Output is correct
13 Correct 6 ms 22608 KB Output is correct
14 Correct 5 ms 22848 KB Output is correct
15 Correct 5 ms 22608 KB Output is correct
16 Correct 6 ms 22608 KB Output is correct
17 Correct 6 ms 22776 KB Output is correct
18 Correct 6 ms 22456 KB Output is correct
19 Correct 6 ms 22780 KB Output is correct
20 Correct 7 ms 22608 KB Output is correct
21 Correct 5 ms 22776 KB Output is correct
22 Correct 6 ms 22608 KB Output is correct
23 Correct 5 ms 22608 KB Output is correct
24 Correct 7 ms 18512 KB Output is correct
25 Correct 6 ms 22608 KB Output is correct
26 Correct 6 ms 22608 KB Output is correct
27 Correct 6 ms 22608 KB Output is correct
28 Correct 6 ms 22608 KB Output is correct
29 Correct 6 ms 22608 KB Output is correct
30 Correct 7 ms 22608 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 22520 KB Output is correct
2 Correct 5 ms 22352 KB Output is correct
3 Correct 4 ms 22608 KB Output is correct
4 Correct 4 ms 22488 KB Output is correct
5 Correct 6 ms 22608 KB Output is correct
6 Correct 6 ms 22608 KB Output is correct
7 Correct 6 ms 22608 KB Output is correct
8 Correct 6 ms 22608 KB Output is correct
9 Correct 6 ms 22712 KB Output is correct
10 Correct 7 ms 22608 KB Output is correct
11 Correct 7 ms 22712 KB Output is correct
12 Correct 7 ms 22776 KB Output is correct
13 Correct 6 ms 22608 KB Output is correct
14 Correct 5 ms 22848 KB Output is correct
15 Correct 5 ms 22608 KB Output is correct
16 Correct 6 ms 22608 KB Output is correct
17 Correct 6 ms 22776 KB Output is correct
18 Correct 6 ms 22456 KB Output is correct
19 Correct 6 ms 22780 KB Output is correct
20 Correct 7 ms 22608 KB Output is correct
21 Correct 5 ms 22776 KB Output is correct
22 Correct 6 ms 22608 KB Output is correct
23 Correct 5 ms 22608 KB Output is correct
24 Correct 7 ms 18512 KB Output is correct
25 Correct 6 ms 22608 KB Output is correct
26 Correct 6 ms 22608 KB Output is correct
27 Correct 6 ms 22608 KB Output is correct
28 Correct 6 ms 22608 KB Output is correct
29 Correct 6 ms 22608 KB Output is correct
30 Correct 7 ms 22608 KB Output is correct
31 Correct 380 ms 32260 KB Output is correct
32 Correct 149 ms 29252 KB Output is correct
33 Correct 397 ms 30620 KB Output is correct
34 Correct 342 ms 30784 KB Output is correct
35 Correct 379 ms 32324 KB Output is correct
36 Correct 413 ms 31040 KB Output is correct
37 Correct 327 ms 29312 KB Output is correct
38 Correct 328 ms 31220 KB Output is correct
39 Correct 275 ms 31052 KB Output is correct
40 Correct 298 ms 29508 KB Output is correct
41 Correct 242 ms 31156 KB Output is correct
42 Correct 175 ms 30980 KB Output is correct
43 Correct 144 ms 32052 KB Output is correct
44 Correct 201 ms 31076 KB Output is correct
45 Correct 237 ms 31244 KB Output is correct
46 Correct 258 ms 31044 KB Output is correct
47 Correct 210 ms 28740 KB Output is correct
48 Correct 213 ms 29116 KB Output is correct
49 Correct 242 ms 30784 KB Output is correct
50 Correct 239 ms 31040 KB Output is correct
51 Correct 260 ms 28740 KB Output is correct
# Verdict Execution time Memory Grader output
1 Runtime error 425 ms 114568 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 446 ms 110948 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 5 ms 22520 KB Output is correct
2 Correct 5 ms 22352 KB Output is correct
3 Correct 4 ms 22608 KB Output is correct
4 Correct 4 ms 22488 KB Output is correct
5 Correct 6 ms 22608 KB Output is correct
6 Correct 6 ms 22608 KB Output is correct
7 Correct 6 ms 22608 KB Output is correct
8 Correct 6 ms 22608 KB Output is correct
9 Correct 6 ms 22712 KB Output is correct
10 Correct 7 ms 22608 KB Output is correct
11 Correct 7 ms 22712 KB Output is correct
12 Correct 7 ms 22776 KB Output is correct
13 Correct 6 ms 22608 KB Output is correct
14 Correct 5 ms 22848 KB Output is correct
15 Correct 5 ms 22608 KB Output is correct
16 Correct 6 ms 22608 KB Output is correct
17 Correct 6 ms 22776 KB Output is correct
18 Correct 6 ms 22456 KB Output is correct
19 Correct 6 ms 22780 KB Output is correct
20 Correct 7 ms 22608 KB Output is correct
21 Correct 5 ms 22776 KB Output is correct
22 Correct 6 ms 22608 KB Output is correct
23 Correct 5 ms 22608 KB Output is correct
24 Correct 7 ms 18512 KB Output is correct
25 Correct 6 ms 22608 KB Output is correct
26 Correct 6 ms 22608 KB Output is correct
27 Correct 6 ms 22608 KB Output is correct
28 Correct 6 ms 22608 KB Output is correct
29 Correct 6 ms 22608 KB Output is correct
30 Correct 7 ms 22608 KB Output is correct
31 Correct 380 ms 32260 KB Output is correct
32 Correct 149 ms 29252 KB Output is correct
33 Correct 397 ms 30620 KB Output is correct
34 Correct 342 ms 30784 KB Output is correct
35 Correct 379 ms 32324 KB Output is correct
36 Correct 413 ms 31040 KB Output is correct
37 Correct 327 ms 29312 KB Output is correct
38 Correct 328 ms 31220 KB Output is correct
39 Correct 275 ms 31052 KB Output is correct
40 Correct 298 ms 29508 KB Output is correct
41 Correct 242 ms 31156 KB Output is correct
42 Correct 175 ms 30980 KB Output is correct
43 Correct 144 ms 32052 KB Output is correct
44 Correct 201 ms 31076 KB Output is correct
45 Correct 237 ms 31244 KB Output is correct
46 Correct 258 ms 31044 KB Output is correct
47 Correct 210 ms 28740 KB Output is correct
48 Correct 213 ms 29116 KB Output is correct
49 Correct 242 ms 30784 KB Output is correct
50 Correct 239 ms 31040 KB Output is correct
51 Correct 260 ms 28740 KB Output is correct
52 Correct 231 ms 37692 KB Output is correct
53 Correct 226 ms 36676 KB Output is correct
54 Correct 221 ms 33848 KB Output is correct
55 Correct 241 ms 32832 KB Output is correct
56 Correct 235 ms 33868 KB Output is correct
57 Correct 228 ms 32076 KB Output is correct
58 Correct 223 ms 32884 KB Output is correct
59 Correct 214 ms 33860 KB Output is correct
60 Correct 214 ms 27720 KB Output is correct
61 Correct 167 ms 38460 KB Output is correct
62 Correct 225 ms 35896 KB Output is correct
63 Correct 268 ms 34472 KB Output is correct
64 Correct 214 ms 30184 KB Output is correct
65 Correct 191 ms 31776 KB Output is correct
66 Correct 209 ms 31048 KB Output is correct
67 Correct 178 ms 24392 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 22520 KB Output is correct
2 Correct 5 ms 22352 KB Output is correct
3 Correct 4 ms 22608 KB Output is correct
4 Correct 4 ms 22488 KB Output is correct
5 Correct 6 ms 22608 KB Output is correct
6 Correct 6 ms 22608 KB Output is correct
7 Correct 6 ms 22608 KB Output is correct
8 Correct 6 ms 22608 KB Output is correct
9 Correct 6 ms 22712 KB Output is correct
10 Correct 7 ms 22608 KB Output is correct
11 Correct 7 ms 22712 KB Output is correct
12 Correct 7 ms 22776 KB Output is correct
13 Correct 6 ms 22608 KB Output is correct
14 Correct 5 ms 22848 KB Output is correct
15 Correct 5 ms 22608 KB Output is correct
16 Correct 6 ms 22608 KB Output is correct
17 Correct 6 ms 22776 KB Output is correct
18 Correct 6 ms 22456 KB Output is correct
19 Correct 6 ms 22780 KB Output is correct
20 Correct 7 ms 22608 KB Output is correct
21 Correct 5 ms 22776 KB Output is correct
22 Correct 6 ms 22608 KB Output is correct
23 Correct 5 ms 22608 KB Output is correct
24 Correct 7 ms 18512 KB Output is correct
25 Correct 6 ms 22608 KB Output is correct
26 Correct 6 ms 22608 KB Output is correct
27 Correct 6 ms 22608 KB Output is correct
28 Correct 6 ms 22608 KB Output is correct
29 Correct 6 ms 22608 KB Output is correct
30 Correct 7 ms 22608 KB Output is correct
31 Correct 380 ms 32260 KB Output is correct
32 Correct 149 ms 29252 KB Output is correct
33 Correct 397 ms 30620 KB Output is correct
34 Correct 342 ms 30784 KB Output is correct
35 Correct 379 ms 32324 KB Output is correct
36 Correct 413 ms 31040 KB Output is correct
37 Correct 327 ms 29312 KB Output is correct
38 Correct 328 ms 31220 KB Output is correct
39 Correct 275 ms 31052 KB Output is correct
40 Correct 298 ms 29508 KB Output is correct
41 Correct 242 ms 31156 KB Output is correct
42 Correct 175 ms 30980 KB Output is correct
43 Correct 144 ms 32052 KB Output is correct
44 Correct 201 ms 31076 KB Output is correct
45 Correct 237 ms 31244 KB Output is correct
46 Correct 258 ms 31044 KB Output is correct
47 Correct 210 ms 28740 KB Output is correct
48 Correct 213 ms 29116 KB Output is correct
49 Correct 242 ms 30784 KB Output is correct
50 Correct 239 ms 31040 KB Output is correct
51 Correct 260 ms 28740 KB Output is correct
52 Runtime error 425 ms 114568 KB Execution killed with signal 11
53 Halted 0 ms 0 KB -