# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1237289 | alexandros | Osumnjičeni (COCI21_osumnjiceni) | C++20 | 1095 ms | 1864 KiB |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
bool overlaps(ll l1, ll r1, ll l2, ll r2)
{
return max(l1, l2) <= min(r1, r2);
}
bool hasOverlap(const vector<pair<ll, ll>>& intervals, ll newL, ll newR)
{
for (auto& seg : intervals)
if (overlaps(seg.first, seg.second, newL, newR))
return true;
return false;
}
int main() {
ll n;
scanf("%lld", &n);
vector<bool> new_block(n, false);
vector<pair<ll, ll>> sofar;
sofar.reserve(n);
for (int i = 0; i < n; i++) {
ll L, R;
scanf("%lld %lld", &L, &R);
if (hasOverlap(sofar, L, R)) {
new_block[i] = true;
sofar.clear();
}
sofar.emplace_back(L, R);
}
vector<ll> ps(n+1, 0);
for (int i = 0; i < n; i++) {
ps[i+1] = ps[i] + (new_block[i] ? 1 : 0);
}
ll Q;
scanf("%lld", &Q);
for(int q = 0; q < Q; q++) {
ll l, r;
scanf("%lld %lld", &l, &r);
l--;
r--;
ll ans = 1 + (ps[r+1] - ps[l+1]);
printf("%lld\n", ans);
}
return 0;
}
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... |