Submission #106801

# Submission time Handle Problem Language Result Execution time Memory
106801 2019-04-20T14:29:47 Z tictaccat New Home (APIO18_new_home) C++14
12 / 100
5000 ms 45112 KB
#include <bits/stdc++.h>

using namespace std;

const int MAX = 3e5 + 10;
const int INF = 1e9;

int n,k,q;

vector<set<pair<int,int>>> types(MAX);
vector<tuple<int,int,int,int,int>> events;
vector<tuple<int,int,int>> queries;
vector<int> answers(MAX);

int main() {

    cin.tie(0);
    ios::sync_with_stdio(false);

    cin >> n >> k >> q;

    for (int i = 0; i < n; i++) {
        int x,t,a,b; cin >> x >> t >> a >> b;
        events.emplace_back(a,i,x,t,1);
        events.emplace_back(b+1,i,x,t,-1);
    }   

    for (int query = 0; query < q; query++) {
        int l,y; cin >> l >> y; 
        queries.push_back(make_tuple(y,l,query));
    }

    sort(events.begin(),events.end());
    sort(queries.begin(),queries.end());
    int p = 0;

    for (int z = 0; z < q; z++) {
       // cout << "z: " << z << "\n";
        int y,l,query; tie(y,l,query) = queries[z];
        while (p < events.size() && get<0>(events[p]) <= y) {
            int time,i,x,type,change; tie(time,i,x,type,change) = events[p];
            if (change == 1) {
                types[type].insert(make_pair(x,i));
                //cout << "adding: " << type << " " << x << " " << i << "\n";
            }
            if (change == -1) {
                //cout << "removing: " << type << " " << x << " " << i << "\n";
                assert(types[type].count(make_pair(x,i)) == 1);
                types[type].erase(make_pair(x,i));
            }
            p++;
        }
        int far = 0;
        for (int type = 1; type <= k; type++) {
            if (types[type].size() == 0) {
               // cout << type << "\n";
                far = -1;
                break;
            }
            auto itRight = types[type].lower_bound(make_pair(l,-1));
            int dist = INF;
            if (itRight != types[type].end()) {
                dist = min(dist,(*itRight).first - l);
                assert((*itRight).first - l >= 0);
            }
            if (itRight != types[type].begin()) {
                auto itLeft = prev(itRight);
                dist = min(dist,l-(*itLeft).first);
                assert(l-(*itLeft).first >= 0);
            }
            far = max(far,dist);
        }
        answers[query] = far;
    }

    for (int query = 0; query < q; query++) cout << answers[query] << "\n";

    return 0;
}

Compilation message

