#include<bits/stdc++.h>
using namespace std;
using ll = long long;
int main(){
cin.tie(nullptr)->sync_with_stdio(false);
int n,m,q;
cin >> n >> m >> q;
vector<int> l(m),r(m);
vector<int> cnt(n+2);
for(int i=0;i<m;i++){
cin >> l[i] >> r[i];
cnt[l[i]]++;
cnt[r[i]+1]--;
}
vector<pair<ll,int>> qrs;
vector<ll> ans(q);
for(int i=0;i<q;i++){
ll s;
cin >> s;
qrs.emplace_back(s,i);
}
sort(qrs.rbegin(),qrs.rend());
vector<pair<ll,int>> a;
map<int,pair<int,ll>> mp;
ll t=0;
for(int i=0;i<m;i++){
auto it=mp.lower_bound(l[i]);
if(it!=mp.end()){
int pl=it->second.first;
if(pl<l[i]){
mp[l[i]-1]={pl,it->second.second-it->first+l[i]-1};
}
}
for(;it!=mp.end()&&it->first<=r[i];it=mp.erase(it)){
int cl=max(l[i],it->second.first);
int cr=it->first;
ll pt=it->second.second;
a.emplace_back(t+cr-l[i]-pt,cr-cl+1);
}
if(it!=mp.end()){
int &pl=it->second.first;
int pr=it->first;
int pt=it->second.second;
if(pl<=r[i]){
a.emplace_back(t+pr-l[i]-pt,r[i]-pl+1);
pl=r[i]+1;
}
}
t+=r[i]-l[i]+1;
mp[r[i]]={l[i],t};
}
a.emplace_back(0,0);
sort(a.begin(),a.end());
ll base=0;
for(auto [s,i]:qrs){
while(a.back().first>=s){
base+=a.back().second;
a.pop_back();
}
ans[i]=base;
}
for(auto x:ans){
cout << x << " ";
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
2 ms |
592 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
2 ms |
592 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
54 ms |
9412 KB |
Output is correct |
4 |
Correct |
46 ms |
10500 KB |
Output is correct |
5 |
Incorrect |
117 ms |
22064 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
2 ms |
592 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
2 ms |
592 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |