답안 #217738

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
217738 2020-03-30T14:55:29 Z Vimmer 새 집 (APIO18_new_home) C++14
12 / 100
2907 ms 24356 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];

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;}

            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 (pos[tp] != 0) sel.erase({qr[tp][pos[tp] - 1], tp});

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

                sel.insert({qr[tp][pos[tp]], 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 9 ms 7424 KB Output is correct
2 Correct 8 ms 7424 KB Output is correct
3 Correct 8 ms 7424 KB Output is correct
4 Correct 8 ms 7424 KB Output is correct
5 Correct 11 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 7552 KB Output is correct
9 Correct 10 ms 7552 KB Output is correct
10 Correct 10 ms 7552 KB Output is correct
11 Correct 10 ms 7424 KB Output is correct
12 Correct 10 ms 7424 KB Output is correct
13 Correct 9 ms 7424 KB Output is correct
14 Correct 10 ms 7424 KB Output is correct
15 Correct 11 ms 7424 KB Output is correct
16 Correct 11 ms 7424 KB Output is correct
17 Correct 10 ms 7424 KB Output is correct
18 Correct 10 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 10 ms 7424 KB Output is correct
22 Correct 10 ms 7424 KB Output is correct
23 Correct 10 ms 7424 KB Output is correct
24 Correct 10 ms 7424 KB Output is correct
25 Correct 11 ms 7552 KB Output is correct
26 Correct 10 ms 7424 KB Output is correct
27 Correct 11 ms 7424 KB Output is correct
28 Correct 10 ms 7424 KB Output is correct
29 Correct 10 ms 7424 KB Output is correct
30 Correct 9 ms 7424 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 7424 KB Output is correct
2 Correct 8 ms 7424 KB Output is correct
3 Correct 8 ms 7424 KB Output is correct
4 Correct 8 ms 7424 KB Output is correct
5 Correct 11 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 7552 KB Output is correct
9 Correct 10 ms 7552 KB Output is correct
10 Correct 10 ms 7552 KB Output is correct
11 Correct 10 ms 7424 KB Output is correct
12 Correct 10 ms 7424 KB Output is correct
13 Correct 9 ms 7424 KB Output is correct
14 Correct 10 ms 7424 KB Output is correct
15 Correct 11 ms 7424 KB Output is correct
16 Correct 11 ms 7424 KB Output is correct
17 Correct 10 ms 7424 KB Output is correct
18 Correct 10 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 10 ms 7424 KB Output is correct
22 Correct 10 ms 7424 KB Output is correct
23 Correct 10 ms 7424 KB Output is correct
24 Correct 10 ms 7424 KB Output is correct
25 Correct 11 ms 7552 KB Output is correct
26 Correct 10 ms 7424 KB Output is correct
27 Correct 11 ms 7424 KB Output is correct
28 Correct 10 ms 7424 KB Output is correct
29 Correct 10 ms 7424 KB Output is correct
30 Correct 9 ms 7424 KB Output is correct
31 Correct 2907 ms 17244 KB Output is correct
32 Correct 185 ms 10344 KB Output is correct
33 Correct 382 ms 15464 KB Output is correct
34 Correct 2139 ms 15460 KB Output is correct
35 Correct 1453 ms 17244 KB Output is correct
36 Correct 463 ms 17128 KB Output is correct
37 Correct 376 ms 14572 KB Output is correct
38 Correct 292 ms 14544 KB Output is correct
39 Correct 255 ms 14428 KB Output is correct
40 Correct 267 ms 14316 KB Output is correct
41 Correct 517 ms 14696 KB Output is correct
42 Correct 448 ms 14312 KB Output is correct
43 Correct 276 ms 10856 KB Output is correct
44 Correct 463 ms 14528 KB Output is correct
45 Correct 299 ms 14572 KB Output is correct
46 Correct 253 ms 14488 KB Output is correct
47 Correct 241 ms 14000 KB Output is correct
48 Correct 225 ms 13992 KB Output is correct
49 Correct 253 ms 14184 KB Output is correct
50 Correct 395 ms 14288 KB Output is correct
51 Correct 240 ms 14188 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1419 ms 24356 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1146 ms 18284 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 7424 KB Output is correct
2 Correct 8 ms 7424 KB Output is correct
3 Correct 8 ms 7424 KB Output is correct
4 Correct 8 ms 7424 KB Output is correct
5 Correct 11 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 7552 KB Output is correct
9 Correct 10 ms 7552 KB Output is correct
10 Correct 10 ms 7552 KB Output is correct
11 Correct 10 ms 7424 KB Output is correct
12 Correct 10 ms 7424 KB Output is correct
13 Correct 9 ms 7424 KB Output is correct
14 Correct 10 ms 7424 KB Output is correct
15 Correct 11 ms 7424 KB Output is correct
16 Correct 11 ms 7424 KB Output is correct
17 Correct 10 ms 7424 KB Output is correct
18 Correct 10 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 10 ms 7424 KB Output is correct
22 Correct 10 ms 7424 KB Output is correct
23 Correct 10 ms 7424 KB Output is correct
24 Correct 10 ms 7424 KB Output is correct
25 Correct 11 ms 7552 KB Output is correct
26 Correct 10 ms 7424 KB Output is correct
27 Correct 11 ms 7424 KB Output is correct
28 Correct 10 ms 7424 KB Output is correct
29 Correct 10 ms 7424 KB Output is correct
30 Correct 9 ms 7424 KB Output is correct
31 Correct 2907 ms 17244 KB Output is correct
32 Correct 185 ms 10344 KB Output is correct
33 Correct 382 ms 15464 KB Output is correct
34 Correct 2139 ms 15460 KB Output is correct
35 Correct 1453 ms 17244 KB Output is correct
36 Correct 463 ms 17128 KB Output is correct
37 Correct 376 ms 14572 KB Output is correct
38 Correct 292 ms 14544 KB Output is correct
39 Correct 255 ms 14428 KB Output is correct
40 Correct 267 ms 14316 KB Output is correct
41 Correct 517 ms 14696 KB Output is correct
42 Correct 448 ms 14312 KB Output is correct
43 Correct 276 ms 10856 KB Output is correct
44 Correct 463 ms 14528 KB Output is correct
45 Correct 299 ms 14572 KB Output is correct
46 Correct 253 ms 14488 KB Output is correct
47 Correct 241 ms 14000 KB Output is correct
48 Correct 225 ms 13992 KB Output is correct
49 Correct 253 ms 14184 KB Output is correct
50 Correct 395 ms 14288 KB Output is correct
51 Correct 240 ms 14188 KB Output is correct
52 Runtime error 79 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 9 ms 7424 KB Output is correct
2 Correct 8 ms 7424 KB Output is correct
3 Correct 8 ms 7424 KB Output is correct
4 Correct 8 ms 7424 KB Output is correct
5 Correct 11 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 7552 KB Output is correct
9 Correct 10 ms 7552 KB Output is correct
10 Correct 10 ms 7552 KB Output is correct
11 Correct 10 ms 7424 KB Output is correct
12 Correct 10 ms 7424 KB Output is correct
13 Correct 9 ms 7424 KB Output is correct
14 Correct 10 ms 7424 KB Output is correct
15 Correct 11 ms 7424 KB Output is correct
16 Correct 11 ms 7424 KB Output is correct
17 Correct 10 ms 7424 KB Output is correct
18 Correct 10 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 10 ms 7424 KB Output is correct
22 Correct 10 ms 7424 KB Output is correct
23 Correct 10 ms 7424 KB Output is correct
24 Correct 10 ms 7424 KB Output is correct
25 Correct 11 ms 7552 KB Output is correct
26 Correct 10 ms 7424 KB Output is correct
27 Correct 11 ms 7424 KB Output is correct
28 Correct 10 ms 7424 KB Output is correct
29 Correct 10 ms 7424 KB Output is correct
30 Correct 9 ms 7424 KB Output is correct
31 Correct 2907 ms 17244 KB Output is correct
32 Correct 185 ms 10344 KB Output is correct
33 Correct 382 ms 15464 KB Output is correct
34 Correct 2139 ms 15460 KB Output is correct
35 Correct 1453 ms 17244 KB Output is correct
36 Correct 463 ms 17128 KB Output is correct
37 Correct 376 ms 14572 KB Output is correct
38 Correct 292 ms 14544 KB Output is correct
39 Correct 255 ms 14428 KB Output is correct
40 Correct 267 ms 14316 KB Output is correct
41 Correct 517 ms 14696 KB Output is correct
42 Correct 448 ms 14312 KB Output is correct
43 Correct 276 ms 10856 KB Output is correct
44 Correct 463 ms 14528 KB Output is correct
45 Correct 299 ms 14572 KB Output is correct
46 Correct 253 ms 14488 KB Output is correct
47 Correct 241 ms 14000 KB Output is correct
48 Correct 225 ms 13992 KB Output is correct
49 Correct 253 ms 14184 KB Output is correct
50 Correct 395 ms 14288 KB Output is correct
51 Correct 240 ms 14188 KB Output is correct
52 Incorrect 1419 ms 24356 KB Output isn't correct
53 Halted 0 ms 0 KB -