Submission #852064

# Submission time Handle Problem Language Result Execution time Memory
852064 2023-09-21T07:47:37 Z dosts Osumnjičeni (COCI21_osumnjiceni) C++17
0 / 110
101 ms 46508 KB
#include <bits/stdc++.h>
using namespace std;
#define sp << " " << 
#define int long long
#define vi vector<int>
#define pb push_back
#define F(xxx,yyy) for (int xxx=1;xxx<=yyy;xxx++)
const int N = 2e5+1;
const int MOD = 1e9;
 
void solve() {
	int n;
	cin >> n;
	vector<pair<int,int>> rng(n+1);
	for (int i=1;i<=n;i++) cin >> rng[i].first >> rng[i].second;
	set<pair<int,int>> rs;
	auto no_intersections=  [](set<pair<int,int>>& rs,pair<int,int>& q) -> bool {
		if (rs.empty()) return 1;
		auto it = rs.lower_bound({q.first,0});
		if (it != rs.end()) {
			if (it->first <= q.second) return 0;
		}
		if (it == rs.begin()) return 1;
		--it;
		return !(it->second >= q.first);
	};
	int j = 1;	
	int dp[n+1][25];
	for (int i=1;i<=n;i++) {
		while (j<=n && no_intersections(rs,rng[j])) {
			rs.insert(rng[j]);
			j++;
		}
		dp[i][0] = j-1;
		rs.erase(rng[i]);	
	}
	for (int i=1;i<25;i++) {
		for (int j=1;j<=n;j++) {
			dp[j][i] = dp[min(n,dp[j][i-1]+1)][i-1];
		}
	}
	auto upq = [&](int node,int k) {
		for (int i=24;i>=0;i--) {
			if (k&(1<<i)) node = dp[node][i];
		}
		return node;
	};
	int q;
	cin >> q;
	while (q--) {
		int a,b;
		cin >> a >> b;
		int l = 1;
		int r = n;
		while (l<=r) {
			int m = (l+r) >> 1;
			if (upq(a,m) >= b) r = m-1;
			else l = m+1;
		}
		cout << l << endl;
	} 
}    
                                
signed main() { 
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int t = 1;
    //cin >> t; 
    while (t --> 0) solve();
}
# Verdict Execution time Memory Grader output
1 Incorrect 101 ms 44372 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 11 ms 1628 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 11 ms 1628 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 99 ms 46508 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 101 ms 44372 KB Output isn't correct
2 Halted 0 ms 0 KB -