답안 #844784

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
844784 2023-09-05T23:56:06 Z Quadrilateral Passport (JOI23_passport) C++14
6 / 100
25 ms 5200 KB
#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
#define MAXN 202020
using namespace std;

int N;

struct pass {
	int L, R;
};

vector<pass> passport;
int Q, ans[MAXN];
int queries[MAXN];

void fastIO() {
	ios_base::sync_with_stdio(0); cin.tie(0);
}

void input() {
	cin >> N;
	passport.resize(N + 1);
	for (int i = 1; i <= N; i++)
		cin >> passport[i].L >> passport[i].R;
	cin >> Q;
	for (int i = 1; i <= Q; i++)
		cin >> queries[i];
}

void init() {
	for (int i = 1; i <= N; i++)
		ans[i] = -1;
}

void solve() {
	init();
	int tmp = 1, destinR = passport[1].R, maxR = passport[1].R;
	for (int i = 2; i < N; i++) {
		maxR = max(maxR, passport[i].R);
		if (i == destinR) {
			tmp++;
			destinR = maxR;
			if (destinR == i) {
				tmp = -1;
				break;
			}
		}
	}
	if (destinR != N && maxR != N) tmp = -1;
	else if (destinR != N) tmp++;
	ans[1] = tmp;
}

void output() {
	for (int i = 1; i <= Q; i++)
		cout << ans[queries[i]] << '\n';
}

int main() {
	fastIO();
	input();
	solve();
	output();
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 504 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 25 ms 4948 KB Output is correct
5 Correct 24 ms 4944 KB Output is correct
6 Correct 24 ms 5200 KB Output is correct
7 Correct 21 ms 4444 KB Output is correct
8 Correct 17 ms 3664 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Incorrect 1 ms 344 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Incorrect 1 ms 344 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Incorrect 1 ms 344 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 504 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 25 ms 4948 KB Output is correct
5 Correct 24 ms 4944 KB Output is correct
6 Correct 24 ms 5200 KB Output is correct
7 Correct 21 ms 4444 KB Output is correct
8 Correct 17 ms 3664 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Incorrect 1 ms 344 KB Output isn't correct
11 Halted 0 ms 0 KB -