답안 #615919

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
615919 2022-07-31T14:57:05 Z amunduzbaev Sky Walking (IOI19_walk) C++17
24 / 100
737 ms 355420 KB
#include "bits/stdc++.h"
using namespace std;
#include "walk.h"

#ifndef EVAL
#include "grader.cpp"
#endif

#define ar array
typedef long long ll;
const ll inf = 1e18;
const int N = 1e5 + 5;

struct ST{
	vector<ll> tree;
	vector<ar<int, 2>> c;
	int last;
	void add(){
		tree.push_back(inf);
		c.push_back({});
		last++;
	}
	
	ST(){ add(); }
	
	void umin(int i, ll v, int lx = 0, int rx = N, int x = 1){
		if(lx == rx) {
			tree[x] = min(tree[x], v);
			return;
		} int m = (lx + rx) >> 1;
		if(i <= m){
			if(!c[x][0]) c[x][0] = last, add();
			umin(i, v, lx, m, c[x][0]);
		} else {
			if(!c[x][1]) c[x][1] = last, add();
			umin(i, v, m + 1, rx, c[x][1]);
		}
		
		tree[x] = inf;
		if(c[x][0]) tree[x] = min(tree[x], tree[c[x][0]]);
		if(c[x][1]) tree[x] = min(tree[x], tree[c[x][1]]);
	}
	
	ll get(int l, int r, int lx = 0, int rx = N, int x = 1){
		if(lx > r || rx < l) return inf;
		if(lx >= l && rx <= r) return tree[x];
		int m = (lx + rx) >> 1;
		ll res = inf;
		if(c[x][0]) res = min(res, get(l, r, lx, m, c[x][0]));
		if(c[x][1]) res = min(res, get(l, r, m + 1, rx, c[x][1]));
		
		return res;
	}
};

struct ST2{
	ST tree[N << 2];
	
	void umin(int i, int j, ll v, int lx = 0, int rx = N, int x = 1){
		tree[x].umin(j, v);
		if(lx == rx) return;
		int m = (lx + rx) >> 1;
		if(i <= m) umin(i, j, v, lx, m, x << 1);
		else umin(i, j, v, m + 1, rx, x << 1 | 1);
	}
	
	ll get(int l, int r, int l_, int r_, int lx = 0, int rx = N, int x = 1){
		if(lx > r || rx < l) return inf;
		if(lx >= l && rx <= r){
			return tree[x].get(l_, r_);
		}
		
		int m = (lx + rx) >> 1;
		return min(get(l, r, l_, r_, lx, m, x << 1), get(l, r, l_, r_, m + 1, rx, x << 1 | 1));
	}
}add, sub;

vector<ar<int, 2>> edges[N * 11];
ll d[N * 11];

