# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
531821 | Killer2501 | Osumnjičeni (COCI21_osumnjiceni) | C++14 | 344 ms | 42096 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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 (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |