# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
238984 |
2020-06-13T21:43:24 Z |
duality |
Sky Walking (IOI19_walk) |
C++14 |
|
1382 ms |
107624 KB |
#define DEBUG 1
#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 |
23 ms |
35584 KB |
Output is correct |
2 |
Correct |
24 ms |
35584 KB |
Output is correct |
3 |
Correct |
23 ms |
35584 KB |
Output is correct |
4 |
Correct |
24 ms |
35584 KB |
Output is correct |
5 |
Correct |
24 ms |
35584 KB |
Output is correct |
6 |
Correct |
26 ms |
35584 KB |
Output is correct |
7 |
Correct |
24 ms |
35584 KB |
Output is correct |
8 |
Correct |
23 ms |
35584 KB |
Output is correct |
9 |
Correct |
23 ms |
35712 KB |
Output is correct |
10 |
Correct |
25 ms |
35584 KB |
Output is correct |
11 |
Correct |
23 ms |
35584 KB |
Output is correct |
12 |
Correct |
27 ms |
35584 KB |
Output is correct |
13 |
Correct |
27 ms |
35584 KB |
Output is correct |
14 |
Correct |
26 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 |
26 ms |
35584 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
31 ms |
35584 KB |
Output is correct |
2 |
Correct |
29 ms |
35584 KB |
Output is correct |
3 |
Correct |
345 ms |
66632 KB |
Output is correct |
4 |
Correct |
507 ms |
76136 KB |
Output is correct |
5 |
Correct |
355 ms |
66920 KB |
Output is correct |
6 |
Correct |
311 ms |
65768 KB |
Output is correct |
7 |
Correct |
308 ms |
67176 KB |
Output is correct |
8 |
Correct |
340 ms |
67820 KB |
Output is correct |
9 |
Correct |
443 ms |
71784 KB |
Output is correct |
10 |
Correct |
475 ms |
75272 KB |
Output is correct |
11 |
Correct |
315 ms |
65640 KB |
Output is correct |
12 |
Correct |
284 ms |
63080 KB |
Output is correct |
13 |
Correct |
530 ms |
76008 KB |
Output is correct |
14 |
Correct |
363 ms |
63464 KB |
Output is correct |
15 |
Correct |
325 ms |
64536 KB |
Output is correct |
16 |
Correct |
283 ms |
63592 KB |
Output is correct |
17 |
Correct |
281 ms |
62696 KB |
Output is correct |
18 |
Correct |
427 ms |
63720 KB |
Output is correct |
19 |
Correct |
37 ms |
37112 KB |
Output is correct |
20 |
Correct |
158 ms |
51028 KB |
Output is correct |
21 |
Correct |
253 ms |
60960 KB |
Output is correct |
22 |
Correct |
286 ms |
62364 KB |
Output is correct |
23 |
Correct |
578 ms |
71784 KB |
Output is correct |
24 |
Correct |
306 ms |
62568 KB |
Output is correct |
25 |
Correct |
327 ms |
62568 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
107 ms |
43888 KB |
Output is correct |
2 |
Correct |
551 ms |
70764 KB |
Output is correct |
3 |
Correct |
595 ms |
72940 KB |
Output is correct |
4 |
Correct |
798 ms |
81068 KB |
Output is correct |
5 |
Correct |
1014 ms |
83816 KB |
Output is correct |
6 |
Correct |
974 ms |
83688 KB |
Output is correct |
7 |
Correct |
338 ms |
62184 KB |
Output is correct |
8 |
Correct |
274 ms |
63208 KB |
Output is correct |
9 |
Correct |
1010 ms |
86900 KB |
Output is correct |
10 |
Correct |
368 ms |
64360 KB |
Output is correct |
11 |
Correct |
57 ms |
39920 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
107 ms |
43888 KB |
Output is correct |
2 |
Correct |
551 ms |
70764 KB |
Output is correct |
3 |
Correct |
595 ms |
72940 KB |
Output is correct |
4 |
Correct |
798 ms |
81068 KB |
Output is correct |
5 |
Correct |
1014 ms |
83816 KB |
Output is correct |
6 |
Correct |
974 ms |
83688 KB |
Output is correct |
7 |
Correct |
338 ms |
62184 KB |
Output is correct |
8 |
Correct |
274 ms |
63208 KB |
Output is correct |
9 |
Correct |
1010 ms |
86900 KB |
Output is correct |
10 |
Correct |
368 ms |
64360 KB |
Output is correct |
11 |
Correct |
57 ms |
39920 KB |
Output is correct |
12 |
Correct |
607 ms |
72964 KB |
Output is correct |
13 |
Correct |
620 ms |
80200 KB |
Output is correct |
14 |
Correct |
1145 ms |
83688 KB |
Output is correct |
15 |
Correct |
644 ms |
74856 KB |
Output is correct |
16 |
Correct |
614 ms |
76776 KB |
Output is correct |
17 |
Correct |
638 ms |
80232 KB |
Output is correct |
18 |
Correct |
677 ms |
74856 KB |
Output is correct |
19 |
Correct |
668 ms |
76392 KB |
Output is correct |
20 |
Correct |
393 ms |
62308 KB |
Output is correct |
21 |
Correct |
113 ms |
44780 KB |
Output is correct |
22 |
Correct |
392 ms |
72168 KB |
Output is correct |
23 |
Correct |
383 ms |
71528 KB |
Output is correct |
24 |
Correct |
317 ms |
65896 KB |
Output is correct |
25 |
Correct |
351 ms |
69352 KB |
Output is correct |
26 |
Correct |
306 ms |
63592 KB |
Output is correct |
27 |
Correct |
1031 ms |
84560 KB |
Output is correct |
28 |
Correct |
551 ms |
79208 KB |
Output is correct |
29 |
Correct |
1008 ms |
83560 KB |
Output is correct |
30 |
Correct |
353 ms |
62156 KB |
Output is correct |
31 |
Correct |
1042 ms |
87164 KB |
Output is correct |
32 |
Correct |
303 ms |
61800 KB |
Output is correct |
33 |
Correct |
316 ms |
62640 KB |
Output is correct |
34 |
Correct |
394 ms |
66552 KB |
Output is correct |
35 |
Correct |
390 ms |
66408 KB |
Output is correct |
36 |
Correct |
319 ms |
64360 KB |
Output is correct |
37 |
Correct |
254 ms |
61004 KB |
Output is correct |
38 |
Correct |
271 ms |
62312 KB |
Output is correct |
39 |
Correct |
482 ms |
71784 KB |
Output is correct |
40 |
Correct |
277 ms |
62704 KB |
Output is correct |
41 |
Correct |
266 ms |
62516 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
23 ms |
35584 KB |
Output is correct |
2 |
Correct |
24 ms |
35584 KB |
Output is correct |
3 |
Correct |
23 ms |
35584 KB |
Output is correct |
4 |
Correct |
24 ms |
35584 KB |
Output is correct |
5 |
Correct |
24 ms |
35584 KB |
Output is correct |
6 |
Correct |
26 ms |
35584 KB |
Output is correct |
7 |
Correct |
24 ms |
35584 KB |
Output is correct |
8 |
Correct |
23 ms |
35584 KB |
Output is correct |
9 |
Correct |
23 ms |
35712 KB |
Output is correct |
10 |
Correct |
25 ms |
35584 KB |
Output is correct |
11 |
Correct |
23 ms |
35584 KB |
Output is correct |
12 |
Correct |
27 ms |
35584 KB |
Output is correct |
13 |
Correct |
27 ms |
35584 KB |
Output is correct |
14 |
Correct |
26 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 |
26 ms |
35584 KB |
Output is correct |
18 |
Correct |
31 ms |
35584 KB |
Output is correct |
19 |
Correct |
29 ms |
35584 KB |
Output is correct |
20 |
Correct |
345 ms |
66632 KB |
Output is correct |
21 |
Correct |
507 ms |
76136 KB |
Output is correct |
22 |
Correct |
355 ms |
66920 KB |
Output is correct |
23 |
Correct |
311 ms |
65768 KB |
Output is correct |
24 |
Correct |
308 ms |
67176 KB |
Output is correct |
25 |
Correct |
340 ms |
67820 KB |
Output is correct |
26 |
Correct |
443 ms |
71784 KB |
Output is correct |
27 |
Correct |
475 ms |
75272 KB |
Output is correct |
28 |
Correct |
315 ms |
65640 KB |
Output is correct |
29 |
Correct |
284 ms |
63080 KB |
Output is correct |
30 |
Correct |
530 ms |
76008 KB |
Output is correct |
31 |
Correct |
363 ms |
63464 KB |
Output is correct |
32 |
Correct |
325 ms |
64536 KB |
Output is correct |
33 |
Correct |
283 ms |
63592 KB |
Output is correct |
34 |
Correct |
281 ms |
62696 KB |
Output is correct |
35 |
Correct |
427 ms |
63720 KB |
Output is correct |
36 |
Correct |
37 ms |
37112 KB |
Output is correct |
37 |
Correct |
158 ms |
51028 KB |
Output is correct |
38 |
Correct |
253 ms |
60960 KB |
Output is correct |
39 |
Correct |
286 ms |
62364 KB |
Output is correct |
40 |
Correct |
578 ms |
71784 KB |
Output is correct |
41 |
Correct |
306 ms |
62568 KB |
Output is correct |
42 |
Correct |
327 ms |
62568 KB |
Output is correct |
43 |
Correct |
107 ms |
43888 KB |
Output is correct |
44 |
Correct |
551 ms |
70764 KB |
Output is correct |
45 |
Correct |
595 ms |
72940 KB |
Output is correct |
46 |
Correct |
798 ms |
81068 KB |
Output is correct |
47 |
Correct |
1014 ms |
83816 KB |
Output is correct |
48 |
Correct |
974 ms |
83688 KB |
Output is correct |
49 |
Correct |
338 ms |
62184 KB |
Output is correct |
50 |
Correct |
274 ms |
63208 KB |
Output is correct |
51 |
Correct |
1010 ms |
86900 KB |
Output is correct |
52 |
Correct |
368 ms |
64360 KB |
Output is correct |
53 |
Correct |
57 ms |
39920 KB |
Output is correct |
54 |
Correct |
607 ms |
72964 KB |
Output is correct |
55 |
Correct |
620 ms |
80200 KB |
Output is correct |
56 |
Correct |
1145 ms |
83688 KB |
Output is correct |
57 |
Correct |
644 ms |
74856 KB |
Output is correct |
58 |
Correct |
614 ms |
76776 KB |
Output is correct |
59 |
Correct |
638 ms |
80232 KB |
Output is correct |
60 |
Correct |
677 ms |
74856 KB |
Output is correct |
61 |
Correct |
668 ms |
76392 KB |
Output is correct |
62 |
Correct |
393 ms |
62308 KB |
Output is correct |
63 |
Correct |
113 ms |
44780 KB |
Output is correct |
64 |
Correct |
392 ms |
72168 KB |
Output is correct |
65 |
Correct |
383 ms |
71528 KB |
Output is correct |
66 |
Correct |
317 ms |
65896 KB |
Output is correct |
67 |
Correct |
351 ms |
69352 KB |
Output is correct |
68 |
Correct |
306 ms |
63592 KB |
Output is correct |
69 |
Correct |
1031 ms |
84560 KB |
Output is correct |
70 |
Correct |
551 ms |
79208 KB |
Output is correct |
71 |
Correct |
1008 ms |
83560 KB |
Output is correct |
72 |
Correct |
353 ms |
62156 KB |
Output is correct |
73 |
Correct |
1042 ms |
87164 KB |
Output is correct |
74 |
Correct |
303 ms |
61800 KB |
Output is correct |
75 |
Correct |
316 ms |
62640 KB |
Output is correct |
76 |
Correct |
394 ms |
66552 KB |
Output is correct |
77 |
Correct |
390 ms |
66408 KB |
Output is correct |
78 |
Correct |
319 ms |
64360 KB |
Output is correct |
79 |
Correct |
254 ms |
61004 KB |
Output is correct |
80 |
Correct |
271 ms |
62312 KB |
Output is correct |
81 |
Correct |
482 ms |
71784 KB |
Output is correct |
82 |
Correct |
277 ms |
62704 KB |
Output is correct |
83 |
Correct |
266 ms |
62516 KB |
Output is correct |
84 |
Correct |
95 ms |
42352 KB |
Output is correct |
85 |
Correct |
586 ms |
74824 KB |
Output is correct |
86 |
Correct |
1130 ms |
95748 KB |
Output is correct |
87 |
Correct |
107 ms |
45804 KB |
Output is correct |
88 |
Correct |
129 ms |
45804 KB |
Output is correct |
89 |
Correct |
109 ms |
45812 KB |
Output is correct |
90 |
Correct |
51 ms |
38400 KB |
Output is correct |
91 |
Correct |
26 ms |
35712 KB |
Output is correct |
92 |
Correct |
46 ms |
37632 KB |
Output is correct |
93 |
Correct |
283 ms |
55528 KB |
Output is correct |
94 |
Correct |
119 ms |
44780 KB |
Output is correct |
95 |
Correct |
437 ms |
73704 KB |
Output is correct |
96 |
Correct |
387 ms |
71912 KB |
Output is correct |
97 |
Correct |
325 ms |
65896 KB |
Output is correct |
98 |
Correct |
349 ms |
69480 KB |
Output is correct |
99 |
Correct |
1382 ms |
107624 KB |
Output is correct |
100 |
Correct |
663 ms |
80616 KB |
Output is correct |
101 |
Correct |
1136 ms |
89832 KB |
Output is correct |
102 |
Correct |
319 ms |
62312 KB |
Output is correct |
103 |
Correct |
341 ms |
62440 KB |
Output is correct |
104 |
Correct |
308 ms |
62568 KB |
Output is correct |
105 |
Correct |
397 ms |
66024 KB |
Output is correct |
106 |
Correct |
347 ms |
64528 KB |
Output is correct |
107 |
Correct |
484 ms |
67564 KB |
Output is correct |
108 |
Correct |
67 ms |
39284 KB |
Output is correct |
109 |
Correct |
726 ms |
73448 KB |
Output is correct |
110 |
Correct |
525 ms |
79336 KB |
Output is correct |
111 |
Correct |
529 ms |
77416 KB |
Output is correct |
112 |
Correct |
362 ms |
66024 KB |
Output is correct |
113 |
Correct |
349 ms |
65000 KB |
Output is correct |