Submission #852039

# Submission time Handle Problem Language Result Execution time Memory
852039 2023-09-21T07:12:08 Z dosts Osumnjičeni (COCI21_osumnjiceni) C++14
0 / 110
98 ms 44032 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;
	int go[n+1];
	set<pair<int,int>> rs;
	
	auto no_intersections=  [](set<pair<int,int>>& rs,pair<int,int>& q) {
		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;
		if (it->second >= q.first) return 0;
		return 1; 
	};
	int j = 1;	
	for (int i=1;i<=n;i++) {
		while (j<=n && no_intersections(rs,rng[j])) {
			rs.insert(rng[j]);
			j++;
		}
		go[i] = j-1;
		rs.erase(rng[i]);	
	}
	int dp[n+1][25];
	for (int i=1;i<=n;i++) dp[i][0] = go[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 97 ms 42304 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 11 ms 1544 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 11 ms 1544 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 98 ms 44032 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 97 ms 42304 KB Output isn't correct
2 Halted 0 ms 0 KB -