Submission #238986

# Submission time Handle Problem Language Result Execution time Memory
238986 2020-06-13T21:46:50 Z duality Sky Walking (IOI19_walk) C++14
100 / 100
1218 ms 104368 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 ----------

vi events[100000];
vpii events2;
multiset<int> S;
map<int,int> M;
vi vv[100000],nodes[100000];
int xx[1200002];
vpii adjList[1200002];
LLI dist[1200002];
priority_queue<pair<LLI,int> > H;
long long int min_distance(vector<int> x,vector<int> h,vector<int> l,vector<int> r,vector<int> y,int s,int g) {
    int i,j,n = x.size(),m = y.size(),num = 0;
    for (i = 0; i < n; i++) events2.pb(mp(h[i],i));
    for (i = 0; i < m; i++) events[l[i]].pb(i),events[r[i]].pb(i),events2.pb(mp(y[i],-i-1));
    sort(events2.begin(),events2.end(),greater<pii>());
    for (i = 0; i < events2.size(); i++) {
        if (events2[i].second >= 0) S.insert(events2[i].second);
        else {
            int v = -events2[i].second-1;
            auto it = S.lower_bound(s);
            if ((it != S.end()) && (*it > l[v]) && (*it < r[v])) events[*it].pb(v);
            if (it != S.begin()) {
                it--;
                if ((*it > l[v]) && (*it < r[v])) events[*it].pb(v);
            }
            it = S.lower_bound(g);
            if ((it != S.end()) && (*it > l[v]) && (*it < r[v])) events[*it].pb(v);
            if (it != S.begin()) {
                it--;
                if ((*it > l[v]) && (*it < r[v])) events[*it].pb(v);
            }
        }
    }
    S.clear(),vv[s].pb(0),vv[g].pb(0);
    for (i = 0; i < n; i++) {
        for (j = 0; j < events[i].size(); j++) {
            if (l[events[i][j]] == i) S.insert(y[events[i][j]]);
        }
        for (j = 0; j < events[i].size(); j++) {
            vv[i].pb(y[events[i][j]]);
            auto it = S.lower_bound(y[events[i][j]]);
            if (it != S.begin()) vv[i].pb(*(--it));
        }
        for (j = 0; j < events[i].size(); j++) {
            if (r[events[i][j]] == i) S.erase(S.find(y[events[i][j]]));
        }
        sort(vv[i].begin(),vv[i].end());
        vv[i].resize(unique(vv[i].begin(),vv[i].end())-vv[i].begin());
        for (j = 0; j < vv[i].size(); j++) nodes[i].pb(num++),xx[num-1] = x[i];
        for (j = 1; j < vv[i].size(); j++) {
            adjList[nodes[i][j-1]].pb(mp(nodes[i][j],vv[i][j]-vv[i][j-1]));
            adjList[nodes[i][j]].pb(mp(nodes[i][j-1],vv[i][j]-vv[i][j-1]));
        }
    }
    for (i = 0; i < n; i++) {
        for (j = 0; j < vv[i].size(); j++) {
            if (M.count(vv[i][j])) {
                int v = M[vv[i][j]];
                adjList[v].pb(mp(nodes[i][j],x[i]-xx[v]));
                adjList[nodes[i][j]].pb(mp(v,x[i]-xx[v]));
                M[vv[i][j]] = nodes[i][j];
            }
        }
        for (j = 0; j < events[i].size(); j++) {
            int v = events[i][j];
            if (r[v] == i) M.erase(y[v]);
        }
        for (j = 0; j < events[i].size(); j++) {
            int v = events[i][j];
            if (l[v] == i) M[y[v]] = nodes[i][lower_bound(vv[i].begin(),vv[i].end(),y[v])-vv[i].begin()];
        }
    }
    fill(dist,dist+num,-1);
    dist[nodes[s][0]] = 0,H.push(mp(0,nodes[s][0]));
    while (!H.empty()) {
        int u = H.top().second;
        LLI d = -H.top().first;
        H.pop();

        if (d > dist[u]) continue;
        else if (u == nodes[g][0]) return d;
        for (i = 0; i < adjList[u].size(); i++) {
            int v = adjList[u][i].first;
            if ((dist[v] == -1) || (dist[u]+adjList[u][i].second < dist[v])) {
                dist[v] = dist[u]+adjList[u][i].second;
                H.push(mp(-dist[v],v));
            }
        }
    }
    return -1;
}

