#include <bits/stdc++.h>
using namespace std;
#define ll long long int
int main()
{
cin.tie(0);
ios_base::sync_with_stdio(NULL);
int N,M,S;cin>>N>>M>>S;
vector<pair<int,int>> ta(M);
for (int i=0;i<M;i++) {
cin>>ta[i].first >> ta[i].second;
}
priority_queue<pair<ll,ll>> ss;
vector<ll> ans(S);
for (int i=0;i<S;i++) {
ll t1;
cin>>t1;
ss.push(make_pair(t1,i));
}
priority_queue<pair<ll,ll>> sl;
//right -> {left, time}
map<int,pair<int,ll>> range;
ll tim = 0;
for (int i=0;i<M;i++) {
auto it = range.lower_bound(ta[i].first);
if (it!=range.end()) {
int l = it->second.first;
int r = it->first;
ll tt = it->second.second;
if (l<ta[i].first) {
range[ta[i].first-1] = {l, tt-(r-ta[i].first)-1};
it->second.first = ta[i].first;
}
}
while (it!=range.end() && it->first<=ta[i].second) {
int l = it->second.first;
int r = it->first;
ll tt = it->second.second;
//sl.push(make_pair(tim-ta[i].first+r-tt, r-l+1));
sl.push(make_pair(tim-ta[i].first+r-tt, r-l+1));
it = range.erase(it);
}
if (it!=range.end()) {
int l = it->second.first;
int r = it->first;
ll tt = it->second.second;
if (l<=ta[i].second) {
sl.push(make_pair(tim-ta[i].first+r-tt, ta[i].second-l+1));
it->second.first = ta[i].second+1;
}
}
tim+=ta[i].second-ta[i].first+1;
range[ta[i].second] = make_pair(ta[i].first, tim);
}
ll sum=0;
while (!ss.empty()) {
while (!ss.empty() && !sl.empty() && ss.top().first<=sl.top().first) {
sum+=sl.top().second;
sl.pop();
}
ans[ss.top().second] = sum;
ss.pop();
}
for (int i=0;i<S;i++) {
cout << ans[i] << ' ';
}
return 0;
}
/*
5 3 7
1 3
3 5
2 3
0 1 2 3 4 5 6
*/
# |
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 |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
1 ms |
336 KB |
Output is correct |
6 |
Correct |
1 ms |
336 KB |
Output is correct |
7 |
Correct |
1 ms |
336 KB |
Output is correct |
8 |
Correct |
1 ms |
336 KB |
Output is correct |
9 |
Correct |
1 ms |
336 KB |
Output is correct |
10 |
Correct |
1 ms |
336 KB |
Output is correct |
11 |
Correct |
1 ms |
336 KB |
Output is correct |
12 |
Correct |
1 ms |
336 KB |
Output is correct |
# |
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 |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
1 ms |
336 KB |
Output is correct |
6 |
Correct |
1 ms |
336 KB |
Output is correct |
7 |
Correct |
1 ms |
336 KB |
Output is correct |
8 |
Correct |
1 ms |
336 KB |
Output is correct |
9 |
Correct |
1 ms |
336 KB |
Output is correct |
10 |
Correct |
1 ms |
336 KB |
Output is correct |
11 |
Correct |
1 ms |
336 KB |
Output is correct |
12 |
Correct |
1 ms |
336 KB |
Output is correct |
13 |
Correct |
62 ms |
8132 KB |
Output is correct |
14 |
Correct |
62 ms |
8324 KB |
Output is correct |
15 |
Correct |
55 ms |
8340 KB |
Output is correct |
16 |
Correct |
54 ms |
8336 KB |
Output is correct |
17 |
Correct |
60 ms |
8144 KB |
Output is correct |
18 |
Correct |
53 ms |
8144 KB |
Output is correct |
19 |
Correct |
67 ms |
8144 KB |
Output is correct |
# |
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 |
59 ms |
8164 KB |
Output is correct |
4 |
Correct |
55 ms |
8336 KB |
Output is correct |
5 |
Correct |
156 ms |
17880 KB |
Output is correct |
6 |
Correct |
100 ms |
22240 KB |
Output is correct |
7 |
Correct |
130 ms |
17340 KB |
Output is correct |
8 |
Correct |
1 ms |
336 KB |
Output is correct |
9 |
Correct |
1 ms |
336 KB |
Output is correct |
# |
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 |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
1 ms |
336 KB |
Output is correct |
6 |
Correct |
1 ms |
336 KB |
Output is correct |
7 |
Correct |
1 ms |
336 KB |
Output is correct |
8 |
Correct |
1 ms |
336 KB |
Output is correct |
9 |
Correct |
1 ms |
336 KB |
Output is correct |
10 |
Correct |
1 ms |
336 KB |
Output is correct |
11 |
Correct |
1 ms |
336 KB |
Output is correct |
12 |
Correct |
1 ms |
336 KB |
Output is correct |
13 |
Correct |
62 ms |
8132 KB |
Output is correct |
14 |
Correct |
62 ms |
8324 KB |
Output is correct |
15 |
Correct |
55 ms |
8340 KB |
Output is correct |
16 |
Correct |
54 ms |
8336 KB |
Output is correct |
17 |
Correct |
60 ms |
8144 KB |
Output is correct |
18 |
Correct |
53 ms |
8144 KB |
Output is correct |
19 |
Correct |
67 ms |
8144 KB |
Output is correct |
20 |
Correct |
65 ms |
8132 KB |
Output is correct |
21 |
Correct |
55 ms |
8132 KB |
Output is correct |
22 |
Correct |
63 ms |
8132 KB |
Output is correct |
23 |
Correct |
51 ms |
8132 KB |
Output is correct |
24 |
Correct |
55 ms |
8132 KB |
Output is correct |
25 |
Correct |
58 ms |
8132 KB |
Output is correct |
26 |
Correct |
60 ms |
8144 KB |
Output is correct |
# |
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 |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
1 ms |
336 KB |
Output is correct |
6 |
Correct |
1 ms |
336 KB |
Output is correct |
7 |
Correct |
1 ms |
336 KB |
Output is correct |
8 |
Correct |
1 ms |
336 KB |
Output is correct |
9 |
Correct |
1 ms |
336 KB |
Output is correct |
10 |
Correct |
1 ms |
336 KB |
Output is correct |
11 |
Correct |
1 ms |
336 KB |
Output is correct |
12 |
Correct |
1 ms |
336 KB |
Output is correct |
13 |
Correct |
62 ms |
8132 KB |
Output is correct |
14 |
Correct |
62 ms |
8324 KB |
Output is correct |
15 |
Correct |
55 ms |
8340 KB |
Output is correct |
16 |
Correct |
54 ms |
8336 KB |
Output is correct |
17 |
Correct |
60 ms |
8144 KB |
Output is correct |
18 |
Correct |
53 ms |
8144 KB |
Output is correct |
19 |
Correct |
67 ms |
8144 KB |
Output is correct |
20 |
Correct |
1 ms |
336 KB |
Output is correct |
21 |
Correct |
1 ms |
336 KB |
Output is correct |
22 |
Correct |
59 ms |
8164 KB |
Output is correct |
23 |
Correct |
55 ms |
8336 KB |
Output is correct |
24 |
Correct |
156 ms |
17880 KB |
Output is correct |
25 |
Correct |
100 ms |
22240 KB |
Output is correct |
26 |
Correct |
130 ms |
17340 KB |
Output is correct |
27 |
Correct |
1 ms |
336 KB |
Output is correct |
28 |
Correct |
1 ms |
336 KB |
Output is correct |
29 |
Correct |
65 ms |
8132 KB |
Output is correct |
30 |
Correct |
55 ms |
8132 KB |
Output is correct |
31 |
Correct |
63 ms |
8132 KB |
Output is correct |
32 |
Correct |
51 ms |
8132 KB |
Output is correct |
33 |
Correct |
55 ms |
8132 KB |
Output is correct |
34 |
Correct |
58 ms |
8132 KB |
Output is correct |
35 |
Correct |
60 ms |
8144 KB |
Output is correct |
36 |
Correct |
208 ms |
29764 KB |
Output is correct |
37 |
Correct |
213 ms |
30280 KB |
Output is correct |
38 |
Correct |
140 ms |
31304 KB |
Output is correct |
39 |
Correct |
177 ms |
26056 KB |
Output is correct |
40 |
Correct |
214 ms |
31160 KB |
Output is correct |
41 |
Correct |
216 ms |
36296 KB |
Output is correct |
42 |
Correct |
161 ms |
38856 KB |
Output is correct |
43 |
Correct |
222 ms |
33888 KB |
Output is correct |
44 |
Correct |
196 ms |
33712 KB |
Output is correct |
45 |
Correct |
223 ms |
30524 KB |
Output is correct |
46 |
Correct |
251 ms |
26552 KB |
Output is correct |
47 |
Correct |
210 ms |
27768 KB |
Output is correct |
48 |
Correct |
233 ms |
30792 KB |
Output is correct |