Submission #322331

# Submission time Handle Problem Language Result Execution time Memory
322331 2020-11-14T13:11:43 Z arnold518 Sky Walking (IOI19_walk) C++14
33 / 100
230 ms 27084 KB
#include "walk.h"
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int MAXN = 1e5;
const ll INF = 1e15;

struct Build
{
	int X, H;
};

struct Line
{
	int L, R, Y;
};

int N, M, S, E;
Build A[MAXN+10];
Line B[MAXN+10];

struct Queue
{
	int u; ll w;
	bool operator < (const Queue &p) const
	{
		return w>p.w;
	}
};

struct SEG
{
	int tree[MAXN*4+10];
	void update(int node, int tl, int tr, int l, int r, int k)
	{
		if(tree[node]!=0 && tl!=tr)
		{
			tree[node*2]=tree[node];
			tree[node*2+1]=tree[node];
			tree[node]=0;
		}
		if(l<=tl && tr<=r) { tree[node]=k; return; }
		if(r<tl || tr<l) return;
		int mid=tl+tr>>1;
		update(node*2, tl, mid, l, r, k);
		update(node*2+1, mid+1, tr, l, r, k);
	}
	int query(int node, int tl, int tr, int p)
	{
		if(tree[node]!=0 && tl!=tr)
		{
			tree[node*2]=tree[node];
			tree[node*2+1]=tree[node];
			tree[node]=0;
		}
		if(tl==tr) return tree[node];
		int mid=tl+tr>>1;
		if(p<=mid) return query(node*2, tl, mid, p);
		else return query(node*2+1, mid+1, tr, p);
	}
}seg;

vector<pll> adj[MAXN+10];
ll dist[MAXN+10];

ll min_distance(vector<int> _X, vector<int> _H, vector<int> _L, vector<int> _R, vector<int> _Y, int _S, int _E)
{
	N=_X.size(); M=_L.size();
	for(int i=0; i<N; i++) A[i+1]={_X[i], _H[i]};
	for(int i=0; i<M; i++) B[i+1]={_L[i]+1, _R[i]+1, _Y[i]};
	S=_S+1; E=_E+1;
	
	B[M+1]={S, S, 0};
	B[M+2]={E, E, 0};
	sort(B+1, B+M+3, [&](const Line &p, const Line &q)
	{
		return p.Y<q.Y;
	});

	for(int i=1; i<=M+2; i++)
	{
		int u=seg.query(1, 1, N, B[i].L);
		if(u)
		{
			adj[u].push_back({i, B[i].Y-B[u].Y});
			adj[i].push_back({u, B[i].Y-B[u].Y});
		}
		u=seg.query(1, 1, N, B[i].R);
		if(u)
		{
			adj[u].push_back({i, B[i].Y-B[u].Y});
			adj[i].push_back({u, B[i].Y-B[u].Y});
		}
		seg.update(1, 1, N, B[i].L, B[i].R, i);
	}

	for(int i=1; i<=M+2; i++) dist[i]=INF;
	priority_queue<Queue> PQ;
	PQ.push({1, 0});
	while(!PQ.empty())
	{
		Queue now=PQ.top(); PQ.pop();
		if(dist[now.u]<=now.w) continue;
		dist[now.u]=now.w;

		for(auto nxt : adj[now.u])
		{
			PQ.push({nxt.first, nxt.second+now.w});
		}
	}
	if(dist[2]==INF) return -1;
	return dist[2]+A[N].X-A[1].X;
}

Compilation message

walk.cpp: In member function 'void SEG::update(int, int, int, int, int, int)':
walk.cpp:48:13: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   48 |   int mid=tl+tr>>1;
      |           ~~^~~
walk.cpp: In member function 'int SEG::query(int, int, int, int)':
walk.cpp:61:13: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   61 |   int mid=tl+tr>>1;
      |           ~~^~~
walk.cpp: In function 'll min_distance(std::vector<int>, std::vector<int>, std::vector<int>, std::vector<int>, std::vector<int>, int, int)':
walk.cpp:112:17: warning: narrowing conversion of 'nxt.std::pair<long long int, long long int>::first' from 'long long int' to 'int' [-Wnarrowing]
  112 |    PQ.push({nxt.first, nxt.second+now.w});
      |             ~~~~^~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 2668 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 2668 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 76 ms 10472 KB Output is correct
2 Correct 138 ms 18284 KB Output is correct
3 Correct 187 ms 18924 KB Output is correct
4 Correct 203 ms 23916 KB Output is correct
5 Correct 198 ms 23788 KB Output is correct
6 Correct 190 ms 23916 KB Output is correct
7 Correct 111 ms 16108 KB Output is correct
8 Correct 189 ms 19308 KB Output is correct
9 Correct 179 ms 23916 KB Output is correct
10 Correct 138 ms 19564 KB Output is correct
11 Correct 15 ms 4972 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 76 ms 10472 KB Output is correct
2 Correct 138 ms 18284 KB Output is correct
3 Correct 187 ms 18924 KB Output is correct
4 Correct 203 ms 23916 KB Output is correct
5 Correct 198 ms 23788 KB Output is correct
6 Correct 190 ms 23916 KB Output is correct
7 Correct 111 ms 16108 KB Output is correct
8 Correct 189 ms 19308 KB Output is correct
9 Correct 179 ms 23916 KB Output is correct
10 Correct 138 ms 19564 KB Output is correct
11 Correct 15 ms 4972 KB Output is correct
12 Correct 163 ms 18916 KB Output is correct
13 Correct 201 ms 23788 KB Output is correct
14 Correct 203 ms 23616 KB Output is correct
15 Correct 163 ms 22484 KB Output is correct
16 Correct 206 ms 27084 KB Output is correct
17 Correct 213 ms 25164 KB Output is correct
18 Correct 168 ms 22348 KB Output is correct
19 Correct 167 ms 22848 KB Output is correct
20 Correct 119 ms 15920 KB Output is correct
21 Correct 34 ms 8172 KB Output is correct
22 Correct 151 ms 21356 KB Output is correct
23 Correct 148 ms 21472 KB Output is correct
24 Correct 150 ms 20072 KB Output is correct
25 Correct 149 ms 20588 KB Output is correct
26 Correct 135 ms 18024 KB Output is correct
27 Correct 197 ms 23912 KB Output is correct
28 Correct 230 ms 24168 KB Output is correct
29 Correct 213 ms 23772 KB Output is correct
30 Correct 114 ms 16048 KB Output is correct
31 Correct 206 ms 23900 KB Output is correct
32 Correct 156 ms 18840 KB Output is correct
33 Correct 153 ms 18908 KB Output is correct
34 Correct 127 ms 20328 KB Output is correct
35 Correct 158 ms 19952 KB Output is correct
36 Correct 184 ms 19564 KB Output is correct
37 Correct 167 ms 18216 KB Output is correct
38 Correct 170 ms 18280 KB Output is correct
39 Correct 135 ms 21100 KB Output is correct
40 Correct 162 ms 18688 KB Output is correct
41 Correct 175 ms 18820 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 2668 KB Output isn't correct
2 Halted 0 ms 0 KB -