답안 #60917

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
60917 2018-07-25T01:23:27 Z duality 새 집 (APIO18_new_home) C++11
100 / 100
4950 ms 323008 KB
#define DEBUG 0

#include <bits/stdc++.h>
using namespace std;

#if DEBUG
// basic debugging macros
int __i__,__j__;
#define printLine(l) for(__i__=0;__i__<l;__i__++){cout<<"-";}cout<<endl
#define printLine2(l,c) for(__i__=0;__i__<l;__i__++){cout<<c;}cout<<endl
#define printVar(n) cout<<#n<<": "<<n<<endl
#define printArr(a,l) cout<<#a<<": ";for(__i__=0;__i__<l;__i__++){cout<<a[__i__]<<" ";}cout<<endl
#define print2dArr(a,r,c) cout<<#a<<":\n";for(__i__=0;__i__<r;__i__++){for(__j__=0;__j__<c;__j__++){cout<<a[__i__][__j__]<<" ";}cout<<endl;}
#define print2dArr2(a,r,c,l) cout<<#a<<":\n";for(__i__=0;__i__<r;__i__++){for(__j__=0;__j__<c;__j__++){cout<<setw(l)<<setfill(' ')<<a[__i__][__j__]<<" ";}cout<<endl;}

// advanced debugging class
// debug 1,2,'A',"test";
class _Debug {
    public:
        template<typename T>
        _Debug& operator,(T val) {
            cout << val << endl;
            return *this;
        }
};
#define debug _Debug(),
#else
#define printLine(l)
#define printLine2(l,c)
#define printVar(n)
#define printArr(a,l)
#define print2dArr(a,r,c)
#define print2dArr2(a,r,c,l)
#define debug
#endif

// define
#define MAX_VAL 999999999
#define MAX_VAL_2 999999999999999999LL
#define EPS 1e-6
#define mp make_pair
#define pb push_back

// typedef
typedef unsigned int UI;
typedef long long int LLI;
typedef unsigned long long int ULLI;
typedef unsigned short int US;
typedef pair<int,int> pii;
typedef pair<LLI,LLI> plli;
typedef vector<int> vi;
typedef vector<LLI> vlli;
typedef vector<pii> vpii;
typedef vector<plli> vplli;

// ---------- END OF TEMPLATE ----------
int readInt() {
    char c;
    while ((c=getchar()) < '0');
    int n = c-'0';
    while ((c=getchar()) >= '0') n *= 10,n += c-'0';
    return n;
}

struct event { int time,x,t; };
bool comp(event a,event b) {
    if (a.time == b.time) return a.t < b.t;
    else return a.time < b.time;
}
vi sorted;
vector<event> events[300000];
multimap<int,int> S;
vector<pair<pii,pii> > oper;
vpii tree[600000];
int ans[300000];
int update(int as,int ae,pii p) {
    as += sorted.size(),ae += sorted.size()+1;
    while (as < ae) {
        if (as & 1) tree[as++].pb(p);
        if (ae & 1) tree[--ae].pb(p);
        as >>= 1,ae >>= 1;
    }
    return 0;
}
int query(int q,pii p) {
    q += sorted.size();
    while (q > 0) tree[q].pb(p),q >>= 1;
    return 0;
}
int main() {
    int i,j;
    int n,k,q;
    int x,t,a,b,l,y;
    n = readInt(),k = readInt(),q = readInt();
    for (i = 0; i < n; i++) {
        x = readInt(),t = readInt()-1,a = readInt(),b = readInt();
        events[t].pb((event){a,x,1});
        events[t].pb((event){b+1,x,-1});
    }
    for (i = 0; i < k; i++) {
        sort(events[i].begin(),events[i].end(),comp);
        S.insert(mp(-3e8,1)),S.insert(mp(3e8,1));
        for (j = 0; j < events[i].size(); j++) {
            if (events[i][j].t == 1) {
                auto it = S.lower_bound(events[i][j].x);
                auto it2 = it;
                it2--;
                pii p = mp(it->first+it2->first,it->first-it2->first);
                oper.pb(mp(p,mp(it2->second,events[i][j].time)));
                it2->second = events[i][j].time;
                S.insert(it,mp(events[i][j].x,events[i][j].time));
            }
            else {
                auto it = S.find(events[i][j].x);
                auto it2 = it;
                it2--;
                pii p = mp(it->first+it2->first,it->first-it2->first);
                oper.pb(mp(p,mp(it2->second,events[i][j].time)));
                it++,it2++,p = mp(it->first+it2->first,it->first-it2->first);
                oper.pb(mp(p,mp(it2->second,events[i][j].time)));
                it2--,p = mp(it->first+it2->first,it->first-it2->first);
                it2->second = events[i][j].time;
                S.erase(--it);
            }
        }
        oper.pb(mp(mp(0,6e8),mp(S.begin()->second,3e8)));
        S.clear();
    }
    for (i = 0; i < q; i++) {
        l = readInt(),y = readInt();
        sorted.pb(y);
        oper.pb(mp(mp(2*l,-(i+1)),mp(y,-1)));
    }
    sort(oper.begin(),oper.end());
    sort(sorted.begin(),sorted.end());
    sorted.resize(unique(sorted.begin(),sorted.end())-sorted.begin());
    for (i = 0; i < oper.size(); i++) {
        if (oper[i].second.second == -1) {
            oper[i].second.first = lower_bound(sorted.begin(),sorted.end(),oper[i].second.first)-sorted.begin();
            query(oper[i].second.first,oper[i].first);
        }
        else {
            oper[i].second.first = lower_bound(sorted.begin(),sorted.end(),oper[i].second.first)-sorted.begin();
            oper[i].second.second = lower_bound(sorted.begin(),sorted.end(),oper[i].second.second)-sorted.begin()-1;
            if (oper[i].second.first <= oper[i].second.second) update(oper[i].second.first,oper[i].second.second,oper[i].first);
        }
    }
    for (i = 1; i < 2*sorted.size(); i++) {
        pii m = mp(-3e8,0);
        for (j = 0; j < tree[i].size(); j++) {
            if (tree[i][j].second >= 0) {
                if (tree[i][j].second > m.second-(tree[i][j].first-m.first)) m = tree[i][j];
            }
            else ans[-tree[i][j].second-1] = max(ans[-tree[i][j].second-1],m.second-(tree[i][j].first-m.first));
        }
        m = mp(3e8,0);
        for (j = tree[i].size()-1; j >= 0; j--) {
            if (tree[i][j].second >= 0) {
                if (tree[i][j].second > m.second-(m.first-tree[i][j].first)) m = tree[i][j];
            }
            else ans[-tree[i][j].second-1] = max(ans[-tree[i][j].second-1],m.second-(m.first-tree[i][j].first));
        }
    }
    for (i = 0; i < q; i++) printf("%d\n",(ans[i] > 3e8) ? -1:ans[i]/2);

    return 0;
}

Compilation message

