답안 #217735

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
217735 2020-03-30T14:48:56 Z Vimmer 새 집 (APIO18_new_home) C++14
12 / 100
2769 ms 25136 KB
#include <bits/stdc++.h>

#define F first
#define S second
#define sz(x) int(x.size())
#define pb push_back
#define N 300005
#define M ll(998244353)

using namespace std;

typedef long double ld;
typedef long long ll;
typedef short int si;


vector <pair <pair <pair <int, int>, int>, int> > sost;

set <int> se[410];

map <pair <int, int>, int > mp;

vector <pair <int, int> > vr;

vector <int> qr[N];

pair <int, int> dist[N];

int pos[N];

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

    int n, k, q;

    cin >> n >> k >> q;

    if (n <= 60000)
    {
        for (int i = 0; i < n; i++)
        {
            int x, t, l, r;

            cin >> x >> t >> l >> r;

            sost.pb({{{l, x}, t}, i});

            sost.pb({{{r + 1, x}, -t}, i});
        }

        vector <pair <pair <int, int>, int>  > gr; gr.resize(q);

        for (int i = 0; i < q; i++) {cin >> gr[i].F.S >> gr[i].F.F; gr[i].S = i;}

        sort(sost.begin(), sost.end());

        sort(gr.begin(), gr.end());

        int ans[q];

        int j = 0;

        for (auto it : gr)
        {
            int nm = it.S, x = it.F.S, tr = it.F.F;

            while (j < n + n && sost[j].F.F.F <= tr)
            {
                int tp = abs(sost[j].F.S);

                if (sost[j].F.S > 0) {mp[{tp, sost[j].F.F.S}]++; if (mp[{tp, sost[j].F.F.S}] == 1) se[tp].insert(sost[j].F.F.S);}
                   else  {mp[{tp, sost[j].F.F.S}]--; if (mp[{tp, sost[j].F.F.S}] == 0) se[tp].erase(sost[j].F.F.S);}

                j++;
            }

            bool f = 1;

            int mx = 0;

            for (int i = 1; i <= k; i++)
            {
                if (sz(se[i]) == 0) {f = 0; break;}

                auto it = se[i].lower_bound(x);

                int mn = 1e9;

                if (it != se[i].end()) mn = min(mn, abs(*it - x));

                if (it != se[i].begin()) {it--; mn = min(mn, abs(*it - x)); }

                mx = max(mx, mn);
            }

            if (!f) ans[nm] = -1; else ans[nm] = mx;
        }

        for (int i = 0; i < q; i++) cout << ans[i] << endl;
    }
    else
    {
        for (int i = 0; i < n; i++)
        {
            int x, t, a, b;

            cin >> x >> t >> a >> b;

            vr.pb({x, t});

            qr[t].pb(x);
        }

        set <pair <int, int> > sel, ser; sel.clear(); ser.clear();

        for (int i = 1; i <= k; i++) sort(qr[i].begin(), qr[i].end());

        sort(vr.begin(), vr.end());

        bool f = 1;

        for (int i = 1; i <= k; i++)
        {
            if (sz(qr[i]) == 0) {f = 0; break;}

            dist[i] = {-1, qr[i][0]};

            ser.insert({qr[i][0], i});
        }

        if (!f) {for (int i = 0; i < q; i++) cout << -1 << endl; exit(0);}

        vector <pair <int, int> > v; v.resize(q);

        for (int i = 0; i < q; i++) {cin >> v[i].F >> v[i].S; v[i].S = i;}

        sort(v.begin(), v.end());

        int ans[q], j = 0;

        for (auto it : v)
        {
            int nm = it.S, x = it.F;

            while (j < sz(vr) && vr[j].F <= x)
            {
                int tp = vr[j].S;

                if (dist[tp].F != -1) sel.erase({qr[tp][pos[tp] - 1], tp});

                ser.erase({qr[tp][pos[tp]], tp});

                sel.insert({qr[tp][pos[tp]], tp});

                dist[tp].F = qr[tp][pos[tp]];

                pos[tp]++;

                if (pos[tp] != sz(qr[tp])) ser.insert({qr[tp][pos[tp]], tp});

                j++;
            }

            int mx = 0;

            if (sz(sel) != 0) mx = max(mx, x - (*sel.begin()).F);

            if (sz(ser) != 0) mx = max(mx, (*ser.rbegin()).F - x);

            ans[nm] = mx;
        }

        for (int i = 0; i < q; i++) cout << ans[i] << endl;
    }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 7424 KB Output is correct
