답안 #25558

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
25558 2017-06-23T04:58:44 Z 김현수(#1073) 버스 (JOI14_bus) C++11
0 / 100
376 ms 29124 KB
#include<bits/stdc++.h>
#define X first
#define Y second
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pll;
const ll N = 100005, M = 300005, inf = 1e18;

ll n, m, q;
bool chk[N];

vector<pll> can[N], ans;

struct sexy {
	ll s, e, x, y;
	bool operator < (const sexy &T) const {
		return (y > T.y);
	}
};

vector<sexy> a;

void arrange (vector<pll> &V) {
	vector<pll> X;
	for(auto &T : V) X.push_back(T);
	V.clear();
	sort(X.begin(), X.end());
	reverse(X.begin(), X.end());
	ll mn = inf;
	for(auto &T : X) {
		if(mn > T.Y) V.push_back(T);
		mn = min(mn, T.Y);
	}
	reverse(V.begin(), V.end());
}

ll lb (vector<pll> &V, ll X) {
	auto it = lower_bound(V.begin(), V.end(), (pll){X, 0});
	if(it == V.end()) return inf;
	return it->second;
}

ll ub (vector<pll> &V, ll X) {
	auto it = upper_bound(V.begin(), V.end(), (pll){X, inf});
	if(it == V.begin()) return inf; it--;
	return it->second;
}

int main()
{
	scanf("%lld%lld",&n,&m);
	for(ll i=1;i<=m;i++) {
		ll S, E, X, Y;
		scanf("%lld%lld%lld%lld",&X,&Y,&S,&E);
		a.push_back({S, E, X, Y});
	}
	sort(a.begin(), a.end());
	for(auto &T : a) {
		if(T.y == n) {
			can[T.x].push_back({T.s, T.e});
			continue;
		}
		if(!chk[T.y]) {
			arrange(can[T.y]);
			chk[T.y] = true;
		}
		ll V = lb(can[T.y], T.e);
		can[T.x].push_back({T.s, V});
	}
	arrange(can[1]);
	for(auto &T : can[1]) {
		ans.push_back({T.Y, T.X});
	}
	scanf("%lld",&q);
	while(q--) {
		ll T, V;
		scanf("%lld",&T);
		V = ub(ans, T);
		printf("%lld\n",(V == inf ? -1 : V));
	}
}

Compilation message

bus.cpp: In function 'int main()':
bus.cpp:51:25: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%lld%lld",&n,&m);
                         ^
bus.cpp:54:40: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%lld%lld%lld%lld",&X,&Y,&S,&E);
                                        ^
bus.cpp:74:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%lld",&q);
                  ^
bus.cpp:77:19: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%lld",&T);
                   ^
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 4464 KB Output is correct
2 Correct 0 ms 4464 KB Output is correct
3 Correct 0 ms 4464 KB Output is correct
4 Correct 0 ms 4464 KB Output is correct
5 Correct 0 ms 4464 KB Output is correct
6 Correct 0 ms 4464 KB Output is correct
7 Correct 0 ms 4464 KB Output is correct
8 Correct 0 ms 4464 KB Output is correct
9 Incorrect 0 ms 4464 KB Output isn't correct
10 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 4464 KB Output is correct
2 Correct 39 ms 4464 KB Output is correct
3 Correct 36 ms 4464 KB Output is correct
4 Correct 3 ms 4464 KB Output is correct
5 Correct 3 ms 4464 KB Output is correct
6 Incorrect 3 ms 4464 KB Output isn't correct
7 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 296 ms 29124 KB Output is correct
2 Correct 276 ms 29124 KB Output is correct
3 Correct 273 ms 29124 KB Output is correct
4 Correct 303 ms 29124 KB Output is correct
5 Correct 303 ms 29124 KB Output is correct
6 Correct 269 ms 29124 KB Output is correct
7 Correct 259 ms 29124 KB Output is correct
8 Correct 296 ms 29124 KB Output is correct
9 Correct 256 ms 29124 KB Output is correct
10 Correct 216 ms 29124 KB Output is correct
11 Incorrect 226 ms 29124 KB Output isn't correct
12 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 316 ms 29124 KB Output is correct
2 Correct 299 ms 29124 KB Output is correct
3 Correct 359 ms 29124 KB Output is correct
4 Correct 376 ms 29124 KB Output is correct
5 Correct 256 ms 29124 KB Output is correct
6 Correct 326 ms 29124 KB Output is correct
7 Incorrect 229 ms 29124 KB Output isn't correct
8 Halted 0 ms 0 KB -