Compilation message

walk.cpp: In function 'long long int min_distance(std::vector<int>, std::vector<int>, std::vector<int>, std::vector<int>, std::vector<int>, int, int)':
walk.cpp:72:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (i = 0; i < events2.size(); i++) {
                 ~~^~~~~~~~~~~~~~~~
walk.cpp:92:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for (j = 0; j < events[i].size(); j++) {
                     ~~^~~~~~~~~~~~~~~~~~
walk.cpp:95:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for (j = 0; j < events[i].size(); j++) {
                     ~~^~~~~~~~~~~~~~~~~~
walk.cpp:100:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for (j = 0; j < events[i].size(); j++) {
                     ~~^~~~~~~~~~~~~~~~~~
walk.cpp:105:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for (j = 0; j < vv[i].size(); j++) nodes[i].pb(num++),xx[num-1] = x[i];
                     ~~^~~~~~~~~~~~~~
walk.cpp:106:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for (j = 1; j < vv[i].size(); j++) {
                     ~~^~~~~~~~~~~~~~
walk.cpp:112:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for (j = 0; j < vv[i].size(); j++) {
                     ~~^~~~~~~~~~~~~~
walk.cpp:120:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for (j = 0; j < events[i].size(); j++) {
                     ~~^~~~~~~~~~~~~~~~~~
walk.cpp:124:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for (j = 0; j < events[i].size(); j++) {
                     ~~^~~~~~~~~~~~~~~~~~
walk.cpp:138:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for (i = 0; i < adjList[u].size(); i++) {
                     ~~^~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 25 ms 35584 KB Output is correct
2 Correct 29 ms 35584 KB Output is correct
3 Correct 30 ms 35584 KB Output is correct
4 Correct 25 ms 35584 KB Output is correct
5 Correct 25 ms 35584 KB Output is correct
6 Correct 25 ms 35584 KB Output is correct
7 Correct 25 ms 35584 KB Output is correct
8 Correct 25 ms 35584 KB Output is correct
9 Correct 29 ms 35584 KB Output is correct
10 Correct 30 ms 35584 KB Output is correct
11 Correct 31 ms 35584 KB Output is correct
12 Correct 29 ms 35584 KB Output is correct
13 Correct 25 ms 35584 KB Output is correct
14 Correct 25 ms 35584 KB Output is correct
15 Correct 30 ms 35584 KB Output is correct
16 Correct 25 ms 35584 KB Output is correct
17 Correct 27 ms 35584 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 25 ms 35584 KB Output is correct
2 Correct 30 ms 35584 KB Output is correct
3 Correct 331 ms 66036 KB Output is correct
4 Correct 444 ms 73524 KB Output is correct
5 Correct 336 ms 65036 KB Output is correct
6 Correct 319 ms 63776 KB Output is correct
7 Correct 319 ms 65068 KB Output is correct
8 Correct 372 ms 67216 KB Output is correct
9 Correct 426 ms 69748 KB Output is correct
10 Correct 490 ms 72808 KB Output is correct
11 Correct 324 ms 64492 KB Output is correct
12 Correct 315 ms 60624 KB Output is correct
13 Correct 506 ms 73320 KB Output is correct
14 Correct 368 ms 61160 KB Output is correct
15 Correct 330 ms 62696 KB Output is correct
16 Correct 290 ms 62184 KB Output is correct
17 Correct 281 ms 61672 KB Output is correct
18 Correct 430 ms 62580 KB Output is correct
19 Correct 41 ms 37120 KB Output is correct
20 Correct 155 ms 50668 KB Output is correct
21 Correct 278 ms 59624 KB Output is correct
22 Correct 263 ms 60520 KB Output is correct
23 Correct 497 ms 70376 KB Output is correct
24 Correct 281 ms 61160 KB Output is correct
25 Correct 263 ms 61416 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 111 ms 43888 KB Output is correct
2 Correct 505 ms 70508 KB Output is correct
3 Correct 601 ms 72556 KB Output is correct
4 Correct 735 ms 78412 KB Output is correct
5 Correct 1143 ms 81232 KB Output is correct
6 Correct 972 ms 81104 KB Output is correct
7 Correct 338 ms 60776 KB Output is correct
8 Correct 272 ms 60524 KB Output is correct
9 Correct 996 ms 84472 KB Output is correct
10 Correct 360 ms 62436 KB Output is correct
11 Correct 57 ms 39920 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 111 ms 43888 KB Output is correct
2 Correct 505 ms 70508 KB Output is correct
3 Correct 601 ms 72556 KB Output is correct
4 Correct 735 ms 78412 KB Output is correct
5 Correct 1143 ms 81232 KB Output is correct
6 Correct 972 ms 81104 KB Output is correct
7 Correct 338 ms 60776 KB Output is correct
8 Correct 272 ms 60524 KB Output is correct
9 Correct 996 ms 84472 KB Output is correct
10 Correct 360 ms 62436 KB Output is correct
11 Correct 57 ms 39920 KB Output is correct
12 Correct 605 ms 72452 KB Output is correct
13 Correct 636 ms 77544 KB Output is correct
14 Correct 994 ms 81064 KB Output is correct
15 Correct 581 ms 72404 KB Output is correct
16 Correct 667 ms 73704 KB Output is correct
17 Correct 639 ms 77416 KB Output is correct
18 Correct 589 ms 72400 KB Output is correct
19 Correct 603 ms 73876 KB Output is correct
20 Correct 380 ms 60648 KB Output is correct
21 Correct 112 ms 44248 KB Output is correct
22 Correct 414 ms 69868 KB Output is correct
23 Correct 385 ms 69096 KB Output is correct
24 Correct 348 ms 63336 KB Output is correct
25 Correct 372 ms 66896 KB Output is correct
26 Correct 312 ms 61036 KB Output is correct
27 Correct 1095 ms 81580 KB Output is correct
28 Correct 518 ms 76392 KB Output is correct
29 Correct 1178 ms 80616 KB Output is correct
30 Correct 357 ms 60412 KB Output is correct
31 Correct 986 ms 84092 KB Output is correct
32 Correct 337 ms 60008 KB Output is correct
33 Correct 302 ms 60544 KB Output is correct
34 Correct 394 ms 64488 KB Output is correct
35 Correct 402 ms 64464 KB Output is correct
36 Correct 315 ms 62364 KB Output is correct
37 Correct 246 ms 59216 KB Output is correct
38 Correct 275 ms 60008 KB Output is correct
39 Correct 488 ms 69992 KB Output is correct
40 Correct 281 ms 60648 KB Output is correct
41 Correct 285 ms 61032 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 25 ms 35584 KB Output is correct
2 Correct 29 ms 35584 KB Output is correct
3 Correct 30 ms 35584 KB Output is correct
4 Correct 25 ms 35584 KB Output is correct
5 Correct 25 ms 35584 KB Output is correct
6 Correct 25 ms 35584 KB Output is correct
7 Correct 25 ms 35584 KB Output is correct
8 Correct 25 ms 35584 KB Output is correct
9 Correct 29 ms 35584 KB Output is correct
10 Correct 30 ms 35584 KB Output is correct
11 Correct 31 ms 35584 KB Output is correct
12 Correct 29 ms 35584 KB Output is correct
13 Correct 25 ms 35584 KB Output is correct
14 Correct 25 ms 35584 KB Output is correct
15 Correct 30 ms 35584 KB Output is correct
16 Correct 25 ms 35584 KB Output is correct
17 Correct 27 ms 35584 KB Output is correct
18 Correct 25 ms 35584 KB Output is correct
19 Correct 30 ms 35584 KB Output is correct
20 Correct 331 ms 66036 KB Output is correct
21 Correct 444 ms 73524 KB Output is correct
22 Correct 336 ms 65036 KB Output is correct
23 Correct 319 ms 63776 KB Output is correct
24 Correct 319 ms 65068 KB Output is correct
25 Correct 372 ms 67216 KB Output is correct
26 Correct 426 ms 69748 KB Output is correct
27 Correct 490 ms 72808 KB Output is correct
28 Correct 324 ms 64492 KB Output is correct
29 Correct 315 ms 60624 KB Output is correct
30 Correct 506 ms 73320 KB Output is correct
31 Correct 368 ms 61160 KB Output is correct
32 Correct 330 ms 62696 KB Output is correct
33 Correct 290 ms 62184 KB Output is correct
34 Correct 281 ms 61672 KB Output is correct
35 Correct 430 ms 62580 KB Output is correct
36 Correct 41 ms 37120 KB Output is correct
37 Correct 155 ms 50668 KB Output is correct
38 Correct 278 ms 59624 KB Output is correct
39 Correct 263 ms 60520 KB Output is correct
40 Correct 497 ms 70376 KB Output is correct
41 Correct 281 ms 61160 KB Output is correct
42 Correct 263 ms 61416 KB Output is correct
43 Correct 111 ms 43888 KB Output is correct
44 Correct 505 ms 70508 KB Output is correct
45 Correct 601 ms 72556 KB Output is correct
46 Correct 735 ms 78412 KB Output is correct
47 Correct 1143 ms 81232 KB Output is correct
48 Correct 972 ms 81104 KB Output is correct
49 Correct 338 ms 60776 KB Output is correct
50 Correct 272 ms 60524 KB Output is correct
51 Correct 996 ms 84472 KB Output is correct
52 Correct 360 ms 62436 KB Output is correct
53 Correct 57 ms 39920 KB Output is correct
54 Correct 605 ms 72452 KB Output is correct
55 Correct 636 ms 77544 KB Output is correct
56 Correct 994 ms 81064 KB Output is correct
57 Correct 581 ms 72404 KB Output is correct
58 Correct 667 ms 73704 KB Output is correct
59 Correct 639 ms 77416 KB Output is correct
60 Correct 589 ms 72400 KB Output is correct
61 Correct 603 ms 73876 KB Output is correct
62 Correct 380 ms 60648 KB Output is correct
63 Correct 112 ms 44248 KB Output is correct
64 Correct 414 ms 69868 KB Output is correct
65 Correct 385 ms 69096 KB Output is correct
66 Correct 348 ms 63336 KB Output is correct
67 Correct 372 ms 66896 KB Output is correct
68 Correct 312 ms 61036 KB Output is correct
69 Correct 1095 ms 81580 KB Output is correct
70 Correct 518 ms 76392 KB Output is correct
71 Correct 1178 ms 80616 KB Output is correct
72 Correct 357 ms 60412 KB Output is correct
73 Correct 986 ms 84092 KB Output is correct
74 Correct 337 ms 60008 KB Output is correct
75 Correct 302 ms 60544 KB Output is correct
76 Correct 394 ms 64488 KB Output is correct
77 Correct 402 ms 64464 KB Output is correct
78 Correct 315 ms 62364 KB Output is correct
79 Correct 246 ms 59216 KB Output is correct
80 Correct 275 ms 60008 KB Output is correct
81 Correct 488 ms 69992 KB Output is correct
82 Correct 281 ms 60648 KB Output is correct
83 Correct 285 ms 61032 KB Output is correct
84 Correct 95 ms 42352 KB Output is correct
85 Correct 585 ms 73800 KB Output is correct
86 Correct 1133 ms 92392 KB Output is correct
87 Correct 110 ms 44572 KB Output is correct
88 Correct 148 ms 44652 KB Output is correct
89 Correct 107 ms 44460 KB Output is correct
90 Correct 47 ms 38388 KB Output is correct
91 Correct 26 ms 35712 KB Output is correct
92 Correct 45 ms 37624 KB Output is correct
93 Correct 278 ms 53864 KB Output is correct
94 Correct 126 ms 43860 KB Output is correct
95 Correct 414 ms 70892 KB Output is correct
96 Correct 377 ms 68968 KB Output is correct
97 Correct 321 ms 63080 KB Output is correct
98 Correct 349 ms 66664 KB Output is correct
99 Correct 1218 ms 104368 KB Output is correct
100 Correct 613 ms 77556 KB Output is correct
101 Correct 1091 ms 86248 KB Output is correct
102 Correct 307 ms 60060 KB Output is correct
103 Correct 303 ms 60136 KB Output is correct
104 Correct 303 ms 60008 KB Output is correct
105 Correct 429 ms 63592 KB Output is correct
106 Correct 336 ms 61672 KB Output is correct
107 Correct 415 ms 65256 KB Output is correct
108 Correct 69 ms 39284 KB Output is correct
109 Correct 777 ms 70224 KB Output is correct
110 Correct 539 ms 75752 KB Output is correct
111 Correct 515 ms 74088 KB Output is correct
112 Correct 362 ms 63592 KB Output is correct
113 Correct 328 ms 62696 KB Output is correct