Submission #615929

# Submission time Handle Problem Language Result Execution time Memory
615929 2022-07-31T15:15:06 Z amunduzbaev Sky Walking (IOI19_walk) C++17
33 / 100
3949 ms 886028 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 = 2e18;
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 = 0){
		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 = 0){
		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];

#define sow cout<<"here"<<endl;

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> p(q); iota(p.begin(), p.end(), 0);
	sort(p.begin(), p.end(), [&](int i, int j){
		return r[i] < r[j];
	});
	
	vector<int> tot;
	vector<ll> dp(q, inf);
	for(int i=0;i<q;i++){
		tot.push_back(y[i]);
	}
	
	sort(tot.begin(), tot.end());
	tot.erase(unique(tot.begin(), tot.end()), tot.end());
	ll res = inf;
	sub.umin(0, 0, 0);
	add.umin(0, 0, 0);
	for(auto i : p){
		int j = lower_bound(tot.begin(), tot.end(), y[i]) - tot.begin() + 1;
		dp[i] = min(dp[i], sub.get(l[i], r[i], 0, j) + y[i]);
		dp[i] = min(dp[i], add.get(l[i], r[i], j, q) - y[i]);
		sub.umin(r[i], j, dp[i] - y[i]);
		add.umin(r[i], j, dp[i] + y[i]);
		if(r[i] == n - 1) res = min(res, dp[i] + y[i]);
	}
	
	res += (x[n - 1] - x[0]);
	if(res < 1e18){
		return res;
	} else {
		return -1;
	}
}
# Verdict Execution time Memory Grader output
1 Incorrect 120 ms 120144 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 112 ms 119988 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 463 ms 141800 KB Output is correct
2 Correct 3031 ms 453628 KB Output is correct
3 Correct 3042 ms 625500 KB Output is correct
4 Correct 2998 ms 861844 KB Output is correct
5 Correct 3059 ms 744668 KB Output is correct
6 Correct 3949 ms 741288 KB Output is correct
7 Correct 1227 ms 514940 KB Output is correct
8 Correct 2270 ms 886028 KB Output is correct
9 Correct 3791 ms 608896 KB Output is correct
10 Correct 1816 ms 289164 KB Output is correct
11 Correct 126 ms 122700 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 463 ms 141800 KB Output is correct
2 Correct 3031 ms 453628 KB Output is correct
3 Correct 3042 ms 625500 KB Output is correct
4 Correct 2998 ms 861844 KB Output is correct
5 Correct 3059 ms 744668 KB Output is correct
6 Correct 3949 ms 741288 KB Output is correct
7 Correct 1227 ms 514940 KB Output is correct
8 Correct 2270 ms 886028 KB Output is correct
9 Correct 3791 ms 608896 KB Output is correct
10 Correct 1816 ms 289164 KB Output is correct
11 Correct 126 ms 122700 KB Output is correct
12 Correct 2989 ms 621044 KB Output is correct
13 Correct 3109 ms 855952 KB Output is correct
14 Correct 3056 ms 740576 KB Output is correct
15 Correct 1945 ms 559380 KB Output is correct
16 Correct 1812 ms 477156 KB Output is correct
17 Correct 1851 ms 501416 KB Output is correct
18 Correct 1845 ms 559356 KB Output is correct
19 Correct 1803 ms 476896 KB Output is correct
20 Correct 1486 ms 493636 KB Output is correct
21 Correct 198 ms 128264 KB Output is correct
22 Correct 1649 ms 567944 KB Output is correct
23 Correct 1599 ms 613372 KB Output is correct
24 Correct 1768 ms 619688 KB Output is correct
25 Correct 1746 ms 674968 KB Output is correct
26 Correct 1618 ms 577444 KB Output is correct
27 Correct 3376 ms 751688 KB Output is correct
28 Correct 2371 ms 861012 KB Output is correct
29 Correct 3667 ms 734144 KB Output is correct
30 Correct 1150 ms 512940 KB Output is correct
31 Correct 3640 ms 607272 KB Output is correct
32 Correct 1266 ms 320092 KB Output is correct
33 Correct 1296 ms 332324 KB Output is correct
34 Correct 1847 ms 368884 KB Output is correct
35 Correct 1408 ms 426512 KB Output is correct
36 Correct 1310 ms 458596 KB Output is correct
37 Correct 1014 ms 274612 KB Output is correct
38 Correct 1086 ms 324216 KB Output is correct
39 Correct 2472 ms 388288 KB Output is correct
40 Correct 1115 ms 335156 KB Output is correct
41 Correct 1061 ms 299452 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 120 ms 120144 KB Output isn't correct
2 Halted 0 ms 0 KB -