2 Correct 10 ms 7424 KB Output is correct
3 Correct 9 ms 7424 KB Output is correct
4 Correct 9 ms 7424 KB Output is correct
5 Correct 10 ms 7424 KB Output is correct
6 Correct 10 ms 7424 KB Output is correct
7 Correct 10 ms 7424 KB Output is correct
8 Correct 10 ms 7424 KB Output is correct
9 Correct 10 ms 7552 KB Output is correct
10 Correct 10 ms 7424 KB Output is correct
11 Correct 10 ms 7424 KB Output is correct
12 Correct 10 ms 7424 KB Output is correct
13 Correct 10 ms 7424 KB Output is correct
14 Correct 10 ms 7424 KB Output is correct
15 Correct 10 ms 7552 KB Output is correct
16 Correct 12 ms 7424 KB Output is correct
17 Correct 10 ms 7424 KB Output is correct
18 Correct 11 ms 7424 KB Output is correct
19 Correct 10 ms 7424 KB Output is correct
20 Correct 10 ms 7424 KB Output is correct
21 Correct 11 ms 7424 KB Output is correct
22 Correct 11 ms 7424 KB Output is correct
23 Correct 13 ms 7424 KB Output is correct
24 Correct 10 ms 7424 KB Output is correct
25 Correct 10 ms 7424 KB Output is correct
26 Correct 10 ms 7424 KB Output is correct
27 Correct 10 ms 7424 KB Output is correct
28 Correct 13 ms 7424 KB Output is correct
29 Correct 10 ms 7424 KB Output is correct
30 Correct 12 ms 7424 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 7424 KB Output is correct
2 Correct 10 ms 7424 KB Output is correct
3 Correct 9 ms 7424 KB Output is correct
4 Correct 9 ms 7424 KB Output is correct
5 Correct 10 ms 7424 KB Output is correct
6 Correct 10 ms 7424 KB Output is correct
7 Correct 10 ms 7424 KB Output is correct
8 Correct 10 ms 7424 KB Output is correct
9 Correct 10 ms 7552 KB Output is correct
10 Correct 10 ms 7424 KB Output is correct
11 Correct 10 ms 7424 KB Output is correct
12 Correct 10 ms 7424 KB Output is correct
13 Correct 10 ms 7424 KB Output is correct
14 Correct 10 ms 7424 KB Output is correct
15 Correct 10 ms 7552 KB Output is correct
16 Correct 12 ms 7424 KB Output is correct
17 Correct 10 ms 7424 KB Output is correct
18 Correct 11 ms 7424 KB Output is correct
19 Correct 10 ms 7424 KB Output is correct
20 Correct 10 ms 7424 KB Output is correct
21 Correct 11 ms 7424 KB Output is correct
22 Correct 11 ms 7424 KB Output is correct
23 Correct 13 ms 7424 KB Output is correct
24 Correct 10 ms 7424 KB Output is correct
25 Correct 10 ms 7424 KB Output is correct
26 Correct 10 ms 7424 KB Output is correct
27 Correct 10 ms 7424 KB Output is correct
28 Correct 13 ms 7424 KB Output is correct
29 Correct 10 ms 7424 KB Output is correct
30 Correct 12 ms 7424 KB Output is correct
31 Correct 2769 ms 17280 KB Output is correct
32 Correct 176 ms 10312 KB Output is correct
33 Correct 366 ms 15468 KB Output is correct
34 Correct 2001 ms 15824 KB Output is correct
35 Correct 1355 ms 17256 KB Output is correct
36 Correct 429 ms 17260 KB Output is correct
37 Correct 363 ms 14572 KB Output is correct
38 Correct 291 ms 14696 KB Output is correct
39 Correct 256 ms 14444 KB Output is correct
40 Correct 256 ms 14312 KB Output is correct
41 Correct 479 ms 14580 KB Output is correct
42 Correct 410 ms 14440 KB Output is correct
43 Correct 265 ms 10860 KB Output is correct
44 Correct 424 ms 14568 KB Output is correct
45 Correct 289 ms 14568 KB Output is correct
46 Correct 241 ms 14572 KB Output is correct
47 Correct 228 ms 14188 KB Output is correct
48 Correct 210 ms 14056 KB Output is correct
49 Correct 241 ms 14184 KB Output is correct
50 Correct 372 ms 14312 KB Output is correct
51 Correct 239 ms 14184 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1302 ms 25136 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1109 ms 18332 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 7424 KB Output is correct
2 Correct 10 ms 7424 KB Output is correct
3 Correct 9 ms 7424 KB Output is correct
4 Correct 9 ms 7424 KB Output is correct
5 Correct 10 ms 7424 KB Output is correct
6 Correct 10 ms 7424 KB Output is correct
7 Correct 10 ms 7424 KB Output is correct
8 Correct 10 ms 7424 KB Output is correct
9 Correct 10 ms 7552 KB Output is correct
10 Correct 10 ms 7424 KB Output is correct
11 Correct 10 ms 7424 KB Output is correct
12 Correct 10 ms 7424 KB Output is correct
13 Correct 10 ms 7424 KB Output is correct
14 Correct 10 ms 7424 KB Output is correct
15 Correct 10 ms 7552 KB Output is correct
16 Correct 12 ms 7424 KB Output is correct
17 Correct 10 ms 7424 KB Output is correct
18 Correct 11 ms 7424 KB Output is correct
19 Correct 10 ms 7424 KB Output is correct
20 Correct 10 ms 7424 KB Output is correct
21 Correct 11 ms 7424 KB Output is correct
22 Correct 11 ms 7424 KB Output is correct
23 Correct 13 ms 7424 KB Output is correct
24 Correct 10 ms 7424 KB Output is correct
25 Correct 10 ms 7424 KB Output is correct
26 Correct 10 ms 7424 KB Output is correct
27 Correct 10 ms 7424 KB Output is correct
28 Correct 13 ms 7424 KB Output is correct
29 Correct 10 ms 7424 KB Output is correct
30 Correct 12 ms 7424 KB Output is correct
31 Correct 2769 ms 17280 KB Output is correct
32 Correct 176 ms 10312 KB Output is correct
33 Correct 366 ms 15468 KB Output is correct
34 Correct 2001 ms 15824 KB Output is correct
35 Correct 1355 ms 17256 KB Output is correct
36 Correct 429 ms 17260 KB Output is correct
37 Correct 363 ms 14572 KB Output is correct
38 Correct 291 ms 14696 KB Output is correct
39 Correct 256 ms 14444 KB Output is correct
40 Correct 256 ms 14312 KB Output is correct
41 Correct 479 ms 14580 KB Output is correct
42 Correct 410 ms 14440 KB Output is correct
43 Correct 265 ms 10860 KB Output is correct
44 Correct 424 ms 14568 KB Output is correct
45 Correct 289 ms 14568 KB Output is correct
46 Correct 241 ms 14572 KB Output is correct
47 Correct 228 ms 14188 KB Output is correct
48 Correct 210 ms 14056 KB Output is correct
49 Correct 241 ms 14184 KB Output is correct
50 Correct 372 ms 14312 KB Output is correct
51 Correct 239 ms 14184 KB Output is correct
52 Runtime error 81 ms 20072 KB Execution killed with signal 11 (could be triggered by violating memory limits)
53 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 7424 KB Output is correct
2 Correct 10 ms 7424 KB Output is correct
3 Correct 9 ms 7424 KB Output is correct
4 Correct 9 ms 7424 KB Output is correct
5 Correct 10 ms 7424 KB Output is correct
6 Correct 10 ms 7424 KB Output is correct
7 Correct 10 ms 7424 KB Output is correct
8 Correct 10 ms 7424 KB Output is correct
9 Correct 10 ms 7552 KB Output is correct
10 Correct 10 ms 7424 KB Output is correct
11 Correct 10 ms 7424 KB Output is correct
12 Correct 10 ms 7424 KB Output is correct
13 Correct 10 ms 7424 KB Output is correct
14 Correct 10 ms 7424 KB Output is correct
15 Correct 10 ms 7552 KB Output is correct
16 Correct 12 ms 7424 KB Output is correct
17 Correct 10 ms 7424 KB Output is correct
18 Correct 11 ms 7424 KB Output is correct
19 Correct 10 ms 7424 KB Output is correct
20 Correct 10 ms 7424 KB Output is correct
21 Correct 11 ms 7424 KB Output is correct
22 Correct 11 ms 7424 KB Output is correct
23 Correct 13 ms 7424 KB Output is correct
24 Correct 10 ms 7424 KB Output is correct
25 Correct 10 ms 7424 KB Output is correct
26 Correct 10 ms 7424 KB Output is correct
27 Correct 10 ms 7424 KB Output is correct
28 Correct 13 ms 7424 KB Output is correct
29 Correct 10 ms 7424 KB Output is correct
30 Correct 12 ms 7424 KB Output is correct
31 Correct 2769 ms 17280 KB Output is correct
32 Correct 176 ms 10312 KB Output is correct
33 Correct 366 ms 15468 KB Output is correct
34 Correct 2001 ms 15824 KB Output is correct
35 Correct 1355 ms 17256 KB Output is correct
36 Correct 429 ms 17260 KB Output is correct
37 Correct 363 ms 14572 KB Output is correct
38 Correct 291 ms 14696 KB Output is correct
39 Correct 256 ms 14444 KB Output is correct
40 Correct 256 ms 14312 KB Output is correct
41 Correct 479 ms 14580 KB Output is correct
42 Correct 410 ms 14440 KB Output is correct
43 Correct 265 ms 10860 KB Output is correct
44 Correct 424 ms 14568 KB Output is correct
45 Correct 289 ms 14568 KB Output is correct
46 Correct 241 ms 14572 KB Output is correct
47 Correct 228 ms 14188 KB Output is correct
48 Correct 210 ms 14056 KB Output is correct
49 Correct 241 ms 14184 KB Output is correct
50 Correct 372 ms 14312 KB Output is correct
51 Correct 239 ms 14184 KB Output is correct
52 Incorrect 1302 ms 25136 KB Output isn't correct
53 Halted 0 ms 0 KB -