답안 #852084

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
852084 2023-09-21T08:17:43 Z dosts Osumnjičeni (COCI21_osumnjiceni) C++17
0 / 110
98 ms 42668 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];
		}
	}
	int q;
	cin >> q;
	while (q--) {
		int a,b;
		cin >> a >> b;
		int haha = 0;
		for (int i=24;i>=0;i--) {
			if (dp[a][i] < b) a = dp[a][i],haha+=(1<<i);
		}
		cout << haha+1 << endl;
	} 
}    
                                
signed main() { 
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int t = 1;
    //cin >> t; 
    while (t --> 0) solve();
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 91 ms 40784 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 8 ms 1372 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 8 ms 1372 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 98 ms 42668 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 91 ms 40784 KB Output isn't correct
2 Halted 0 ms 0 KB -