#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <vector>
#include <stack>
#include <deque>
#include <queue>
#include <set>
#include <map>
#include <unordered_map>
#include <bitset>
#include <string>
#define pb push_back
#define sz(V) ((int)(V).size())
#define allv(V) ((V).begin()),((V).end())
#define befv(V) ((V)[(sz(V)-2)])
#define sorv(V) sort(allv(V))
#define revv(V) reverse(allv(V))
#define univ(V) (V).erase(unique(allv(V)),(V).end())
#define clv(V) (V).clear()
#define upmin(a,b) (a)=min((a),(b))
#define upmax(a,b) (a)=max((a),(b))
#define rb(x) ((x)&(-(x)))
#define INF (1100000099)
#define INFLL (1100000000000000099ll)
#define MOD (1000000007)
#define MAXN (100005)
#define MAXM (300005)
#define MAXQ (100005)
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<int, ll> pil;
typedef pair<ll, int> pli;
int uptwo[MAXN] = {1, };
struct SEG {
int *d; int MX;
void init(const int SZ) { MX = uptwo[SZ]; d = new int[MX*2]; fill(d, d+(MX*2), INF); }
void upd(int X, int R) { for(X += MX; X; X /= 2) upmin(d[X], R); }
int get(int S, int E) {
int r = INF; for(S += MX, E += MX; S <= E; S /= 2, E /= 2) {
if(S&1) upmin(r, d[S++]); if(~E&1) upmin(r, d[E--]);
} return r;
}
};
SEG seg[MAXN];
vector<int> VT[MAXN];
int AnsT[MAXM];
int A[MAXM], B[MAXM], X[MAXM], Y[MAXM], P[MAXM];
int XI[MAXM], YI[MAXM];
int QT[MAXQ], QP[MAXQ];
int Ans[MAXQ];
int N, M, Q;
int main() {
for(int i = 1; i < MAXN; i++) uptwo[i] = uptwo[i/2]*2;
scanf("%d%d", &N, &M);
for(int i = 1; i <= M; i++) scanf("%d%d%d%d", &A[i], &B[i], &X[i], &Y[i]);
for(int i = 1; i <= M; i++) { VT[A[i]].pb(X[i]); VT[B[i]].pb(Y[i]); }
for(int i = 1; i <= M; i++) P[i] = i;
sort(P+1, P+M+1, [&](const int& a, const int& b) -> bool {
return Y[a] > Y[b];
});
for(int i = 1; i <= N; i++) { sorv(VT[i]); univ(VT[i]); }
for(int i = 1; i < N; i++) seg[i].init(sz(VT[i]));
for(int i = 1; i <= M; i++) {
XI[i] = (int)(lower_bound(allv(VT[A[i]]), X[i]) - VT[A[i]].begin()) + 1;
YI[i] = (int)(lower_bound(allv(VT[B[i]]), Y[i]) - VT[B[i]].begin()) + 1;
}
for(int ei = 1; ei <= M; ei++) {
const int idx = P[ei];
if(A[idx] == N) continue;
else if(B[idx] == N) {
seg[A[idx]].upd(XI[idx], Y[idx]);
} else {
const int ret = seg[B[idx]].get(YI[idx], sz(VT[B[idx]]));
if(INF <= ret) continue;
seg[A[idx]].upd(XI[idx], ret);
}
}
for(int i = 1; i <= sz(VT[1]); i++) AnsT[i] = seg[1].get(i, i);
for(int i = sz(VT[1])-1; i; i--) upmin(AnsT[i], AnsT[i+1]);
scanf("%d", &Q); for(int i = 1; i <= Q; i++) scanf("%d", &QT[i]);
for(int i = 1; i <= Q; i++) QP[i] = i;
sort(QP+1, QP+Q+1, [&](const int& a, const int& b) -> bool { return QT[a] < QT[b]; });
for(int qi = 1, i = 1; qi <= Q; qi++) {
const int idx = QP[qi];
for(; i <= sz(VT[1]) && AnsT[i] <= QT[idx]; i++);
Ans[idx] = (1 == i) ? -1 : VT[1][i-2];
}
for(int i = 1; i <= Q; i++) printf("%d\n", Ans[i]);
return 0;
}
Compilation message
bus.cpp: In function 'int main()':
bus.cpp:63:23: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d", &N, &M);
^
bus.cpp:64:75: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
for(int i = 1; i <= M; i++) scanf("%d%d%d%d", &A[i], &B[i], &X[i], &Y[i]);
^
bus.cpp:89:17: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d", &Q); for(int i = 1; i <= Q; i++) scanf("%d", &QT[i]);
^
bus.cpp:89:66: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d", &Q); for(int i = 1; i <= Q; i++) scanf("%d", &QT[i]);
^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
16872 KB |
Output is correct |
2 |
Correct |
0 ms |
16872 KB |
Output is correct |
3 |
Correct |
0 ms |
16872 KB |
Output is correct |
4 |
Correct |
0 ms |
16872 KB |
Output is correct |
5 |
Correct |
0 ms |
16872 KB |
Output is correct |
6 |
Correct |
0 ms |
16872 KB |
Output is correct |
7 |
Correct |
0 ms |
16872 KB |
Output is correct |
8 |
Correct |
0 ms |
16872 KB |
Output is correct |
9 |
Correct |
0 ms |
16872 KB |
Output is correct |
10 |
Correct |
0 ms |
16872 KB |
Output is correct |
11 |
Correct |
0 ms |
17004 KB |
Output is correct |
12 |
Correct |
3 ms |
17004 KB |
Output is correct |
13 |
Correct |
0 ms |
17004 KB |
Output is correct |
14 |
Correct |
3 ms |
17004 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
16872 KB |
Output is correct |
2 |
Correct |
56 ms |
16872 KB |
Output is correct |
3 |
Correct |
49 ms |
16872 KB |
Output is correct |
4 |
Correct |
3 ms |
16872 KB |
Output is correct |
5 |
Correct |
6 ms |
16872 KB |
Output is correct |
6 |
Correct |
6 ms |
16872 KB |
Output is correct |
7 |
Correct |
29 ms |
16872 KB |
Output is correct |
8 |
Correct |
0 ms |
16872 KB |
Output is correct |
9 |
Correct |
29 ms |
16872 KB |
Output is correct |
10 |
Correct |
69 ms |
17004 KB |
Output is correct |
11 |
Correct |
39 ms |
17004 KB |
Output is correct |
12 |
Correct |
36 ms |
17004 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
383 ms |
31128 KB |
Output is correct |
2 |
Correct |
449 ms |
31128 KB |
Output is correct |
3 |
Correct |
346 ms |
31128 KB |
Output is correct |
4 |
Correct |
423 ms |
31128 KB |
Output is correct |
5 |
Correct |
446 ms |
31128 KB |
Output is correct |
6 |
Correct |
443 ms |
31152 KB |
Output is correct |
7 |
Correct |
356 ms |
27436 KB |
Output is correct |
8 |
Correct |
356 ms |
30596 KB |
Output is correct |
9 |
Correct |
439 ms |
31028 KB |
Output is correct |
10 |
Correct |
413 ms |
29192 KB |
Output is correct |
11 |
Correct |
446 ms |
29196 KB |
Output is correct |
12 |
Correct |
489 ms |
29316 KB |
Output is correct |
13 |
Correct |
483 ms |
29316 KB |
Output is correct |
14 |
Correct |
436 ms |
29196 KB |
Output is correct |
15 |
Correct |
403 ms |
29316 KB |
Output is correct |
16 |
Correct |
143 ms |
24660 KB |
Output is correct |
17 |
Correct |
113 ms |
24660 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
463 ms |
31128 KB |
Output is correct |
2 |
Correct |
453 ms |
31128 KB |
Output is correct |
3 |
Correct |
509 ms |
31128 KB |
Output is correct |
4 |
Correct |
453 ms |
31128 KB |
Output is correct |
5 |
Correct |
459 ms |
31128 KB |
Output is correct |
6 |
Correct |
376 ms |
31152 KB |
Output is correct |
7 |
Correct |
403 ms |
27436 KB |
Output is correct |
8 |
Correct |
489 ms |
31028 KB |
Output is correct |
9 |
Correct |
486 ms |
31028 KB |
Output is correct |
10 |
Correct |
519 ms |
29192 KB |
Output is correct |
11 |
Correct |
466 ms |
29196 KB |
Output is correct |
12 |
Correct |
456 ms |
29192 KB |
Output is correct |
13 |
Correct |
479 ms |
29316 KB |
Output is correct |
14 |
Correct |
506 ms |
29196 KB |
Output is correct |
15 |
Correct |
456 ms |
29316 KB |
Output is correct |
16 |
Correct |
173 ms |
24660 KB |
Output is correct |