답안 #728996

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
728996 2023-04-23T11:33:00 Z DeMen100ns 새 집 (APIO18_new_home) C++17
100 / 100
2266 ms 125064 KB
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ff first
#define ss second
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define N 2000005
const ll MOD = 1000000007;
const int INF = 0x3f3f3f3f;
 
int x[N], ans[N], y[N], l[N], t[N], a[N], b[N];
int n, k, q;
vector<int> tmp;
 
vector<pair<int, int> > sh[N];
map<int, int> in, ok;
vector<pair<pair<int, int>, pair<int, int> > > lol;
int seg[N];
int hel;
void update(int id, int l, int r, int L, int R, int v){
    if(l >= L && r <= R){
        seg[id] = max(seg[id], v);
        return;
    }
    if(l > R || r < L) return;
    int m = (l + r) >> 1;
    update(id << 1, l, m, L, R, v);
    update(id << 1 | 1, m + 1, r, L, R, v);
}
 
int query(int id, int l, int r, int x){
    if(x < l || x > r) return 0;
    if(l == r) return seg[id];
    int m = (l + r) >> 1;
    return max(seg[id], max(query(id << 1, l, m, x), query(id << 1 | 1, m + 1, r, x)));
}
 
void solve(){
    for(int i = 1; i <= k; ++i){
        in.clear();
        in[INF] = 1;
        in[-INF] = 1;
        for(auto& x : sh[i]){
            if(x.ss > 0){
                if(++ok[x.ss] >= 2)
                    continue;
                auto r = in.insert({x.ss, x.ff}).ff;
                auto l = r++;
                auto it = l--;
                if(r -> ss < x.ff && r -> ff > 0)
                    lol.push_back({{(r -> ff + l -> ff) / 2, r -> ff}, {r -> ss, x.ff - 1}});
                r -> ss = x.ff;
            } else {
                if(--ok[-x.ss] > 0)
                    continue;
                ok.erase(-x.ss);
                auto r = in.find(-x.ss);
                auto l = r++;
                auto it = l--;
                if(it -> ss < x.ff && it -> ff > 0)
                    lol.push_back({{(it -> ff + l -> ff) / 2, it -> ff}, {it -> ss, x.ff - 1}});
                if(r -> ss < x.ff && r -> ff > 0)
                    lol.push_back({{(it -> ff + r -> ff) / 2, r -> ff}, {r -> ss, x.ff - 1}});
                in[r -> ff] = x.ff;
                in.erase(it);
            }
        }
        auto r = in.begin();
        auto l = r++;
        if(r -> ss <= hel && r -> ff > 0)
            lol.push_back({{(r -> ff + l -> ff) / 2, r -> ff}, {r -> ss, hel}});
    }
    for(int i = 1; i <= q; ++i)
        lol.push_back({{l[i], 1'200'000'000}, {i, y[i]}});
    
    sort(lol.begin(), lol.end(), [](const pair<pair<int, int>, pair<int, int> >& lhs, const pair<pair<int, int>, pair<int, int> >& rhs){
        return lhs.ff < rhs.ff;
    });
    for(auto& x : lol){
        if(x.ff.ss != 1'200'000'000)
            update(1, 1, hel, x.ss.ff, x.ss.ss, x.ff.ss);
        else
            ans[x.ss.ff] = max(ans[x.ss.ff], query(1, 1, hel, x.ss.ss) - x.ff.ff);
    }
}
 
int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
 
    cin>>n>>k>>q;
    for(int i = 1; i <= n; ++i)
        cin>>x[i]>>t[i]>>a[i]>>b[i];
    for(int i = 1; i <= q; ++i){
        cin>>l[i]>>y[i];
        l[i] <<= 1;
        tmp.push_back(y[i]);
    }
    sort(tmp.begin(), tmp.end());
    tmp.resize(unique(tmp.begin(), tmp.end()) - tmp.begin());
    hel = tmp.size();
    for(int i = 1; i <= q; ++i)
        y[i] = upper_bound(tmp.begin(), tmp.end(), y[i]) - tmp.begin();
    for(int i = 1; i <= n; ++i){
        a[i] = lower_bound(tmp.begin(), tmp.end(), a[i]) - tmp.begin() + 1;
        b[i] = lower_bound(tmp.begin(), tmp.end(), b[i] + 1) - tmp.begin() + 1;
        if(a[i] < b[i]){
            x[i] <<= 1;
            sh[t[i]].push_back({a[i], x[i]});
            sh[t[i]].push_back({b[i], -x[i]});
        }
    }
 
    for(int i = 1; i <= k; ++i)
        sort(sh[i].begin(), sh[i].end(), [](const pair<int, int>& lhs, const pair<int, int>& rhs){
            return lhs.ff < rhs.ff;
        });
    solve();
 
    memset(seg, 0, sizeof seg);
    lol.clear();
    for(int i = 1; i <= q; ++i)
        l[i] = 200'000'002 - l[i];
    for(int i = 1; i <= k; ++i)
        for(auto& x : sh[i])
            if(x.ss > 0)
                x.ss = 200'000'002 - x.ss;
            else
                x.ss = -200'000'002 - x.ss;
    solve();
 
    for(int i = 1; i <= q; ++i){
        if(ans[i] > 400'000'002)
            cout<<"-1\n";
        else
            cout<<ans[i] / 2<<'\n';
    }
}

Compilation message

new_home.cpp: In function 'void solve()':
new_home.cpp:49:22: warning: variable 'it' set but not used [-Wunused-but-set-variable]
   49 |                 auto it = l--;
      |                      ^~
# 결과 실행 시간 메모리 Grader output
1 Correct 27 ms 55112 KB Output is correct
2 Correct 27 ms 55156 KB Output is correct
3 Correct 27 ms 55164 KB Output is correct
4 Correct 30 ms 55144 KB Output is correct
5 Correct 36 ms 55236 KB Output is correct
6 Correct 30 ms 55272 KB Output is correct
7 Correct 28 ms 55252 KB Output is correct
8 Correct 28 ms 55252 KB Output is correct
9 Correct 29 ms 55236 KB Output is correct
10 Correct 28 ms 55252 KB Output is correct
11 Correct 28 ms 55240 KB Output is correct
12 Correct 28 ms 55260 KB Output is correct
13 Correct 28 ms 55244 KB Output is correct
14 Correct 28 ms 55252 KB Output is correct
15 Correct 31 ms 55260 KB Output is correct
16 Correct 31 ms 55236 KB Output is correct
17 Correct 33 ms 55168 KB Output is correct
18 Correct 28 ms 55236 KB Output is correct
19 Correct 30 ms 55284 KB Output is correct
20 Correct 30 ms 55244 KB Output is correct
21 Correct 33 ms 55252 KB Output is correct
22 Correct 28 ms 55212 KB Output is correct
23 Correct 29 ms 55252 KB Output is correct
24 Correct 30 ms 55240 KB Output is correct
25 Correct 33 ms 55264 KB Output is correct
26 Correct 28 ms 55260 KB Output is correct
27 Correct 28 ms 55172 KB Output is correct
28 Correct 29 ms 55184 KB Output is correct
29 Correct 28 ms 55284 KB Output is correct
30 Correct 28 ms 55148 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 27 ms 55112 KB Output is correct
2 Correct 27 ms 55156 KB Output is correct
3 Correct 27 ms 55164 KB Output is correct
4 Correct 30 ms 55144 KB Output is correct
5 Correct 36 ms 55236 KB Output is correct
6 Correct 30 ms 55272 KB Output is correct
7 Correct 28 ms 55252 KB Output is correct
8 Correct 28 ms 55252 KB Output is correct
9 Correct 29 ms 55236 KB Output is correct
10 Correct 28 ms 55252 KB Output is correct
11 Correct 28 ms 55240 KB Output is correct
12 Correct 28 ms 55260 KB Output is correct
13 Correct 28 ms 55244 KB Output is correct
14 Correct 28 ms 55252 KB Output is correct
15 Correct 31 ms 55260 KB Output is correct
16 Correct 31 ms 55236 KB Output is correct
17 Correct 33 ms 55168 KB Output is correct
18 Correct 28 ms 55236 KB Output is correct
19 Correct 30 ms 55284 KB Output is correct
20 Correct 30 ms 55244 KB Output is correct
21 Correct 33 ms 55252 KB Output is correct
22 Correct 28 ms 55212 KB Output is correct
23 Correct 29 ms 55252 KB Output is correct
24 Correct 30 ms 55240 KB Output is correct
25 Correct 33 ms 55264 KB Output is correct
26 Correct 28 ms 55260 KB Output is correct
27 Correct 28 ms 55172 KB Output is correct
28 Correct 29 ms 55184 KB Output is correct
29 Correct 28 ms 55284 KB Output is correct
30 Correct 28 ms 55148 KB Output is correct
31 Correct 312 ms 66124 KB Output is correct
32 Correct 82 ms 60124 KB Output is correct
33 Correct 322 ms 65284 KB Output is correct
34 Correct 288 ms 66180 KB Output is correct
35 Correct 308 ms 65464 KB Output is correct
36 Correct 336 ms 65748 KB Output is correct
37 Correct 293 ms 65532 KB Output is correct
38 Correct 330 ms 65124 KB Output is correct
39 Correct 248 ms 64996 KB Output is correct
40 Correct 306 ms 64948 KB Output is correct
41 Correct 238 ms 65464 KB Output is correct
42 Correct 255 ms 65576 KB Output is correct
43 Correct 71 ms 62568 KB Output is correct
44 Correct 235 ms 65708 KB Output is correct
45 Correct 239 ms 65540 KB Output is correct
46 Correct 214 ms 65280 KB Output is correct
47 Correct 179 ms 64812 KB Output is correct
48 Correct 176 ms 64536 KB Output is correct
49 Correct 195 ms 65288 KB Output is correct
50 Correct 208 ms 65808 KB Output is correct
51 Correct 204 ms 64960 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 848 ms 99068 KB Output is correct
2 Correct 1201 ms 95936 KB Output is correct
3 Correct 811 ms 104740 KB Output is correct
4 Correct 748 ms 99620 KB Output is correct
5 Correct 1612 ms 120324 KB Output is correct
6 Correct 1275 ms 98580 KB Output is correct
7 Correct 744 ms 104780 KB Output is correct
8 Correct 723 ms 99096 KB Output is correct
9 Correct 746 ms 97456 KB Output is correct
10 Correct 884 ms 95320 KB Output is correct
11 Correct 860 ms 96292 KB Output is correct
12 Correct 819 ms 95412 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1312 ms 101200 KB Output is correct
2 Correct 266 ms 81584 KB Output is correct
3 Correct 1629 ms 100316 KB Output is correct
4 Correct 1168 ms 111456 KB Output is correct
5 Correct 1132 ms 101804 KB Output is correct
6 Correct 1071 ms 102464 KB Output is correct
7 Correct 2266 ms 125064 KB Output is correct
8 Correct 1786 ms 103068 KB Output is correct
9 Correct 1036 ms 111500 KB Output is correct
10 Correct 1045 ms 102760 KB Output is correct
11 Correct 1112 ms 101160 KB Output is correct
12 Correct 1308 ms 100992 KB Output is correct
13 Correct 955 ms 99488 KB Output is correct
14 Correct 1006 ms 101832 KB Output is correct
15 Correct 1091 ms 98816 KB Output is correct
16 Correct 1045 ms 99928 KB Output is correct
17 Correct 1141 ms 100000 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 27 ms 55112 KB Output is correct
2 Correct 27 ms 55156 KB Output is correct
3 Correct 27 ms 55164 KB Output is correct
4 Correct 30 ms 55144 KB Output is correct
5 Correct 36 ms 55236 KB Output is correct
6 Correct 30 ms 55272 KB Output is correct
7 Correct 28 ms 55252 KB Output is correct
8 Correct 28 ms 55252 KB Output is correct
9 Correct 29 ms 55236 KB Output is correct
10 Correct 28 ms 55252 KB Output is correct
11 Correct 28 ms 55240 KB Output is correct
12 Correct 28 ms 55260 KB Output is correct
13 Correct 28 ms 55244 KB Output is correct
14 Correct 28 ms 55252 KB Output is correct
15 Correct 31 ms 55260 KB Output is correct
16 Correct 31 ms 55236 KB Output is correct
17 Correct 33 ms 55168 KB Output is correct
18 Correct 28 ms 55236 KB Output is correct
19 Correct 30 ms 55284 KB Output is correct
20 Correct 30 ms 55244 KB Output is correct
21 Correct 33 ms 55252 KB Output is correct
22 Correct 28 ms 55212 KB Output is correct
23 Correct 29 ms 55252 KB Output is correct
24 Correct 30 ms 55240 KB Output is correct
25 Correct 33 ms 55264 KB Output is correct
26 Correct 28 ms 55260 KB Output is correct
27 Correct 28 ms 55172 KB Output is correct
28 Correct 29 ms 55184 KB Output is correct
29 Correct 28 ms 55284 KB Output is correct
30 Correct 28 ms 55148 KB Output is correct
31 Correct 312 ms 66124 KB Output is correct
32 Correct 82 ms 60124 KB Output is correct
33 Correct 322 ms 65284 KB Output is correct
34 Correct 288 ms 66180 KB Output is correct
35 Correct 308 ms 65464 KB Output is correct
36 Correct 336 ms 65748 KB Output is correct
37 Correct 293 ms 65532 KB Output is correct
38 Correct 330 ms 65124 KB Output is correct
39 Correct 248 ms 64996 KB Output is correct
40 Correct 306 ms 64948 KB Output is correct
41 Correct 238 ms 65464 KB Output is correct
42 Correct 255 ms 65576 KB Output is correct
43 Correct 71 ms 62568 KB Output is correct
44 Correct 235 ms 65708 KB Output is correct
45 Correct 239 ms 65540 KB Output is correct
46 Correct 214 ms 65280 KB Output is correct
47 Correct 179 ms 64812 KB Output is correct
48 Correct 176 ms 64536 KB Output is correct
49 Correct 195 ms 65288 KB Output is correct
50 Correct 208 ms 65808 KB Output is correct
51 Correct 204 ms 64960 KB Output is correct
52 Correct 270 ms 67044 KB Output is correct
53 Correct 270 ms 66888 KB Output is correct
54 Correct 269 ms 66008 KB Output is correct
55 Correct 237 ms 66184 KB Output is correct
56 Correct 240 ms 66480 KB Output is correct
57 Correct 240 ms 65664 KB Output is correct
58 Correct 248 ms 66156 KB Output is correct
59 Correct 249 ms 66356 KB Output is correct
60 Correct 250 ms 65888 KB Output is correct
61 Correct 100 ms 64820 KB Output is correct
62 Correct 266 ms 67196 KB Output is correct
63 Correct 267 ms 66256 KB Output is correct
64 Correct 286 ms 65924 KB Output is correct
65 Correct 264 ms 65884 KB Output is correct
66 Correct 246 ms 65712 KB Output is correct
67 Correct 145 ms 63532 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 27 ms 55112 KB Output is correct
2 Correct 27 ms 55156 KB Output is correct
3 Correct 27 ms 55164 KB Output is correct
4 Correct 30 ms 55144 KB Output is correct
5 Correct 36 ms 55236 KB Output is correct
6 Correct 30 ms 55272 KB Output is correct
7 Correct 28 ms 55252 KB Output is correct
8 Correct 28 ms 55252 KB Output is correct
9 Correct 29 ms 55236 KB Output is correct
10 Correct 28 ms 55252 KB Output is correct
11 Correct 28 ms 55240 KB Output is correct
12 Correct 28 ms 55260 KB Output is correct
13 Correct 28 ms 55244 KB Output is correct
14 Correct 28 ms 55252 KB Output is correct
15 Correct 31 ms 55260 KB Output is correct
16 Correct 31 ms 55236 KB Output is correct
17 Correct 33 ms 55168 KB Output is correct
18 Correct 28 ms 55236 KB Output is correct
19 Correct 30 ms 55284 KB Output is correct
20 Correct 30 ms 55244 KB Output is correct
21 Correct 33 ms 55252 KB Output is correct
22 Correct 28 ms 55212 KB Output is correct
23 Correct 29 ms 55252 KB Output is correct
24 Correct 30 ms 55240 KB Output is correct
25 Correct 33 ms 55264 KB Output is correct
26 Correct 28 ms 55260 KB Output is correct
27 Correct 28 ms 55172 KB Output is correct
28 Correct 29 ms 55184 KB Output is correct
29 Correct 28 ms 55284 KB Output is correct
30 Correct 28 ms 55148 KB Output is correct
31 Correct 312 ms 66124 KB Output is correct
32 Correct 82 ms 60124 KB Output is correct
33 Correct 322 ms 65284 KB Output is correct
34 Correct 288 ms 66180 KB Output is correct
35 Correct 308 ms 65464 KB Output is correct
36 Correct 336 ms 65748 KB Output is correct
37 Correct 293 ms 65532 KB Output is correct
38 Correct 330 ms 65124 KB Output is correct
39 Correct 248 ms 64996 KB Output is correct
40 Correct 306 ms 64948 KB Output is correct
41 Correct 238 ms 65464 KB Output is correct
42 Correct 255 ms 65576 KB Output is correct
43 Correct 71 ms 62568 KB Output is correct
44 Correct 235 ms 65708 KB Output is correct
45 Correct 239 ms 65540 KB Output is correct
46 Correct 214 ms 65280 KB Output is correct
47 Correct 179 ms 64812 KB Output is correct
48 Correct 176 ms 64536 KB Output is correct
49 Correct 195 ms 65288 KB Output is correct
50 Correct 208 ms 65808 KB Output is correct
51 Correct 204 ms 64960 KB Output is correct
52 Correct 848 ms 99068 KB Output is correct
53 Correct 1201 ms 95936 KB Output is correct
54 Correct 811 ms 104740 KB Output is correct
55 Correct 748 ms 99620 KB Output is correct
56 Correct 1612 ms 120324 KB Output is correct
57 Correct 1275 ms 98580 KB Output is correct
58 Correct 744 ms 104780 KB Output is correct
59 Correct 723 ms 99096 KB Output is correct
60 Correct 746 ms 97456 KB Output is correct
61 Correct 884 ms 95320 KB Output is correct
62 Correct 860 ms 96292 KB Output is correct
63 Correct 819 ms 95412 KB Output is correct
64 Correct 1312 ms 101200 KB Output is correct
65 Correct 266 ms 81584 KB Output is correct
66 Correct 1629 ms 100316 KB Output is correct
67 Correct 1168 ms 111456 KB Output is correct
68 Correct 1132 ms 101804 KB Output is correct
69 Correct 1071 ms 102464 KB Output is correct
70 Correct 2266 ms 125064 KB Output is correct
71 Correct 1786 ms 103068 KB Output is correct
72 Correct 1036 ms 111500 KB Output is correct
73 Correct 1045 ms 102760 KB Output is correct
74 Correct 1112 ms 101160 KB Output is correct
75 Correct 1308 ms 100992 KB Output is correct
76 Correct 955 ms 99488 KB Output is correct
77 Correct 1006 ms 101832 KB Output is correct
78 Correct 1091 ms 98816 KB Output is correct
79 Correct 1045 ms 99928 KB Output is correct
80 Correct 1141 ms 100000 KB Output is correct
81 Correct 270 ms 67044 KB Output is correct
82 Correct 270 ms 66888 KB Output is correct
83 Correct 269 ms 66008 KB Output is correct
84 Correct 237 ms 66184 KB Output is correct
85 Correct 240 ms 66480 KB Output is correct
86 Correct 240 ms 65664 KB Output is correct
87 Correct 248 ms 66156 KB Output is correct
88 Correct 249 ms 66356 KB Output is correct
89 Correct 250 ms 65888 KB Output is correct
90 Correct 100 ms 64820 KB Output is correct
91 Correct 266 ms 67196 KB Output is correct
92 Correct 267 ms 66256 KB Output is correct
93 Correct 286 ms 65924 KB Output is correct
94 Correct 264 ms 65884 KB Output is correct
95 Correct 246 ms 65712 KB Output is correct
96 Correct 145 ms 63532 KB Output is correct
97 Correct 1449 ms 114028 KB Output is correct
98 Correct 293 ms 82528 KB Output is correct
99 Correct 1798 ms 110428 KB Output is correct
100 Correct 1470 ms 114016 KB Output is correct
101 Correct 1428 ms 111492 KB Output is correct
102 Correct 1856 ms 111944 KB Output is correct
103 Correct 1487 ms 110124 KB Output is correct
104 Correct 1623 ms 109704 KB Output is correct
105 Correct 1290 ms 110076 KB Output is correct
106 Correct 1395 ms 110240 KB Output is correct
107 Correct 1234 ms 110520 KB Output is correct
108 Correct 1235 ms 111692 KB Output is correct
109 Correct 1271 ms 111000 KB Output is correct
110 Correct 1251 ms 111508 KB Output is correct
111 Correct 1276 ms 111924 KB Output is correct
112 Correct 1252 ms 110756 KB Output is correct
113 Correct 406 ms 103292 KB Output is correct
114 Correct 1337 ms 114544 KB Output is correct
115 Correct 1357 ms 111772 KB Output is correct
116 Correct 1346 ms 110556 KB Output is correct
117 Correct 1329 ms 110816 KB Output is correct
118 Correct 1279 ms 110488 KB Output is correct
119 Correct 604 ms 101420 KB Output is correct
120 Correct 759 ms 109616 KB Output is correct
121 Correct 864 ms 109112 KB Output is correct
122 Correct 827 ms 109376 KB Output is correct
123 Correct 947 ms 109604 KB Output is correct
124 Correct 1064 ms 109588 KB Output is correct
125 Correct 944 ms 109332 KB Output is correct
126 Correct 1095 ms 111784 KB Output is correct