new_home.cpp: In function 'int main()':
new_home.cpp:40:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         while (p < events.size() && get<0>(events[p]) <= y) {
                ~~^~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 17 ms 15616 KB Output is correct
2 Correct 17 ms 15616 KB Output is correct
3 Correct 18 ms 15588 KB Output is correct
4 Correct 18 ms 15616 KB Output is correct
5 Correct 18 ms 15616 KB Output is correct
6 Correct 19 ms 15744 KB Output is correct
7 Correct 23 ms 15616 KB Output is correct
8 Correct 21 ms 15616 KB Output is correct
9 Correct 18 ms 15616 KB Output is correct
10 Correct 18 ms 15616 KB Output is correct
11 Correct 18 ms 15744 KB Output is correct
12 Correct 18 ms 15616 KB Output is correct
13 Correct 18 ms 15616 KB Output is correct
14 Correct 17 ms 15616 KB Output is correct
15 Correct 17 ms 15616 KB Output is correct
16 Correct 19 ms 15616 KB Output is correct
17 Correct 19 ms 15616 KB Output is correct
18 Correct 20 ms 15744 KB Output is correct
19 Correct 19 ms 15736 KB Output is correct
20 Correct 19 ms 15744 KB Output is correct
21 Correct 20 ms 15736 KB Output is correct
22 Correct 18 ms 15744 KB Output is correct
23 Correct 20 ms 15872 KB Output is correct
24 Correct 18 ms 15744 KB Output is correct
25 Correct 19 ms 15616 KB Output is correct
26 Correct 19 ms 15616 KB Output is correct
27 Correct 20 ms 15616 KB Output is correct
28 Correct 19 ms 15616 KB Output is correct
29 Correct 20 ms 15616 KB Output is correct
30 Correct 21 ms 15616 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 17 ms 15616 KB Output is correct
2 Correct 17 ms 15616 KB Output is correct
3 Correct 18 ms 15588 KB Output is correct
4 Correct 18 ms 15616 KB Output is correct
5 Correct 18 ms 15616 KB Output is correct
6 Correct 19 ms 15744 KB Output is correct
7 Correct 23 ms 15616 KB Output is correct
8 Correct 21 ms 15616 KB Output is correct
9 Correct 18 ms 15616 KB Output is correct
10 Correct 18 ms 15616 KB Output is correct
11 Correct 18 ms 15744 KB Output is correct
12 Correct 18 ms 15616 KB Output is correct
13 Correct 18 ms 15616 KB Output is correct
14 Correct 17 ms 15616 KB Output is correct
15 Correct 17 ms 15616 KB Output is correct
16 Correct 19 ms 15616 KB Output is correct
17 Correct 19 ms 15616 KB Output is correct
18 Correct 20 ms 15744 KB Output is correct
19 Correct 19 ms 15736 KB Output is correct
20 Correct 19 ms 15744 KB Output is correct
21 Correct 20 ms 15736 KB Output is correct
22 Correct 18 ms 15744 KB Output is correct
23 Correct 20 ms 15872 KB Output is correct
24 Correct 18 ms 15744 KB Output is correct
25 Correct 19 ms 15616 KB Output is correct
26 Correct 19 ms 15616 KB Output is correct
27 Correct 20 ms 15616 KB Output is correct
28 Correct 19 ms 15616 KB Output is correct
29 Correct 20 ms 15616 KB Output is correct
30 Correct 21 ms 15616 KB Output is correct
31 Correct 2894 ms 24988 KB Output is correct
32 Correct 134 ms 20992 KB Output is correct
33 Correct 263 ms 22996 KB Output is correct
34 Correct 2223 ms 23272 KB Output is correct
35 Correct 1619 ms 25032 KB Output is correct
36 Correct 384 ms 24812 KB Output is correct
37 Correct 179 ms 22764 KB Output is correct
38 Correct 120 ms 22692 KB Output is correct
39 Correct 105 ms 22628 KB Output is correct
40 Correct 101 ms 22608 KB Output is correct
41 Correct 342 ms 22860 KB Output is correct
42 Correct 233 ms 22772 KB Output is correct
43 Correct 441 ms 24400 KB Output is correct
44 Correct 277 ms 23144 KB Output is correct
45 Correct 152 ms 22888 KB Output is correct
46 Correct 104 ms 22888 KB Output is correct
47 Correct 96 ms 22416 KB Output is correct
48 Correct 99 ms 22376 KB Output is correct
49 Correct 116 ms 22508 KB Output is correct
50 Correct 230 ms 22772 KB Output is correct
51 Correct 105 ms 22632 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 5075 ms 45112 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 5053 ms 45112 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 17 ms 15616 KB Output is correct
2 Correct 17 ms 15616 KB Output is correct
3 Correct 18 ms 15588 KB Output is correct
4 Correct 18 ms 15616 KB Output is correct
5 Correct 18 ms 15616 KB Output is correct
6 Correct 19 ms 15744 KB Output is correct
7 Correct 23 ms 15616 KB Output is correct
8 Correct 21 ms 15616 KB Output is correct
9 Correct 18 ms 15616 KB Output is correct
10 Correct 18 ms 15616 KB Output is correct
11 Correct 18 ms 15744 KB Output is correct
12 Correct 18 ms 15616 KB Output is correct
13 Correct 18 ms 15616 KB Output is correct
14 Correct 17 ms 15616 KB Output is correct
15 Correct 17 ms 15616 KB Output is correct
16 Correct 19 ms 15616 KB Output is correct
17 Correct 19 ms 15616 KB Output is correct
18 Correct 20 ms 15744 KB Output is correct
19 Correct 19 ms 15736 KB Output is correct
20 Correct 19 ms 15744 KB Output is correct
21 Correct 20 ms 15736 KB Output is correct
22 Correct 18 ms 15744 KB Output is correct
23 Correct 20 ms 15872 KB Output is correct
24 Correct 18 ms 15744 KB Output is correct
25 Correct 19 ms 15616 KB Output is correct
26 Correct 19 ms 15616 KB Output is correct
27 Correct 20 ms 15616 KB Output is correct
28 Correct 19 ms 15616 KB Output is correct
29 Correct 20 ms 15616 KB Output is correct
30 Correct 21 ms 15616 KB Output is correct
31 Correct 2894 ms 24988 KB Output is correct
32 Correct 134 ms 20992 KB Output is correct
33 Correct 263 ms 22996 KB Output is correct
34 Correct 2223 ms 23272 KB Output is correct
35 Correct 1619 ms 25032 KB Output is correct
36 Correct 384 ms 24812 KB Output is correct
37 Correct 179 ms 22764 KB Output is correct
38 Correct 120 ms 22692 KB Output is correct
39 Correct 105 ms 22628 KB Output is correct
40 Correct 101 ms 22608 KB Output is correct
41 Correct 342 ms 22860 KB Output is correct
42 Correct 233 ms 22772 KB Output is correct
43 Correct 441 ms 24400 KB Output is correct
44 Correct 277 ms 23144 KB Output is correct
45 Correct 152 ms 22888 KB Output is correct
46 Correct 104 ms 22888 KB Output is correct
47 Correct 96 ms 22416 KB Output is correct
48 Correct 99 ms 22376 KB Output is correct
49 Correct 116 ms 22508 KB Output is correct
50 Correct 230 ms 22772 KB Output is correct
51 Correct 105 ms 22632 KB Output is correct
52 Correct 138 ms 24780 KB Output is correct
53 Correct 102 ms 23048 KB Output is correct
54 Correct 196 ms 24804 KB Output is correct
55 Execution timed out 5032 ms 22776 KB Time limit exceeded
56 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 17 ms 15616 KB Output is correct
2 Correct 17 ms 15616 KB Output is correct
3 Correct 18 ms 15588 KB Output is correct
4 Correct 18 ms 15616 KB Output is correct
5 Correct 18 ms 15616 KB Output is correct
6 Correct 19 ms 15744 KB Output is correct
7 Correct 23 ms 15616 KB Output is correct
8 Correct 21 ms 15616 KB Output is correct
9 Correct 18 ms 15616 KB Output is correct
10 Correct 18 ms 15616 KB Output is correct
11 Correct 18 ms 15744 KB Output is correct
12 Correct 18 ms 15616 KB Output is correct
13 Correct 18 ms 15616 KB Output is correct
14 Correct 17 ms 15616 KB Output is correct
15 Correct 17 ms 15616 KB Output is correct
16 Correct 19 ms 15616 KB Output is correct
17 Correct 19 ms 15616 KB Output is correct
18 Correct 20 ms 15744 KB Output is correct
19 Correct 19 ms 15736 KB Output is correct
20 Correct 19 ms 15744 KB Output is correct
21 Correct 20 ms 15736 KB Output is correct
22 Correct 18 ms 15744 KB Output is correct
23 Correct 20 ms 15872 KB Output is correct
24 Correct 18 ms 15744 KB Output is correct
25 Correct 19 ms 15616 KB Output is correct
26 Correct 19 ms 15616 KB Output is correct
27 Correct 20 ms 15616 KB Output is correct
28 Correct 19 ms 15616 KB Output is correct
29 Correct 20 ms 15616 KB Output is correct
30 Correct 21 ms 15616 KB Output is correct
31 Correct 2894 ms 24988 KB Output is correct
32 Correct 134 ms 20992 KB Output is correct
33 Correct 263 ms 22996 KB Output is correct
34 Correct 2223 ms 23272 KB Output is correct
35 Correct 1619 ms 25032 KB Output is correct
36 Correct 384 ms 24812 KB Output is correct
37 Correct 179 ms 22764 KB Output is correct
38 Correct 120 ms 22692 KB Output is correct
39 Correct 105 ms 22628 KB Output is correct
40 Correct 101 ms 22608 KB Output is correct
41 Correct 342 ms 22860 KB Output is correct
42 Correct 233 ms 22772 KB Output is correct
43 Correct 441 ms 24400 KB Output is correct
44 Correct 277 ms 23144 KB Output is correct
45 Correct 152 ms 22888 KB Output is correct
46 Correct 104 ms 22888 KB Output is correct
47 Correct 96 ms 22416 KB Output is correct
48 Correct 99 ms 22376 KB Output is correct
49 Correct 116 ms 22508 KB Output is correct
50 Correct 230 ms 22772 KB Output is correct
51 Correct 105 ms 22632 KB Output is correct
52 Execution timed out 5075 ms 45112 KB Time limit exceeded
53 Halted 0 ms 0 KB -