ll min_distance(vector<int> x, vector<int> h, vector<int> l, vector<int> r, vector<int> y, int s, int g) {
	int n = x.size(), q = l.size();
	//~ vector<int> _x(n);
	//~ for(int i=0;i<n;i++){
		//~ _x[i] = x[i];
	//~ }
	
	vector<int> p(q); iota(p.begin(), p.end(), 0);
	sort(p.begin(), p.end(), [&](int i, int j){
		return y[i] > y[j];
	});
	
	vector<int> P(n); iota(P.begin(), P.end(), 0);
	sort(P.begin(), P.end(), [&](int i, int j){
		return h[i] > h[j];
	});
	
	vector<int> last(n, -1), id(n, -1);
	set<int> ss;
	int j = 0, v = 0;
	for(auto i : p){
		while(j < n && h[P[j]] >= y[i]){
			ss.insert(P[j]);
			j++;
		}
		//~ for(auto x : ss) cout<<x<<" ";
		//~ cout<<"\n";
		//~ cout<<l[i]<<" "<<r[i]<<"\n";
		//~ int k = lower_bound(x.begin(), x.end(), l[i]) - x.begin();
		auto it = ss.lower_bound(l[i]);
		int tmp = -1, X = -1;
		while(it != ss.end() && *it <= r[i]){
			int k = *it;
			//~ cout<<k<<" ";
			if(~tmp){
				edges[v].push_back({tmp, x[k] - X});
				edges[tmp].push_back({v, x[k] - X});
			}
			if(~last[k]){
				edges[v].push_back({last[k], y[id[k]] - y[i]});
				edges[last[k]].push_back({v, y[id[k]] - y[i]});
			}
			last[k] = v, id[k] = i;
			tmp = v, X = x[*it];
			v++;
			it++;
		}
		
		//~ cout<<"\n";
	}
	
	for(int i=0;i<n;i++){
		if(~last[i]){
			edges[v].push_back({last[i], y[id[i]]});
			edges[last[i]].push_back({v, y[id[i]]});
			last[i] = v;
			v++;
		}
	}
	
	//~ last[s], last[g]
	if(last[s] == -1 || last[g] == -1) return -1;
	s = last[s], g = last[g];
	memset(d, 15, sizeof d);
	priority_queue<ar<ll, 2>, vector<ar<ll, 2>>, greater<ar<ll, 2>> > pq;
	d[s] = 0; pq.push({0, s});
	while(!pq.empty()){
		auto [D, u] = pq.top(); pq.pop();
		if(D > d[u]) continue;
		for(auto x : edges[u]){
			if(d[x[0]] > d[u] + x[1]){
				d[x[0]] = d[u] + x[1];
				pq.push({d[x[0]], x[0]});
			}
		}
	}
	
	if(d[g] > inf) return -1;
	return d[g];
}
# 결과 실행 시간 메모리 Grader output
1 Correct 98 ms 128664 KB Output is correct
2 Correct 103 ms 128620 KB Output is correct
3 Correct 102 ms 128688 KB Output is correct
4 Correct 97 ms 120068 KB Output is correct
5 Correct 102 ms 128632 KB Output is correct
6 Correct 102 ms 128664 KB Output is correct
7 Correct 104 ms 128608 KB Output is correct
8 Correct 104 ms 128736 KB Output is correct
9 Correct 104 ms 128564 KB Output is correct
10 Correct 100 ms 128628 KB Output is correct
11 Correct 99 ms 128668 KB Output is correct
12 Correct 103 ms 128632 KB Output is correct
13 Correct 107 ms 128588 KB Output is correct
14 Correct 99 ms 128584 KB Output is correct
15 Correct 97 ms 120056 KB Output is correct
16 Correct 97 ms 128636 KB Output is correct
17 Correct 104 ms 128716 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 116 ms 128560 KB Output is correct
2 Correct 104 ms 128588 KB Output is correct
3 Correct 471 ms 167544 KB Output is correct
4 Correct 654 ms 178228 KB Output is correct
5 Correct 412 ms 172380 KB Output is correct
6 Correct 397 ms 168668 KB Output is correct
7 Correct 408 ms 172464 KB Output is correct
8 Correct 556 ms 176900 KB Output is correct
9 Correct 472 ms 171092 KB Output is correct
10 Correct 737 ms 192580 KB Output is correct
11 Correct 396 ms 154676 KB Output is correct
12 Correct 375 ms 153740 KB Output is correct
13 Correct 687 ms 186172 KB Output is correct
14 Correct 272 ms 144140 KB Output is correct
15 Correct 293 ms 153012 KB Output is correct
16 Correct 300 ms 152504 KB Output is correct
17 Correct 295 ms 151496 KB Output is correct
18 Correct 198 ms 148160 KB Output is correct
19 Correct 110 ms 129768 KB Output is correct
20 Correct 167 ms 140672 KB Output is correct
21 Correct 341 ms 150312 KB Output is correct
22 Correct 296 ms 152936 KB Output is correct
23 Correct 292 ms 157180 KB Output is correct
24 Correct 281 ms 152568 KB Output is correct
25 Correct 306 ms 151720 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 159 ms 136628 KB Output is correct
2 Runtime error 442 ms 355420 KB Execution killed with signal 11
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 159 ms 136628 KB Output is correct
2 Runtime error 442 ms 355420 KB Execution killed with signal 11
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 98 ms 128664 KB Output is correct
2 Correct 103 ms 128620 KB Output is correct
3 Correct 102 ms 128688 KB Output is correct
4 Correct 97 ms 120068 KB Output is correct
5 Correct 102 ms 128632 KB Output is correct
6 Correct 102 ms 128664 KB Output is correct
7 Correct 104 ms 128608 KB Output is correct
8 Correct 104 ms 128736 KB Output is correct
9 Correct 104 ms 128564 KB Output is correct
10 Correct 100 ms 128628 KB Output is correct
11 Correct 99 ms 128668 KB Output is correct
12 Correct 103 ms 128632 KB Output is correct
13 Correct 107 ms 128588 KB Output is correct
14 Correct 99 ms 128584 KB Output is correct
15 Correct 97 ms 120056 KB Output is correct
16 Correct 97 ms 128636 KB Output is correct
17 Correct 104 ms 128716 KB Output is correct
18 Correct 116 ms 128560 KB Output is correct
19 Correct 104 ms 128588 KB Output is correct
20 Correct 471 ms 167544 KB Output is correct
21 Correct 654 ms 178228 KB Output is correct
22 Correct 412 ms 172380 KB Output is correct
23 Correct 397 ms 168668 KB Output is correct
24 Correct 408 ms 172464 KB Output is correct
25 Correct 556 ms 176900 KB Output is correct
26 Correct 472 ms 171092 KB Output is correct
27 Correct 737 ms 192580 KB Output is correct
28 Correct 396 ms 154676 KB Output is correct
29 Correct 375 ms 153740 KB Output is correct
30 Correct 687 ms 186172 KB Output is correct
31 Correct 272 ms 144140 KB Output is correct
32 Correct 293 ms 153012 KB Output is correct
33 Correct 300 ms 152504 KB Output is correct
34 Correct 295 ms 151496 KB Output is correct
35 Correct 198 ms 148160 KB Output is correct
36 Correct 110 ms 129768 KB Output is correct
37 Correct 167 ms 140672 KB Output is correct
38 Correct 341 ms 150312 KB Output is correct
39 Correct 296 ms 152936 KB Output is correct
40 Correct 292 ms 157180 KB Output is correct
41 Correct 281 ms 152568 KB Output is correct
42 Correct 306 ms 151720 KB Output is correct
43 Correct 159 ms 136628 KB Output is correct
44 Runtime error 442 ms 355420 KB Execution killed with signal 11
45 Halted 0 ms 0 KB -