#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define ull unsigned long long
#define pb push_back
#define pll pair<ll, ll>
#define pii pair<ll, int>
#define fi first
#define se second
using namespace std;
const int N = 2e5+5;
const int M = 250;
const int mod = 1e9+7;
const ll base = 75;
const ll inf = 1e16;
int n, lab[N], t, c[N], h[N], P[N][20], m, a[N], b[N], ans, d[N], k;
vector<int> adj[N];
vector<int> vi;
string s;
bool vis[N];
void add(int& x, int y)
{
x += y;
if(x >= mod)x -= mod;
}
int findp(int u)
{
return lab[u] < 0 ? u : lab[u] = findp(lab[u]);
}
void hop(int u, int v)
{
u = findp(u);
v = findp(v);
if(u == v)return;
if(lab[u] > lab[v])swap(u, v);
lab[u] += lab[v];
lab[v] = u;
}
pii p[N];
void sol()
{
cin >> n;
for(int i = 1; i <= n; i ++)cin >> p[i].fi >> p[i].se;
set<pii> seg;
for(int i = 1, j = 1; i <= n; i ++)
{
while(j <= n)
{
auto it = seg.lower_bound(make_pair(p[j].fi, 0));
if(it != seg.end() && (*it).fi <= p[j].se)break;
if(it != seg.begin())
{
--it;
if((*it).se >= p[j].fi)break;
}
seg.insert(p[j]);
++j;
}
seg.erase(p[i]);
P[i][0] = j;
//cout << i <<" "<<j<<'\n';
}
for(int j = 1; j <= 18; j ++)
{
for(int i = 1; i <= n; i ++)
{
if(P[i][j-1])
P[i][j] = P[P[i][j-1]][j-1];
}
}
cin >> m;
while(m -- > 0)
{
int l, r;
cin >> l >> r;
ans = 1;
for(int j = 18; j >= 0; j --)
{
if(P[l][j] && P[l][j] <= r)
{
ans += (1<<j);
l = P[l][j];
}
}
cout << ans << '\n';
}
}
int main()
{
cin.tie(0);
cout.tie(0);
ios_base::sync_with_stdio(0);
#define task "test"
if(fopen(task".inp", "r"))
{
freopen(task".inp", "r", stdin);
freopen(task".out", "w", stdout);
}
int test = 1;
//cin >> test;
while(test -- > 0)sol();
return 0;
}
/*
1234
21
*/
Compilation message
Main.cpp: In function 'int main()':
Main.cpp:98:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
98 | freopen(task".inp", "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:99:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
99 | freopen(task".out", "w", stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
89 ms |
22908 KB |
Output is correct |
2 |
Correct |
97 ms |
26344 KB |
Output is correct |
3 |
Correct |
83 ms |
26332 KB |
Output is correct |
4 |
Correct |
119 ms |
26568 KB |
Output is correct |
5 |
Correct |
89 ms |
27588 KB |
Output is correct |
6 |
Correct |
80 ms |
25480 KB |
Output is correct |
7 |
Correct |
82 ms |
25916 KB |
Output is correct |
8 |
Correct |
90 ms |
26076 KB |
Output is correct |
9 |
Correct |
95 ms |
26488 KB |
Output is correct |
10 |
Correct |
111 ms |
25760 KB |
Output is correct |
11 |
Correct |
233 ms |
38940 KB |
Output is correct |
12 |
Correct |
213 ms |
36688 KB |
Output is correct |
13 |
Correct |
223 ms |
36676 KB |
Output is correct |
14 |
Correct |
194 ms |
33576 KB |
Output is correct |
15 |
Correct |
179 ms |
31280 KB |
Output is correct |
16 |
Correct |
3 ms |
4940 KB |
Output is correct |
17 |
Correct |
85 ms |
27184 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
5452 KB |
Output is correct |
2 |
Correct |
7 ms |
5540 KB |
Output is correct |
3 |
Correct |
8 ms |
5528 KB |
Output is correct |
4 |
Correct |
7 ms |
5556 KB |
Output is correct |
5 |
Correct |
5 ms |
5580 KB |
Output is correct |
6 |
Correct |
6 ms |
5580 KB |
Output is correct |
7 |
Correct |
6 ms |
5580 KB |
Output is correct |
8 |
Correct |
6 ms |
5580 KB |
Output is correct |
9 |
Correct |
7 ms |
5556 KB |
Output is correct |
10 |
Correct |
6 ms |
5580 KB |
Output is correct |
11 |
Correct |
7 ms |
5824 KB |
Output is correct |
12 |
Correct |
8 ms |
5836 KB |
Output is correct |
13 |
Correct |
9 ms |
5836 KB |
Output is correct |
14 |
Correct |
7 ms |
5660 KB |
Output is correct |
15 |
Correct |
7 ms |
5708 KB |
Output is correct |
16 |
Correct |
3 ms |
5024 KB |
Output is correct |
17 |
Correct |
6 ms |
5580 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
5452 KB |
Output is correct |
2 |
Correct |
7 ms |
5540 KB |
Output is correct |
3 |
Correct |
8 ms |
5528 KB |
Output is correct |
4 |
Correct |
7 ms |
5556 KB |
Output is correct |
5 |
Correct |
5 ms |
5580 KB |
Output is correct |
6 |
Correct |
6 ms |
5580 KB |
Output is correct |
7 |
Correct |
6 ms |
5580 KB |
Output is correct |
8 |
Correct |
6 ms |
5580 KB |
Output is correct |
9 |
Correct |
7 ms |
5556 KB |
Output is correct |
10 |
Correct |
6 ms |
5580 KB |
Output is correct |
11 |
Correct |
7 ms |
5824 KB |
Output is correct |
12 |
Correct |
8 ms |
5836 KB |
Output is correct |
13 |
Correct |
9 ms |
5836 KB |
Output is correct |
14 |
Correct |
7 ms |
5660 KB |
Output is correct |
15 |
Correct |
7 ms |
5708 KB |
Output is correct |
16 |
Correct |
3 ms |
5024 KB |
Output is correct |
17 |
Correct |
6 ms |
5580 KB |
Output is correct |
18 |
Correct |
72 ms |
8228 KB |
Output is correct |
19 |
Correct |
82 ms |
8008 KB |
Output is correct |
20 |
Correct |
90 ms |
8260 KB |
Output is correct |
21 |
Correct |
66 ms |
8004 KB |
Output is correct |
22 |
Correct |
67 ms |
8136 KB |
Output is correct |
23 |
Correct |
72 ms |
8004 KB |
Output is correct |
24 |
Correct |
79 ms |
8108 KB |
Output is correct |
25 |
Correct |
72 ms |
8132 KB |
Output is correct |
26 |
Correct |
68 ms |
8044 KB |
Output is correct |
27 |
Correct |
77 ms |
7884 KB |
Output is correct |
28 |
Correct |
50 ms |
7852 KB |
Output is correct |
29 |
Correct |
50 ms |
7956 KB |
Output is correct |
30 |
Correct |
49 ms |
8004 KB |
Output is correct |
31 |
Correct |
52 ms |
7736 KB |
Output is correct |
32 |
Correct |
65 ms |
7820 KB |
Output is correct |
33 |
Correct |
3 ms |
4940 KB |
Output is correct |
34 |
Correct |
58 ms |
7876 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
87 ms |
23776 KB |
Output is correct |
2 |
Correct |
90 ms |
27100 KB |
Output is correct |
3 |
Correct |
85 ms |
25540 KB |
Output is correct |
4 |
Correct |
79 ms |
25396 KB |
Output is correct |
5 |
Correct |
87 ms |
26048 KB |
Output is correct |
6 |
Correct |
74 ms |
25708 KB |
Output is correct |
7 |
Correct |
92 ms |
25428 KB |
Output is correct |
8 |
Correct |
101 ms |
25644 KB |
Output is correct |
9 |
Correct |
81 ms |
25412 KB |
Output is correct |
10 |
Correct |
94 ms |
27028 KB |
Output is correct |
11 |
Correct |
209 ms |
36520 KB |
Output is correct |
12 |
Correct |
283 ms |
39540 KB |
Output is correct |
13 |
Correct |
238 ms |
36480 KB |
Output is correct |
14 |
Correct |
174 ms |
31332 KB |
Output is correct |
15 |
Correct |
233 ms |
33888 KB |
Output is correct |
16 |
Correct |
3 ms |
4940 KB |
Output is correct |
17 |
Correct |
72 ms |
26032 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
89 ms |
22908 KB |
Output is correct |
2 |
Correct |
97 ms |
26344 KB |
Output is correct |
3 |
Correct |
83 ms |
26332 KB |
Output is correct |
4 |
Correct |
119 ms |
26568 KB |
Output is correct |
5 |
Correct |
89 ms |
27588 KB |
Output is correct |
6 |
Correct |
80 ms |
25480 KB |
Output is correct |
7 |
Correct |
82 ms |
25916 KB |
Output is correct |
8 |
Correct |
90 ms |
26076 KB |
Output is correct |
9 |
Correct |
95 ms |
26488 KB |
Output is correct |
10 |
Correct |
111 ms |
25760 KB |
Output is correct |
11 |
Correct |
233 ms |
38940 KB |
Output is correct |
12 |
Correct |
213 ms |
36688 KB |
Output is correct |
13 |
Correct |
223 ms |
36676 KB |
Output is correct |
14 |
Correct |
194 ms |
33576 KB |
Output is correct |
15 |
Correct |
179 ms |
31280 KB |
Output is correct |
16 |
Correct |
3 ms |
4940 KB |
Output is correct |
17 |
Correct |
85 ms |
27184 KB |
Output is correct |
18 |
Correct |
6 ms |
5452 KB |
Output is correct |
19 |
Correct |
7 ms |
5540 KB |
Output is correct |
20 |
Correct |
8 ms |
5528 KB |
Output is correct |
21 |
Correct |
7 ms |
5556 KB |
Output is correct |
22 |
Correct |
5 ms |
5580 KB |
Output is correct |
23 |
Correct |
6 ms |
5580 KB |
Output is correct |
24 |
Correct |
6 ms |
5580 KB |
Output is correct |
25 |
Correct |
6 ms |
5580 KB |
Output is correct |
26 |
Correct |
7 ms |
5556 KB |
Output is correct |
27 |
Correct |
6 ms |
5580 KB |
Output is correct |
28 |
Correct |
7 ms |
5824 KB |
Output is correct |
29 |
Correct |
8 ms |
5836 KB |
Output is correct |
30 |
Correct |
9 ms |
5836 KB |
Output is correct |
31 |
Correct |
7 ms |
5660 KB |
Output is correct |
32 |
Correct |
7 ms |
5708 KB |
Output is correct |
33 |
Correct |
3 ms |
5024 KB |
Output is correct |
34 |
Correct |
6 ms |
5580 KB |
Output is correct |
35 |
Correct |
72 ms |
8228 KB |
Output is correct |
36 |
Correct |
82 ms |
8008 KB |
Output is correct |
37 |
Correct |
90 ms |
8260 KB |
Output is correct |
38 |
Correct |
66 ms |
8004 KB |
Output is correct |
39 |
Correct |
67 ms |
8136 KB |
Output is correct |
40 |
Correct |
72 ms |
8004 KB |
Output is correct |
41 |
Correct |
79 ms |
8108 KB |
Output is correct |
42 |
Correct |
72 ms |
8132 KB |
Output is correct |
43 |
Correct |
68 ms |
8044 KB |
Output is correct |
44 |
Correct |
77 ms |
7884 KB |
Output is correct |
45 |
Correct |
50 ms |
7852 KB |
Output is correct |
46 |
Correct |
50 ms |
7956 KB |
Output is correct |
47 |
Correct |
49 ms |
8004 KB |
Output is correct |
48 |
Correct |
52 ms |
7736 KB |
Output is correct |
49 |
Correct |
65 ms |
7820 KB |
Output is correct |
50 |
Correct |
3 ms |
4940 KB |
Output is correct |
51 |
Correct |
58 ms |
7876 KB |
Output is correct |
52 |
Correct |
87 ms |
23776 KB |
Output is correct |
53 |
Correct |
90 ms |
27100 KB |
Output is correct |
54 |
Correct |
85 ms |
25540 KB |
Output is correct |
55 |
Correct |
79 ms |
25396 KB |
Output is correct |
56 |
Correct |
87 ms |
26048 KB |
Output is correct |
57 |
Correct |
74 ms |
25708 KB |
Output is correct |
58 |
Correct |
92 ms |
25428 KB |
Output is correct |
59 |
Correct |
101 ms |
25644 KB |
Output is correct |
60 |
Correct |
81 ms |
25412 KB |
Output is correct |
61 |
Correct |
94 ms |
27028 KB |
Output is correct |
62 |
Correct |
209 ms |
36520 KB |
Output is correct |
63 |
Correct |
283 ms |
39540 KB |
Output is correct |
64 |
Correct |
238 ms |
36480 KB |
Output is correct |
65 |
Correct |
174 ms |
31332 KB |
Output is correct |
66 |
Correct |
233 ms |
33888 KB |
Output is correct |
67 |
Correct |
3 ms |
4940 KB |
Output is correct |
68 |
Correct |
72 ms |
26032 KB |
Output is correct |
69 |
Correct |
251 ms |
29508 KB |
Output is correct |
70 |
Correct |
261 ms |
30916 KB |
Output is correct |
71 |
Correct |
280 ms |
28864 KB |
Output is correct |
72 |
Correct |
246 ms |
30280 KB |
Output is correct |
73 |
Correct |
317 ms |
29712 KB |
Output is correct |
74 |
Correct |
299 ms |
31028 KB |
Output is correct |
75 |
Correct |
261 ms |
29220 KB |
Output is correct |
76 |
Correct |
265 ms |
31100 KB |
Output is correct |
77 |
Correct |
284 ms |
29016 KB |
Output is correct |
78 |
Correct |
239 ms |
29468 KB |
Output is correct |
79 |
Correct |
344 ms |
42096 KB |
Output is correct |
80 |
Correct |
272 ms |
39460 KB |
Output is correct |
81 |
Correct |
293 ms |
39236 KB |
Output is correct |
82 |
Correct |
273 ms |
34540 KB |
Output is correct |
83 |
Correct |
227 ms |
33388 KB |
Output is correct |
84 |
Correct |
3 ms |
4940 KB |
Output is correct |
85 |
Correct |
176 ms |
29140 KB |
Output is correct |