Submission #852101

# Submission time Handle Problem Language Result Execution time Memory
852101 2023-09-21T08:29:58 Z dosts Osumnjičeni (COCI21_osumnjiceni) C++14
110 / 110
531 ms 60816 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]+1;
				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();
}
# Verdict Execution time Memory Grader output
1 Correct 97 ms 44368 KB Output is correct
2 Correct 90 ms 43856 KB Output is correct
3 Correct 95 ms 44112 KB Output is correct
4 Correct 93 ms 44368 KB Output is correct
5 Correct 98 ms 46416 KB Output is correct
6 Correct 85 ms 42072 KB Output is correct
7 Correct 93 ms 42988 KB Output is correct
8 Correct 91 ms 43348 KB Output is correct
9 Correct 103 ms 44368 KB Output is correct
10 Correct 96 ms 42836 KB Output is correct
11 Correct 220 ms 57264 KB Output is correct
12 Correct 191 ms 53772 KB Output is correct
13 Correct 193 ms 53864 KB Output is correct
14 Correct 185 ms 51968 KB Output is correct
15 Correct 177 ms 48976 KB Output is correct
16 Correct 1 ms 600 KB Output is correct
17 Correct 89 ms 44948 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 1628 KB Output is correct
2 Correct 8 ms 1368 KB Output is correct
3 Correct 8 ms 1372 KB Output is correct
4 Correct 8 ms 1368 KB Output is correct
5 Correct 8 ms 1372 KB Output is correct
6 Correct 8 ms 1628 KB Output is correct
7 Correct 9 ms 1368 KB Output is correct
8 Correct 8 ms 1880 KB Output is correct
9 Correct 9 ms 1372 KB Output is correct
10 Correct 9 ms 1576 KB Output is correct
11 Correct 9 ms 1884 KB Output is correct
12 Correct 9 ms 1628 KB Output is correct
13 Correct 9 ms 1724 KB Output is correct
14 Correct 9 ms 1628 KB Output is correct
15 Correct 9 ms 1624 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 8 ms 1488 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 1628 KB Output is correct
2 Correct 8 ms 1368 KB Output is correct
3 Correct 8 ms 1372 KB Output is correct
4 Correct 8 ms 1368 KB Output is correct
5 Correct 8 ms 1372 KB Output is correct
6 Correct 8 ms 1628 KB Output is correct
7 Correct 9 ms 1368 KB Output is correct
8 Correct 8 ms 1880 KB Output is correct
9 Correct 9 ms 1372 KB Output is correct
10 Correct 9 ms 1576 KB Output is correct
11 Correct 9 ms 1884 KB Output is correct
12 Correct 9 ms 1628 KB Output is correct
13 Correct 9 ms 1724 KB Output is correct
14 Correct 9 ms 1628 KB Output is correct
15 Correct 9 ms 1624 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 8 ms 1488 KB Output is correct
18 Correct 272 ms 4044 KB Output is correct
19 Correct 241 ms 3920 KB Output is correct
20 Correct 268 ms 4184 KB Output is correct
21 Correct 249 ms 3828 KB Output is correct
22 Correct 273 ms 3920 KB Output is correct
23 Correct 261 ms 4004 KB Output is correct
24 Correct 259 ms 4020 KB Output is correct
25 Correct 267 ms 3980 KB Output is correct
26 Correct 259 ms 3948 KB Output is correct
27 Correct 245 ms 4144 KB Output is correct
28 Correct 242 ms 3836 KB Output is correct
29 Correct 244 ms 3904 KB Output is correct
30 Correct 247 ms 3764 KB Output is correct
31 Correct 238 ms 3680 KB Output is correct
32 Correct 229 ms 3760 KB Output is correct
33 Correct 0 ms 512 KB Output is correct
34 Correct 249 ms 3908 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 101 ms 46416 KB Output is correct
2 Correct 93 ms 45596 KB Output is correct
3 Correct 85 ms 42324 KB Output is correct
4 Correct 86 ms 42036 KB Output is correct
5 Correct 88 ms 43344 KB Output is correct
6 Correct 85 ms 42580 KB Output is correct
7 Correct 88 ms 42224 KB Output is correct
8 Correct 89 ms 42464 KB Output is correct
9 Correct 95 ms 42064 KB Output is correct
10 Correct 99 ms 45392 KB Output is correct
11 Correct 195 ms 53260 KB Output is correct
12 Correct 225 ms 58448 KB Output is correct
13 Correct 191 ms 53072 KB Output is correct
14 Correct 182 ms 48732 KB Output is correct
15 Correct 194 ms 52612 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 88 ms 43064 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 97 ms 44368 KB Output is correct
2 Correct 90 ms 43856 KB Output is correct
3 Correct 95 ms 44112 KB Output is correct
4 Correct 93 ms 44368 KB Output is correct
5 Correct 98 ms 46416 KB Output is correct
6 Correct 85 ms 42072 KB Output is correct
7 Correct 93 ms 42988 KB Output is correct
8 Correct 91 ms 43348 KB Output is correct
9 Correct 103 ms 44368 KB Output is correct
10 Correct 96 ms 42836 KB Output is correct
11 Correct 220 ms 57264 KB Output is correct
12 Correct 191 ms 53772 KB Output is correct
13 Correct 193 ms 53864 KB Output is correct
14 Correct 185 ms 51968 KB Output is correct
15 Correct 177 ms 48976 KB Output is correct
16 Correct 1 ms 600 KB Output is correct
17 Correct 89 ms 44948 KB Output is correct
18 Correct 9 ms 1628 KB Output is correct
19 Correct 8 ms 1368 KB Output is correct
20 Correct 8 ms 1372 KB Output is correct
21 Correct 8 ms 1368 KB Output is correct
22 Correct 8 ms 1372 KB Output is correct
23 Correct 8 ms 1628 KB Output is correct
24 Correct 9 ms 1368 KB Output is correct
25 Correct 8 ms 1880 KB Output is correct
26 Correct 9 ms 1372 KB Output is correct
27 Correct 9 ms 1576 KB Output is correct
28 Correct 9 ms 1884 KB Output is correct
29 Correct 9 ms 1628 KB Output is correct
30 Correct 9 ms 1724 KB Output is correct
31 Correct 9 ms 1628 KB Output is correct
32 Correct 9 ms 1624 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
34 Correct 8 ms 1488 KB Output is correct
35 Correct 272 ms 4044 KB Output is correct
36 Correct 241 ms 3920 KB Output is correct
37 Correct 268 ms 4184 KB Output is correct
38 Correct 249 ms 3828 KB Output is correct
39 Correct 273 ms 3920 KB Output is correct
40 Correct 261 ms 4004 KB Output is correct
41 Correct 259 ms 4020 KB Output is correct
42 Correct 267 ms 3980 KB Output is correct
43 Correct 259 ms 3948 KB Output is correct
44 Correct 245 ms 4144 KB Output is correct
45 Correct 242 ms 3836 KB Output is correct
46 Correct 244 ms 3904 KB Output is correct
47 Correct 247 ms 3764 KB Output is correct
48 Correct 238 ms 3680 KB Output is correct
49 Correct 229 ms 3760 KB Output is correct
50 Correct 0 ms 512 KB Output is correct
51 Correct 249 ms 3908 KB Output is correct
52 Correct 101 ms 46416 KB Output is correct
53 Correct 93 ms 45596 KB Output is correct
54 Correct 85 ms 42324 KB Output is correct
55 Correct 86 ms 42036 KB Output is correct
56 Correct 88 ms 43344 KB Output is correct
57 Correct 85 ms 42580 KB Output is correct
58 Correct 88 ms 42224 KB Output is correct
59 Correct 89 ms 42464 KB Output is correct
60 Correct 95 ms 42064 KB Output is correct
61 Correct 99 ms 45392 KB Output is correct
62 Correct 195 ms 53260 KB Output is correct
63 Correct 225 ms 58448 KB Output is correct
64 Correct 191 ms 53072 KB Output is correct
65 Correct 182 ms 48732 KB Output is correct
66 Correct 194 ms 52612 KB Output is correct
67 Correct 0 ms 348 KB Output is correct
68 Correct 88 ms 43064 KB Output is correct
69 Correct 502 ms 46912 KB Output is correct
70 Correct 531 ms 49256 KB Output is correct
71 Correct 509 ms 45528 KB Output is correct
72 Correct 474 ms 47672 KB Output is correct
73 Correct 512 ms 47132 KB Output is correct
74 Correct 510 ms 49636 KB Output is correct
75 Correct 477 ms 46164 KB Output is correct
76 Correct 505 ms 49768 KB Output is correct
77 Correct 435 ms 45988 KB Output is correct
78 Correct 509 ms 46728 KB Output is correct
79 Correct 490 ms 60816 KB Output is correct
80 Correct 437 ms 56244 KB Output is correct
81 Correct 457 ms 55904 KB Output is correct
82 Correct 462 ms 52820 KB Output is correct
83 Correct 413 ms 50256 KB Output is correct
84 Correct 0 ms 344 KB Output is correct
85 Correct 358 ms 46052 KB Output is correct