Submission #529484

# Submission time Handle Problem Language Result Execution time Memory
529484 2022-02-23T04:31:39 Z fhvirus Railway Trip 2 (JOI22_ho_t4) C++17
0 / 100
499 ms 25572 KB
#include <bits/stdc++.h>
using namespace std;
typedef int64_t ll; typedef pair<int, int> pii;
#define pb emplace_back
#define AI(x) begin(x),end(x)
#define ff first
#define ss second
#ifdef OWO
#define debug(args...) LKJ("\033[0;32m[ " + string(#args) + " ]\033[0m", args)
template<class I> void LKJ(I&&x) { cerr << x << endl; }
template<class I, class...T> void LKJ(I&&x, T&&...t) { cerr << x << ", "; LKJ(t...); }
template<class I> void OI(I a, I b) { while (a != b) cerr << *a << ' ', ++a; cerr << endl; }
#else
#define debug(...) 0
#define OI(...) 0
#endif

struct RMQ {
	int n; vector<int> val;
	RMQ() = default;
	void build(int i, int l, int r, const vector<int>& v) {
		if (l == r) {
			val[i] = v[l];
			return;
		}
		int m = (l + r) / 2;
		build(i * 2, l, m, v);
		build(i * 2 + 1, m + 1, r, v);
		val[i] = max(val[i * 2], val[i * 2 + 1]);
	}
	void build(const vector<int>& v) {
		n = v.size();
		val.resize(n * 4);
		build(1, 1, n, v);
	}
	int query(int i, int l, int r, int ql, int qr) {
		if (ql <= l and r <= qr) return val[i];
		int m = (l + r) / 2;
		int ans = 0;
		if (ql <= m) ans = max(ans, query(i * 2, l, m, ql, qr));
		if (m < qr) ans = max(ans, query(i * 2 + 1, m + 1, r, ql, qr));
		return ans;
	}
	int query(int l, int r) {
		return query(1, 1, n, l, r);
	}
};

signed main() {
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

	int N, K; cin >> N >> K;
	int M; cin >> M;
	vector<int> A(M + 1), B(M + 1);
	for (int i = 1; i <= M; ++i)
		cin >> A[i] >> B[i];
	int Q; cin >> Q;
	vector<int> S(Q + 1), T(Q + 1);
	for (int i = 1; i <= Q; ++i)
		cin >> S[i] >> T[i];

	vector<vector<int>> ono(N + 1);
	for (int i = 1; i <= M; ++i) {
		assert(A[i] < B[i]);
		ono[A[i]].pb(B[i]);
		if (A[i] + K <= N)
			ono[A[i] + K].pb(-B[i]); 
	}

	multiset<int> st;
	vector<int> rightmost(N + 1, 0);
	for (int i = 1; i <= N; ++i) {
		for (const int& v: ono[i]) {
			if (v > 0) st.insert(v);
			else {
				auto it = st.find(-v);
				st.erase(it);
			}
		}
		if (!st.empty())
			rightmost[i] = max(i, *rbegin(st));
		else
			rightmost[i] = i;
	}

	int lg = __lg(N) + 1;
	RMQ rmq;
	vector<vector<int>> jmp(lg + 1, vector<int>(N + 1, 0));
	jmp[0] = rightmost;
	for (int l = 1; l <= lg; ++l) {
		rmq.build(jmp[l - 1]);
		for (int i = 1; i <= N; ++i) {
			int rb = jmp[l - 1][i];
			jmp[l][i] = rmq.query(i, rb);
		}
		debug(l);
		OI(AI(jmp[l]));
	}

	for (int i = 1; i <= Q; ++i) {
		int s = S[i], t = T[i];
		if (jmp[lg][s] < t) {
			cout << -1 << '\n';
			continue;
		}
		int ans = 0;
		for (int l = lg; l >= 0; --l)
			if (jmp[l][s] < t) {
				ans += (1 << l);
				s = jmp[l][s];
			}
		cout << ans + 1 << '\n';
	}

	return 0;
}

Compilation message

Main.cpp: In function 'int main()':
Main.cpp:14:20: warning: statement has no effect [-Wunused-value]
   14 | #define debug(...) 0
      |                    ^
Main.cpp:96:3: note: in expansion of macro 'debug'
   96 |   debug(l);
      |   ^~~~~
Main.cpp:15:17: warning: statement has no effect [-Wunused-value]
   15 | #define OI(...) 0
      |                 ^
Main.cpp:97:3: note: in expansion of macro 'OI'
   97 |   OI(AI(jmp[l]));
      |   ^~
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 460 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 460 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 14 ms 6472 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 21 ms 7216 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 467 ms 21008 KB Output is correct
2 Correct 293 ms 16188 KB Output is correct
3 Correct 295 ms 14296 KB Output is correct
4 Correct 304 ms 13116 KB Output is correct
5 Correct 233 ms 12556 KB Output is correct
6 Correct 299 ms 12288 KB Output is correct
7 Correct 356 ms 20676 KB Output is correct
8 Correct 2 ms 332 KB Output is correct
9 Correct 4 ms 588 KB Output is correct
10 Correct 487 ms 21204 KB Output is correct
11 Correct 450 ms 25572 KB Output is correct
12 Correct 474 ms 20868 KB Output is correct
13 Correct 499 ms 25192 KB Output is correct
14 Incorrect 1 ms 332 KB Output isn't correct
15 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 460 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -