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 ar array
#define int long long
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
const int mod = 1e9 + 7;
const int LOG = 20;
const int maxn = 1e5 + 5;
vector<pll> qus;
int bin_search(ll p) {
int l=0, r=qus.size()-1, ans=-1;
while(l <= r) {
int mid = (l + r) / 2;
if(qus[mid].first <= p) ans = mid, l = mid + 1;
else r = mid - 1;
}
return ans;
}
signed main() {
ios_base::sync_with_stdio(false);
cout.tie(0); cin.tie(0);
int n, m, q; cin >> n >> m >> q;
ll day = 1;
vector<int> L(m), R(m);
for(int i=0; i<m; i++) cin >> L[i] >> R[i];
for(int i=0; i<q; i++) {
ll x; cin >> x;
qus.push_back({ x, i });
}
sort(qus.begin(), qus.end());
vector<ll> ans(q), last(n+1);
for(int i=0; i<m; i++) {
for(int j=L[i]; j<=R[i]; j++) {
if(last[j]) {
int p = bin_search(day - last[j] - 1);
if(p > -1) ans[p]++;
}
last[j] = day++;
}
}
for(int i=q-2; i>=0; i--) ans[i] += ans[i+1];
for(int i=0; i<q; i++) qus[i].first = ans[i];
sort(qus.begin(), qus.end(), [&](pll a, pll b) { return a.second < b.second; });
for(auto x : qus) cout << x.first << " ";
return 0;
}
# | 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... |