new_home.cpp: In function 'int main()':
new_home.cpp:103:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for (j = 0; j < events[i].size(); j++) {
                     ~~^~~~~~~~~~~~~~~~~~
new_home.cpp:137:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (i = 0; i < oper.size(); i++) {
                 ~~^~~~~~~~~~~~~
new_home.cpp:148:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (i = 1; i < 2*sorted.size(); i++) {
                 ~~^~~~~~~~~~~~~~~~~
new_home.cpp:150:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for (j = 0; j < tree[i].size(); j++) {
                     ~~^~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 22 ms 21496 KB Output is correct
2 Correct 21 ms 21496 KB Output is correct
3 Correct 20 ms 21536 KB Output is correct
4 Correct 20 ms 21636 KB Output is correct
5 Correct 21 ms 21744 KB Output is correct
6 Correct 21 ms 21744 KB Output is correct
7 Correct 23 ms 21792 KB Output is correct
8 Correct 23 ms 21792 KB Output is correct
9 Correct 23 ms 21792 KB Output is correct
10 Correct 23 ms 21920 KB Output is correct
11 Correct 22 ms 21920 KB Output is correct
12 Correct 23 ms 21920 KB Output is correct
13 Correct 22 ms 21920 KB Output is correct
14 Correct 26 ms 21920 KB Output is correct
15 Correct 21 ms 21920 KB Output is correct
16 Correct 24 ms 21920 KB Output is correct
17 Correct 24 ms 21996 KB Output is correct
18 Correct 23 ms 21996 KB Output is correct
19 Correct 23 ms 21996 KB Output is correct
20 Correct 23 ms 21996 KB Output is correct
21 Correct 22 ms 21996 KB Output is correct
22 Correct 23 ms 21996 KB Output is correct
23 Correct 22 ms 21996 KB Output is correct
24 Correct 23 ms 21996 KB Output is correct
25 Correct 20 ms 21996 KB Output is correct
26 Correct 22 ms 21996 KB Output is correct
27 Correct 21 ms 21996 KB Output is correct
28 Correct 23 ms 21996 KB Output is correct
29 Correct 24 ms 21996 KB Output is correct
30 Correct 23 ms 21996 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 22 ms 21496 KB Output is correct
2 Correct 21 ms 21496 KB Output is correct
3 Correct 20 ms 21536 KB Output is correct
4 Correct 20 ms 21636 KB Output is correct
5 Correct 21 ms 21744 KB Output is correct
6 Correct 21 ms 21744 KB Output is correct
7 Correct 23 ms 21792 KB Output is correct
8 Correct 23 ms 21792 KB Output is correct
9 Correct 23 ms 21792 KB Output is correct
10 Correct 23 ms 21920 KB Output is correct
11 Correct 22 ms 21920 KB Output is correct
12 Correct 23 ms 21920 KB Output is correct
13 Correct 22 ms 21920 KB Output is correct
14 Correct 26 ms 21920 KB Output is correct
15 Correct 21 ms 21920 KB Output is correct
16 Correct 24 ms 21920 KB Output is correct
17 Correct 24 ms 21996 KB Output is correct
18 Correct 23 ms 21996 KB Output is correct
19 Correct 23 ms 21996 KB Output is correct
20 Correct 23 ms 21996 KB Output is correct
21 Correct 22 ms 21996 KB Output is correct
22 Correct 23 ms 21996 KB Output is correct
23 Correct 22 ms 21996 KB Output is correct
24 Correct 23 ms 21996 KB Output is correct
25 Correct 20 ms 21996 KB Output is correct
26 Correct 22 ms 21996 KB Output is correct
27 Correct 21 ms 21996 KB Output is correct
28 Correct 23 ms 21996 KB Output is correct
29 Correct 24 ms 21996 KB Output is correct
30 Correct 23 ms 21996 KB Output is correct
31 Correct 576 ms 64724 KB Output is correct
32 Correct 119 ms 64724 KB Output is correct
33 Correct 526 ms 64724 KB Output is correct
34 Correct 549 ms 64724 KB Output is correct
35 Correct 562 ms 64724 KB Output is correct
36 Correct 533 ms 64724 KB Output is correct
37 Correct 356 ms 64724 KB Output is correct
38 Correct 393 ms 64724 KB Output is correct
39 Correct 292 ms 64724 KB Output is correct
40 Correct 306 ms 64724 KB Output is correct
41 Correct 510 ms 64724 KB Output is correct
42 Correct 505 ms 64724 KB Output is correct
43 Correct 93 ms 64724 KB Output is correct
44 Correct 481 ms 64724 KB Output is correct
45 Correct 450 ms 64724 KB Output is correct
46 Correct 388 ms 64724 KB Output is correct
47 Correct 238 ms 64724 KB Output is correct
48 Correct 221 ms 64724 KB Output is correct
49 Correct 289 ms 64724 KB Output is correct
50 Correct 302 ms 64724 KB Output is correct
51 Correct 266 ms 64724 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2156 ms 185128 KB Output is correct
2 Correct 2199 ms 185128 KB Output is correct
3 Correct 2405 ms 252568 KB Output is correct
4 Correct 2016 ms 252568 KB Output is correct
5 Correct 2368 ms 252568 KB Output is correct
6 Correct 2108 ms 252568 KB Output is correct
7 Correct 2121 ms 256236 KB Output is correct
8 Correct 1881 ms 256236 KB Output is correct
9 Correct 2040 ms 256236 KB Output is correct
10 Correct 2174 ms 256236 KB Output is correct
11 Correct 1194 ms 256236 KB Output is correct
12 Correct 1146 ms 256236 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3265 ms 256236 KB Output is correct
2 Correct 523 ms 256236 KB Output is correct
3 Correct 3374 ms 256236 KB Output is correct
4 Correct 3657 ms 293584 KB Output is correct
5 Correct 3354 ms 293584 KB Output is correct
6 Correct 3485 ms 293584 KB Output is correct
7 Correct 3627 ms 293584 KB Output is correct
8 Correct 3168 ms 293584 KB Output is correct
9 Correct 2825 ms 301232 KB Output is correct
10 Correct 3056 ms 301232 KB Output is correct
11 Correct 3116 ms 301232 KB Output is correct
12 Correct 3245 ms 301232 KB Output is correct
13 Correct 1303 ms 301232 KB Output is correct
14 Correct 1434 ms 301232 KB Output is correct
15 Correct 1757 ms 301232 KB Output is correct
16 Correct 1818 ms 301232 KB Output is correct
17 Correct 1902 ms 301232 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 22 ms 21496 KB Output is correct
2 Correct 21 ms 21496 KB Output is correct
3 Correct 20 ms 21536 KB Output is correct
4 Correct 20 ms 21636 KB Output is correct
5 Correct 21 ms 21744 KB Output is correct
6 Correct 21 ms 21744 KB Output is correct
7 Correct 23 ms 21792 KB Output is correct
8 Correct 23 ms 21792 KB Output is correct
9 Correct 23 ms 21792 KB Output is correct
10 Correct 23 ms 21920 KB Output is correct
11 Correct 22 ms 21920 KB Output is correct
12 Correct 23 ms 21920 KB Output is correct
13 Correct 22 ms 21920 KB Output is correct
14 Correct 26 ms 21920 KB Output is correct
15 Correct 21 ms 21920 KB Output is correct
16 Correct 24 ms 21920 KB Output is correct
17 Correct 24 ms 21996 KB Output is correct
18 Correct 23 ms 21996 KB Output is correct
19 Correct 23 ms 21996 KB Output is correct
20 Correct 23 ms 21996 KB Output is correct
21 Correct 22 ms 21996 KB Output is correct
22 Correct 23 ms 21996 KB Output is correct
23 Correct 22 ms 21996 KB Output is correct
24 Correct 23 ms 21996 KB Output is correct
25 Correct 20 ms 21996 KB Output is correct
26 Correct 22 ms 21996 KB Output is correct
27 Correct 21 ms 21996 KB Output is correct
28 Correct 23 ms 21996 KB Output is correct
29 Correct 24 ms 21996 KB Output is correct
30 Correct 23 ms 21996 KB Output is correct
31 Correct 576 ms 64724 KB Output is correct
32 Correct 119 ms 64724 KB Output is correct
33 Correct 526 ms 64724 KB Output is correct
34 Correct 549 ms 64724 KB Output is correct
35 Correct 562 ms 64724 KB Output is correct
36 Correct 533 ms 64724 KB Output is correct
37 Correct 356 ms 64724 KB Output is correct
38 Correct 393 ms 64724 KB Output is correct
39 Correct 292 ms 64724 KB Output is correct
40 Correct 306 ms 64724 KB Output is correct
41 Correct 510 ms 64724 KB Output is correct
42 Correct 505 ms 64724 KB Output is correct
43 Correct 93 ms 64724 KB Output is correct
44 Correct 481 ms 64724 KB Output is correct
45 Correct 450 ms 64724 KB Output is correct
46 Correct 388 ms 64724 KB Output is correct
47 Correct 238 ms 64724 KB Output is correct
48 Correct 221 ms 64724 KB Output is correct
49 Correct 289 ms 64724 KB Output is correct
50 Correct 302 ms 64724 KB Output is correct
51 Correct 266 ms 64724 KB Output is correct
52 Correct 590 ms 301232 KB Output is correct
53 Correct 650 ms 301232 KB Output is correct
54 Correct 691 ms 301232 KB Output is correct
55 Correct 514 ms 301232 KB Output is correct
56 Correct 447 ms 301232 KB Output is correct
57 Correct 549 ms 301232 KB Output is correct
58 Correct 589 ms 301232 KB Output is correct
59 Correct 604 ms 301232 KB Output is correct
60 Correct 652 ms 301232 KB Output is correct
61 Correct 133 ms 301232 KB Output is correct
62 Correct 531 ms 301232 KB Output is correct
63 Correct 532 ms 301232 KB Output is correct
64 Correct 553 ms 301232 KB Output is correct
65 Correct 554 ms 301232 KB Output is correct
66 Correct 511 ms 301232 KB Output is correct
67 Correct 139 ms 301232 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 22 ms 21496 KB Output is correct
2 Correct 21 ms 21496 KB Output is correct
3 Correct 20 ms 21536 KB Output is correct
4 Correct 20 ms 21636 KB Output is correct
5 Correct 21 ms 21744 KB Output is correct
6 Correct 21 ms 21744 KB Output is correct
7 Correct 23 ms 21792 KB Output is correct
8 Correct 23 ms 21792 KB Output is correct
9 Correct 23 ms 21792 KB Output is correct
10 Correct 23 ms 21920 KB Output is correct
11 Correct 22 ms 21920 KB Output is correct
12 Correct 23 ms 21920 KB Output is correct
13 Correct 22 ms 21920 KB Output is correct
14 Correct 26 ms 21920 KB Output is correct
15 Correct 21 ms 21920 KB Output is correct
16 Correct 24 ms 21920 KB Output is correct
17 Correct 24 ms 21996 KB Output is correct
18 Correct 23 ms 21996 KB Output is correct
19 Correct 23 ms 21996 KB Output is correct
20 Correct 23 ms 21996 KB Output is correct
21 Correct 22 ms 21996 KB Output is correct
22 Correct 23 ms 21996 KB Output is correct
23 Correct 22 ms 21996 KB Output is correct
24 Correct 23 ms 21996 KB Output is correct
25 Correct 20 ms 21996 KB Output is correct
26 Correct 22 ms 21996 KB Output is correct
27 Correct 21 ms 21996 KB Output is correct
28 Correct 23 ms 21996 KB Output is correct
29 Correct 24 ms 21996 KB Output is correct
30 Correct 23 ms 21996 KB Output is correct
31 Correct 576 ms 64724 KB Output is correct
32 Correct 119 ms 64724 KB Output is correct
33 Correct 526 ms 64724 KB Output is correct
34 Correct 549 ms 64724 KB Output is correct
35 Correct 562 ms 64724 KB Output is correct
36 Correct 533 ms 64724 KB Output is correct
37 Correct 356 ms 64724 KB Output is correct
38 Correct 393 ms 64724 KB Output is correct
39 Correct 292 ms 64724 KB Output is correct
40 Correct 306 ms 64724 KB Output is correct
41 Correct 510 ms 64724 KB Output is correct
42 Correct 505 ms 64724 KB Output is correct
43 Correct 93 ms 64724 KB Output is correct
44 Correct 481 ms 64724 KB Output is correct
45 Correct 450 ms 64724 KB Output is correct
46 Correct 388 ms 64724 KB Output is correct
47 Correct 238 ms 64724 KB Output is correct
48 Correct 221 ms 64724 KB Output is correct
49 Correct 289 ms 64724 KB Output is correct
50 Correct 302 ms 64724 KB Output is correct
51 Correct 266 ms 64724 KB Output is correct
52 Correct 2156 ms 185128 KB Output is correct
53 Correct 2199 ms 185128 KB Output is correct
54 Correct 2405 ms 252568 KB Output is correct
55 Correct 2016 ms 252568 KB Output is correct
56 Correct 2368 ms 252568 KB Output is correct
57 Correct 2108 ms 252568 KB Output is correct
58 Correct 2121 ms 256236 KB Output is correct
59 Correct 1881 ms 256236 KB Output is correct
60 Correct 2040 ms 256236 KB Output is correct
61 Correct 2174 ms 256236 KB Output is correct
62 Correct 1194 ms 256236 KB Output is correct
63 Correct 1146 ms 256236 KB Output is correct
64 Correct 3265 ms 256236 KB Output is correct
65 Correct 523 ms 256236 KB Output is correct
66 Correct 3374 ms 256236 KB Output is correct
67 Correct 3657 ms 293584 KB Output is correct
68 Correct 3354 ms 293584 KB Output is correct
69 Correct 3485 ms 293584 KB Output is correct
70 Correct 3627 ms 293584 KB Output is correct
71 Correct 3168 ms 293584 KB Output is correct
72 Correct 2825 ms 301232 KB Output is correct
73 Correct 3056 ms 301232 KB Output is correct
74 Correct 3116 ms 301232 KB Output is correct
75 Correct 3245 ms 301232 KB Output is correct
76 Correct 1303 ms 301232 KB Output is correct
77 Correct 1434 ms 301232 KB Output is correct
78 Correct 1757 ms 301232 KB Output is correct
79 Correct 1818 ms 301232 KB Output is correct
80 Correct 1902 ms 301232 KB Output is correct
81 Correct 590 ms 301232 KB Output is correct
82 Correct 650 ms 301232 KB Output is correct
83 Correct 691 ms 301232 KB Output is correct
84 Correct 514 ms 301232 KB Output is correct
85 Correct 447 ms 301232 KB Output is correct
86 Correct 549 ms 301232 KB Output is correct
87 Correct 589 ms 301232 KB Output is correct
88 Correct 604 ms 301232 KB Output is correct
89 Correct 652 ms 301232 KB Output is correct
90 Correct 133 ms 301232 KB Output is correct
91 Correct 531 ms 301232 KB Output is correct
92 Correct 532 ms 301232 KB Output is correct
93 Correct 553 ms 301232 KB Output is correct
94 Correct 554 ms 301232 KB Output is correct
95 Correct 511 ms 301232 KB Output is correct
96 Correct 139 ms 301232 KB Output is correct
97 Correct 4696 ms 323008 KB Output is correct
98 Correct 638 ms 323008 KB Output is correct
99 Correct 4591 ms 323008 KB Output is correct
100 Correct 4491 ms 323008 KB Output is correct
101 Correct 4950 ms 323008 KB Output is correct
102 Correct 4611 ms 323008 KB Output is correct
103 Correct 3098 ms 323008 KB Output is correct
104 Correct 3107 ms 323008 KB Output is correct
105 Correct 1795 ms 323008 KB Output is correct
106 Correct 1931 ms 323008 KB Output is correct
107 Correct 3858 ms 323008 KB Output is correct
108 Correct 3358 ms 323008 KB Output is correct
109 Correct 4056 ms 323008 KB Output is correct
110 Correct 4638 ms 323008 KB Output is correct
111 Correct 4330 ms 323008 KB Output is correct
112 Correct 3850 ms 323008 KB Output is correct
113 Correct 563 ms 323008 KB Output is correct
114 Correct 3938 ms 323008 KB Output is correct
115 Correct 4131 ms 323008 KB Output is correct
116 Correct 4244 ms 323008 KB Output is correct
117 Correct 4246 ms 323008 KB Output is correct
118 Correct 4380 ms 323008 KB Output is correct
119 Correct 606 ms 323008 KB Output is correct
120 Correct 1139 ms 323008 KB Output is correct
121 Correct 1230 ms 323008 KB Output is correct
122 Correct 1227 ms 323008 KB Output is correct
123 Correct 1415 ms 323008 KB Output is correct
124 Correct 1818 ms 323008 KB Output is correct
125 Correct 1687 ms 323008 KB Output is correct
126 Correct 1980 ms 323008 KB Output is correct