#include <bits/stdc++.h>
#pragma GCC optimize("O1")
#pragma GCC optimize("O2")
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC target("popcnt")
using namespace std;
const int maxlog = 18;
struct aint
{
vector<int> a;
vector<int> lazy;
void resize(int n)
{
a = lazy = vector<int>(4 * n);
}
void prop(int node, int left, int right)
{
a[node] += lazy[node];
if (left != right)
{
lazy[2 * node] += lazy[node];
lazy[2 * node + 1] += lazy[node];
}
lazy[node] = 0;
}
void update(int node, int left, int right, int st, int dr, int val)
{
prop(node, left, right);
if (right < st || left > dr)
{
return;
}
if (st <= left && dr >= right)
{
lazy[node] += val;
prop(node, left, right);
return;
}
int mid = (left + right) / 2;
update(2 * node, left, mid, st, dr, val);
update(2 * node + 1, mid + 1, right, st, dr, val);
a[node] = a[2 * node] + a[2 * node + 1];
}
int query(int node, int left, int right, int st, int dr)
{
prop(node, left, right);
if (right < st || left > dr)
{
return 0;
}
if (st <= left && dr >= right)
{
return a[node];
}
int mid = (left + right) / 2;
return query(2 * node, left, mid, st, dr) + query(2 * node + 1, mid + 1, right, st, dr);
}
};
int32_t main()
{
cin.tie(nullptr)->sync_with_stdio(false);
int n;
cin >> n;
vector<pair<int, int>> a(n + 1);
vector<int> norm;
for (int i = 1; i <= n; ++i)
{
cin >> a[i].first >> a[i].second;
norm.push_back(a[i].first);
norm.push_back(a[i].second);
}
sort(norm.begin(), norm.end());
map<int, int> qui;
int p = 0;
for (auto i : norm)
{
if (qui.find(i) == qui.end())
{
qui[i] = ++p;
}
}
for (int i = 1; i <= n; ++i)
{
a[i].first = qui[a[i].first];
a[i].second = qui[a[i].second];
}
aint tree;
tree.resize(p);
vector<int> next(n + 2);
next[n + 1] = n + 1;
int p2 = 1;
for (int i = 1; i <= n; ++i)
{
if (i != 1)
{
tree.update(1, 1, p, a[i - 1].first, a[i - 1].second, -1);
}
while (p2 <= n && tree.query(1, 1, p, a[p2].first, a[p2].second) == 0)
{
tree.update(1, 1, p, a[p2].first, a[p2].second, 1);
p2++;
}
next[i] = p2;
}
int jump[maxlog + 1][n + 2];
for (int i = 1; i <= n + 1; ++i)
{
jump[0][i] = next[i];
}
for (int j = 1; j <= maxlog; ++j)
{
for (int i = 1; i <= n + 1; ++i)
{
jump[j][i] = jump[j - 1][jump[j - 1][i]];
}
}
int q;
cin >> q;
while (q--)
{
int st, dr;
cin >> st >> dr;
int ans = 0;
int wh = st;
for (int i = maxlog; i >= 0; --i)
{
if (jump[i][wh] <= dr)
{
wh = jump[i][wh];
ans += (1 << i);
}
}
cout << ans + 1 << '\n';
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1071 ms |
48148 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
22 ms |
1464 KB |
Output is correct |
2 |
Correct |
18 ms |
1492 KB |
Output is correct |
3 |
Correct |
17 ms |
1408 KB |
Output is correct |
4 |
Correct |
16 ms |
1492 KB |
Output is correct |
5 |
Correct |
16 ms |
1452 KB |
Output is correct |
6 |
Correct |
3 ms |
852 KB |
Output is correct |
7 |
Correct |
4 ms |
792 KB |
Output is correct |
8 |
Correct |
4 ms |
724 KB |
Output is correct |
9 |
Correct |
4 ms |
724 KB |
Output is correct |
10 |
Correct |
5 ms |
724 KB |
Output is correct |
11 |
Correct |
10 ms |
1500 KB |
Output is correct |
12 |
Correct |
11 ms |
1492 KB |
Output is correct |
13 |
Correct |
10 ms |
1492 KB |
Output is correct |
14 |
Correct |
12 ms |
1492 KB |
Output is correct |
15 |
Correct |
12 ms |
1460 KB |
Output is correct |
16 |
Correct |
0 ms |
212 KB |
Output is correct |
17 |
Correct |
3 ms |
832 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
22 ms |
1464 KB |
Output is correct |
2 |
Correct |
18 ms |
1492 KB |
Output is correct |
3 |
Correct |
17 ms |
1408 KB |
Output is correct |
4 |
Correct |
16 ms |
1492 KB |
Output is correct |
5 |
Correct |
16 ms |
1452 KB |
Output is correct |
6 |
Correct |
3 ms |
852 KB |
Output is correct |
7 |
Correct |
4 ms |
792 KB |
Output is correct |
8 |
Correct |
4 ms |
724 KB |
Output is correct |
9 |
Correct |
4 ms |
724 KB |
Output is correct |
10 |
Correct |
5 ms |
724 KB |
Output is correct |
11 |
Correct |
10 ms |
1500 KB |
Output is correct |
12 |
Correct |
11 ms |
1492 KB |
Output is correct |
13 |
Correct |
10 ms |
1492 KB |
Output is correct |
14 |
Correct |
12 ms |
1492 KB |
Output is correct |
15 |
Correct |
12 ms |
1460 KB |
Output is correct |
16 |
Correct |
0 ms |
212 KB |
Output is correct |
17 |
Correct |
3 ms |
832 KB |
Output is correct |
18 |
Correct |
77 ms |
2372 KB |
Output is correct |
19 |
Correct |
74 ms |
2196 KB |
Output is correct |
20 |
Correct |
86 ms |
2352 KB |
Output is correct |
21 |
Correct |
81 ms |
2316 KB |
Output is correct |
22 |
Correct |
82 ms |
2220 KB |
Output is correct |
23 |
Correct |
58 ms |
1624 KB |
Output is correct |
24 |
Correct |
65 ms |
1764 KB |
Output is correct |
25 |
Correct |
63 ms |
1536 KB |
Output is correct |
26 |
Correct |
64 ms |
1532 KB |
Output is correct |
27 |
Correct |
58 ms |
1508 KB |
Output is correct |
28 |
Correct |
62 ms |
1792 KB |
Output is correct |
29 |
Correct |
59 ms |
1816 KB |
Output is correct |
30 |
Correct |
52 ms |
1880 KB |
Output is correct |
31 |
Correct |
52 ms |
1776 KB |
Output is correct |
32 |
Correct |
54 ms |
1864 KB |
Output is correct |
33 |
Correct |
0 ms |
212 KB |
Output is correct |
34 |
Correct |
46 ms |
1680 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1088 ms |
50360 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1071 ms |
48148 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |