Submission #932370

# Submission time Handle Problem Language Result Execution time Memory
932370 2024-02-23T08:54:39 Z beepbeepsheep Sky Walking (IOI19_walk) C++17
33 / 100
3364 ms 81088 KB
#include "walk.h"
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define iiii tuple<ll,ll,ll,ll>
const ll maxn=1e5+5;
const ll inf=1e15;
struct node{
	ll s,e,m,val;
	node *l,*r;
	node(ll _s, ll _e){
		s=_s,e=_e,m=(s+e)>>1,val=inf;
		if (s!=e) l=new node(s,m),r=new node(m+1,e);
	}
	void upd(ll x, ll v){
		if (s==e){
			val=v;
			return;
		}
		if (x>m) r->upd(x,v);
		else l->upd(x,v);
		val=min(l->val,r->val);
	}
	ll query(ll x, ll y){
		if (x<=s && e<=y) return val;
		if (x>m) return r->query(x,y);
		if (y<=m) return l->query(x,y);
		return min(l->query(x,y),r->query(x,y));
	}
}*small, *big;
vector<iiii> bridges;
bool cmp(iiii a, iiii b){
	if (get<2>(a)==get<2>(b)) return get<0>(a)>get<0>(b);
	return get<2>(a)<get<2>(b);
}

long long min_distance(std::vector<int> x, std::vector<int> h, std::vector<int> l, std::vector<int> r, std::vector<int> y, int s, int g) {
	ll n=x.size(),m=l.size();
	assert(s==0 && g==n-1);
	small=new node(1,n);
	big=new node(1,n);
	for (int i=0;i<m;i++) bridges.emplace_back(l[i],r[i],y[i],i);
	sort(bridges.begin(),bridges.end(),cmp); //sorted by height
	vector<iiii> queries; //time, off/on, where to toggle, original height
	for (int i=0;i<m;i++){
		ll a,b,c,d;
		tie(a,b,c,d)=bridges[i];
		queries.emplace_back(a,0,i+1,c);
		queries.emplace_back(b,1,i+1,c);
	}
	queries.emplace_back(0,1,0,0);
	sort(queries.begin(),queries.end());
	ll ptr=0;
	small=new node(0,m+5),big=new node(0,m+5);
	small->upd(0,0);
	for (int i=0;i<n-1;i++){
		while (ptr!=queries.size() && get<0>(queries[ptr])<=i){
			ll a,b,c,d;
			tie(a,d,b,c)=queries[ptr];
			cerr<<a<<' '<<b<<' '<<c<<' '<<d<<" queries"<<endl;
			if (d==0){
				ll lo=small->query(0,b-1)+c;
				ll hi=big->query(b+1,m+5)-c;
				ll res=min(lo,hi);
				cerr<<c<<' '<<hi<<' '<<lo<<' '<<res<<endl;
				small->upd(b,res-c); //get dominated
				big->upd(b,res+c); //dominated
			} else{
				small->upd(b,inf);
				big->upd(b,inf); //reset to sentinels
			}
			ptr++;
		}
	}
	ll ans=big->query(0,m+5); //0 is under everything
	if (ans==inf) return -1;
	return ans+x.back()-x.front();
}

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:57:13: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::tuple<long long int, long long int, long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   57 |   while (ptr!=queries.size() && get<0>(queries[ptr])<=i){
      |          ~~~^~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 600 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 348 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1457 ms 23752 KB Output is correct
2 Correct 3083 ms 50004 KB Output is correct
3 Correct 3135 ms 50244 KB Output is correct
4 Correct 3158 ms 75284 KB Output is correct
5 Correct 3207 ms 75332 KB Output is correct
6 Correct 2872 ms 73636 KB Output is correct
7 Correct 1584 ms 51820 KB Output is correct
8 Correct 3122 ms 75932 KB Output is correct
9 Correct 2635 ms 75044 KB Output is correct
10 Correct 2773 ms 73396 KB Output is correct
11 Correct 19 ms 13660 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1457 ms 23752 KB Output is correct
2 Correct 3083 ms 50004 KB Output is correct
3 Correct 3135 ms 50244 KB Output is correct
4 Correct 3158 ms 75284 KB Output is correct
5 Correct 3207 ms 75332 KB Output is correct
6 Correct 2872 ms 73636 KB Output is correct
7 Correct 1584 ms 51820 KB Output is correct
8 Correct 3122 ms 75932 KB Output is correct
9 Correct 2635 ms 75044 KB Output is correct
10 Correct 2773 ms 73396 KB Output is correct
11 Correct 19 ms 13660 KB Output is correct
12 Correct 3157 ms 51336 KB Output is correct
13 Correct 3236 ms 81088 KB Output is correct
14 Correct 3364 ms 78536 KB Output is correct
15 Correct 3206 ms 74364 KB Output is correct
16 Correct 3118 ms 76128 KB Output is correct
17 Correct 3103 ms 74296 KB Output is correct
18 Correct 3031 ms 76584 KB Output is correct
19 Correct 3042 ms 76352 KB Output is correct
20 Correct 1531 ms 50288 KB Output is correct
21 Correct 55 ms 27460 KB Output is correct
22 Correct 2563 ms 68652 KB Output is correct
23 Correct 2693 ms 69728 KB Output is correct
24 Correct 2754 ms 70744 KB Output is correct
25 Correct 2561 ms 69208 KB Output is correct
26 Correct 2717 ms 70944 KB Output is correct
27 Correct 3150 ms 74556 KB Output is correct
28 Correct 3130 ms 76408 KB Output is correct
29 Correct 2893 ms 75076 KB Output is correct
30 Correct 1568 ms 52160 KB Output is correct
31 Correct 2619 ms 74852 KB Output is correct
32 Correct 2967 ms 71960 KB Output is correct
33 Correct 2986 ms 75040 KB Output is correct
34 Correct 2744 ms 75832 KB Output is correct
35 Correct 2965 ms 73744 KB Output is correct
36 Correct 2961 ms 71908 KB Output is correct
37 Correct 2986 ms 68536 KB Output is correct
38 Correct 3004 ms 73772 KB Output is correct
39 Correct 2472 ms 72752 KB Output is correct
40 Correct 2991 ms 74476 KB Output is correct
41 Correct 2933 ms 71028 KB Output is correct
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 600 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -