#include<iostream>
#include<stack>
#include<map>
#include<vector>
#include<string>
#include<cassert>
#include<unordered_map>
#include <queue>
#include <cstdint>
#include<cstring>
#include<limits.h>
#include<cmath>
#include<set>
#include<algorithm>
#include <iomanip>
#include<numeric>
#include<bitset>
using namespace std;
#define ll long long
#define f first
#define s second
#define pii pair<int,int>
#define ppii pair<int,pii>
#define vi vector<int>
#define pb push_back
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define F(n) for(int i=0;i<n;i++)
#define lb lower_bound
#define ub upper_bound
#define fastio ios::sync_with_stdio(false);cin.tie(NULL);
#pragma GCC optimize ("03,unroll-lopps")
#define int long long
using namespace std;
const int mod=998244353,mxn=2e5+5,inf=1e18,minf=-1e18,lg=30;
//#undef int
int n,k,m,q;
void setIO(string name){
ios_base::sync_with_stdio(0); cin.tie(0);
freopen((name+".in").c_str(),"r",stdin);
freopen((name+".out").c_str(),"w",stdout);
}
set<int>have;
vector<int>add[mxn+10],rem[mxn+10],start[mxn+10];
vector<pii>allgap;
unordered_map<int,vector<int>>gap;
void put(int x,int id){gap[x].pb(id);}
void unput(int x,int id){
if(gap[x].empty())assert(0);
if(id-gap[x].back())allgap.pb({x,id-gap[x].back()});
gap[x].pop_back();
}
int32_t main(){
fastio
cin>>n>>m>>q;
int cnt=0;
for(int i=0;i<m;i++){
int l,r;cin>>l>>r;
add[l].pb(cnt+1-l);
rem[r+1].pb(cnt+1-l);
cnt+=(r-l+1);
}
for(int i=1;i<=n+1;i++){
for(auto j:rem[i]){
auto it=have.find(j);
if(it!=have.begin()&&next(it)!=have.end())put((*next(it))-(*prev(it)),i);
if(it!=have.begin())unput(j-(*prev(it)),i);
if(next(it)!=have.end())unput((*next(it))-j,i);
have.erase(it);
}
for(auto j:add[i]){
auto it=have.insert(j).f;
if(it!=have.begin()&&next(it)!=have.end())unput((*next(it))-(*prev(it)),i);
if(it!=have.begin())put(j-(*prev(it)),i);
if(next(it)!=have.end())put((*next(it))-j,i);
}
}
vector<pii>qry(q);
vector<int>sum(q,0);
for(int i=0;i<q;i++)cin>>qry[i].f,qry[i].s=i;
sort(all(qry));
sort(all(allgap));
int where=allgap.size()-1;
for(int j=q-1;j>=0;j--){
while(where>=0&&allgap[where].f-1>=qry[j].f){
sum[j]+=allgap[where].s;
where--;
}
if(j+1<q)sum[j]+=sum[j+1];
}
vector<int>ans(q,0);
for(int i=0;i<q;i++)ans[qry[i].s]=sum[i];
for(auto i:ans)cout<<i<<" ";
}
/*
for each m we keep start time-l
then add at l and del at r
we can keep gap
when add a gap keep the starting time(posi)
when remove we know how long a gap is present by posi-starting time
we can use this to cal answer
*/
Compilation message
Main.cpp:32:40: warning: bad option '-funroll-lopps' to pragma 'optimize' [-Wpragmas]
32 | #pragma GCC optimize ("03,unroll-lopps")
| ^
Main.cpp:38:23: warning: bad option '-funroll-lopps' to attribute 'optimize' [-Wattributes]
38 | void setIO(string name){
| ^
Main.cpp:47:22: warning: bad option '-funroll-lopps' to attribute 'optimize' [-Wattributes]
47 | void put(int x,int id){gap[x].pb(id);}
| ^
Main.cpp:48:24: warning: bad option '-funroll-lopps' to attribute 'optimize' [-Wattributes]
48 | void unput(int x,int id){
| ^
Main.cpp:53:14: warning: bad option '-funroll-lopps' to attribute 'optimize' [-Wattributes]
53 | int32_t main(){
| ^
Main.cpp: In function 'void setIO(std::string)':
Main.cpp:40:9: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
40 | freopen((name+".in").c_str(),"r",stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:41:9: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
41 | freopen((name+".out").c_str(),"w",stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
14416 KB |
Output is correct |
2 |
Correct |
4 ms |
14416 KB |
Output is correct |
3 |
Correct |
3 ms |
14556 KB |
Output is correct |
4 |
Correct |
5 ms |
14416 KB |
Output is correct |
5 |
Correct |
4 ms |
14428 KB |
Output is correct |
6 |
Correct |
4 ms |
14416 KB |
Output is correct |
7 |
Correct |
5 ms |
14416 KB |
Output is correct |
8 |
Correct |
4 ms |
14416 KB |
Output is correct |
9 |
Correct |
5 ms |
14416 KB |
Output is correct |
10 |
Correct |
4 ms |
14416 KB |
Output is correct |
11 |
Correct |
4 ms |
14416 KB |
Output is correct |
12 |
Correct |
5 ms |
14416 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
14416 KB |
Output is correct |
2 |
Correct |
4 ms |
14416 KB |
Output is correct |
3 |
Correct |
3 ms |
14556 KB |
Output is correct |
4 |
Correct |
5 ms |
14416 KB |
Output is correct |
5 |
Correct |
4 ms |
14428 KB |
Output is correct |
6 |
Correct |
4 ms |
14416 KB |
Output is correct |
7 |
Correct |
5 ms |
14416 KB |
Output is correct |
8 |
Correct |
4 ms |
14416 KB |
Output is correct |
9 |
Correct |
5 ms |
14416 KB |
Output is correct |
10 |
Correct |
4 ms |
14416 KB |
Output is correct |
11 |
Correct |
4 ms |
14416 KB |
Output is correct |
12 |
Correct |
5 ms |
14416 KB |
Output is correct |
13 |
Correct |
53 ms |
21832 KB |
Output is correct |
14 |
Correct |
43 ms |
21252 KB |
Output is correct |
15 |
Correct |
44 ms |
23300 KB |
Output is correct |
16 |
Correct |
42 ms |
21840 KB |
Output is correct |
17 |
Correct |
45 ms |
22600 KB |
Output is correct |
18 |
Correct |
43 ms |
22600 KB |
Output is correct |
19 |
Correct |
45 ms |
22088 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
14416 KB |
Output is correct |
2 |
Correct |
4 ms |
14584 KB |
Output is correct |
3 |
Correct |
43 ms |
22952 KB |
Output is correct |
4 |
Correct |
45 ms |
21836 KB |
Output is correct |
5 |
Correct |
411 ms |
65632 KB |
Output is correct |
6 |
Correct |
365 ms |
61024 KB |
Output is correct |
7 |
Correct |
250 ms |
49356 KB |
Output is correct |
8 |
Correct |
4 ms |
14416 KB |
Output is correct |
9 |
Correct |
4 ms |
14348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
14416 KB |
Output is correct |
2 |
Correct |
4 ms |
14416 KB |
Output is correct |
3 |
Correct |
3 ms |
14556 KB |
Output is correct |
4 |
Correct |
5 ms |
14416 KB |
Output is correct |
5 |
Correct |
4 ms |
14428 KB |
Output is correct |
6 |
Correct |
4 ms |
14416 KB |
Output is correct |
7 |
Correct |
5 ms |
14416 KB |
Output is correct |
8 |
Correct |
4 ms |
14416 KB |
Output is correct |
9 |
Correct |
5 ms |
14416 KB |
Output is correct |
10 |
Correct |
4 ms |
14416 KB |
Output is correct |
11 |
Correct |
4 ms |
14416 KB |
Output is correct |
12 |
Correct |
5 ms |
14416 KB |
Output is correct |
13 |
Correct |
53 ms |
21832 KB |
Output is correct |
14 |
Correct |
43 ms |
21252 KB |
Output is correct |
15 |
Correct |
44 ms |
23300 KB |
Output is correct |
16 |
Correct |
42 ms |
21840 KB |
Output is correct |
17 |
Correct |
45 ms |
22600 KB |
Output is correct |
18 |
Correct |
43 ms |
22600 KB |
Output is correct |
19 |
Correct |
45 ms |
22088 KB |
Output is correct |
20 |
Correct |
47 ms |
24648 KB |
Output is correct |
21 |
Correct |
42 ms |
21832 KB |
Output is correct |
22 |
Correct |
51 ms |
24392 KB |
Output is correct |
23 |
Correct |
42 ms |
21832 KB |
Output is correct |
24 |
Correct |
45 ms |
21472 KB |
Output is correct |
25 |
Correct |
49 ms |
21832 KB |
Output is correct |
26 |
Correct |
57 ms |
23568 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
14416 KB |
Output is correct |
2 |
Correct |
4 ms |
14416 KB |
Output is correct |
3 |
Correct |
3 ms |
14556 KB |
Output is correct |
4 |
Correct |
5 ms |
14416 KB |
Output is correct |
5 |
Correct |
4 ms |
14428 KB |
Output is correct |
6 |
Correct |
4 ms |
14416 KB |
Output is correct |
7 |
Correct |
5 ms |
14416 KB |
Output is correct |
8 |
Correct |
4 ms |
14416 KB |
Output is correct |
9 |
Correct |
5 ms |
14416 KB |
Output is correct |
10 |
Correct |
4 ms |
14416 KB |
Output is correct |
11 |
Correct |
4 ms |
14416 KB |
Output is correct |
12 |
Correct |
5 ms |
14416 KB |
Output is correct |
13 |
Correct |
53 ms |
21832 KB |
Output is correct |
14 |
Correct |
43 ms |
21252 KB |
Output is correct |
15 |
Correct |
44 ms |
23300 KB |
Output is correct |
16 |
Correct |
42 ms |
21840 KB |
Output is correct |
17 |
Correct |
45 ms |
22600 KB |
Output is correct |
18 |
Correct |
43 ms |
22600 KB |
Output is correct |
19 |
Correct |
45 ms |
22088 KB |
Output is correct |
20 |
Correct |
4 ms |
14416 KB |
Output is correct |
21 |
Correct |
4 ms |
14584 KB |
Output is correct |
22 |
Correct |
43 ms |
22952 KB |
Output is correct |
23 |
Correct |
45 ms |
21836 KB |
Output is correct |
24 |
Correct |
411 ms |
65632 KB |
Output is correct |
25 |
Correct |
365 ms |
61024 KB |
Output is correct |
26 |
Correct |
250 ms |
49356 KB |
Output is correct |
27 |
Correct |
4 ms |
14416 KB |
Output is correct |
28 |
Correct |
4 ms |
14348 KB |
Output is correct |
29 |
Correct |
47 ms |
24648 KB |
Output is correct |
30 |
Correct |
42 ms |
21832 KB |
Output is correct |
31 |
Correct |
51 ms |
24392 KB |
Output is correct |
32 |
Correct |
42 ms |
21832 KB |
Output is correct |
33 |
Correct |
45 ms |
21472 KB |
Output is correct |
34 |
Correct |
49 ms |
21832 KB |
Output is correct |
35 |
Correct |
57 ms |
23568 KB |
Output is correct |
36 |
Correct |
524 ms |
61044 KB |
Output is correct |
37 |
Correct |
807 ms |
79320 KB |
Output is correct |
38 |
Correct |
800 ms |
77328 KB |
Output is correct |
39 |
Correct |
180 ms |
40880 KB |
Output is correct |
40 |
Correct |
583 ms |
79060 KB |
Output is correct |
41 |
Correct |
421 ms |
79560 KB |
Output is correct |
42 |
Correct |
418 ms |
79048 KB |
Output is correct |
43 |
Correct |
311 ms |
64724 KB |
Output is correct |
44 |
Correct |
301 ms |
67388 KB |
Output is correct |
45 |
Correct |
505 ms |
79468 KB |
Output is correct |
46 |
Correct |
331 ms |
71952 KB |
Output is correct |
47 |
Correct |
359 ms |
67204 KB |
Output is correct |
48 |
Correct |
731 ms |
80516 KB |
Output is correct |