#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;
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);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
14416 KB |
Output is correct |
2 |
Correct |
4 ms |
14416 KB |
Output is correct |
3 |
Correct |
4 ms |
14416 KB |
Output is correct |
4 |
Correct |
4 ms |
14416 KB |
Output is correct |
5 |
Correct |
4 ms |
14416 KB |
Output is correct |
6 |
Correct |
3 ms |
14416 KB |
Output is correct |
7 |
Correct |
5 ms |
14608 KB |
Output is correct |
8 |
Correct |
4 ms |
14416 KB |
Output is correct |
9 |
Correct |
4 ms |
14416 KB |
Output is correct |
10 |
Correct |
4 ms |
14476 KB |
Output is correct |
11 |
Correct |
4 ms |
14584 KB |
Output is correct |
12 |
Correct |
4 ms |
14416 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
14416 KB |
Output is correct |
2 |
Correct |
4 ms |
14416 KB |
Output is correct |
3 |
Correct |
4 ms |
14416 KB |
Output is correct |
4 |
Correct |
4 ms |
14416 KB |
Output is correct |
5 |
Correct |
4 ms |
14416 KB |
Output is correct |
6 |
Correct |
3 ms |
14416 KB |
Output is correct |
7 |
Correct |
5 ms |
14608 KB |
Output is correct |
8 |
Correct |
4 ms |
14416 KB |
Output is correct |
9 |
Correct |
4 ms |
14416 KB |
Output is correct |
10 |
Correct |
4 ms |
14476 KB |
Output is correct |
11 |
Correct |
4 ms |
14584 KB |
Output is correct |
12 |
Correct |
4 ms |
14416 KB |
Output is correct |
13 |
Correct |
49 ms |
23116 KB |
Output is correct |
14 |
Correct |
41 ms |
22680 KB |
Output is correct |
15 |
Correct |
44 ms |
23368 KB |
Output is correct |
16 |
Correct |
47 ms |
23368 KB |
Output is correct |
17 |
Correct |
47 ms |
23112 KB |
Output is correct |
18 |
Correct |
51 ms |
23204 KB |
Output is correct |
19 |
Correct |
49 ms |
23348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
14416 KB |
Output is correct |
2 |
Correct |
4 ms |
14600 KB |
Output is correct |
3 |
Correct |
46 ms |
21576 KB |
Output is correct |
4 |
Correct |
54 ms |
22096 KB |
Output is correct |
5 |
Correct |
925 ms |
71908 KB |
Output is correct |
6 |
Correct |
833 ms |
70612 KB |
Output is correct |
7 |
Correct |
571 ms |
54960 KB |
Output is correct |
8 |
Correct |
4 ms |
14416 KB |
Output is correct |
9 |
Correct |
4 ms |
14416 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
14416 KB |
Output is correct |
2 |
Correct |
4 ms |
14416 KB |
Output is correct |
3 |
Correct |
4 ms |
14416 KB |
Output is correct |
4 |
Correct |
4 ms |
14416 KB |
Output is correct |
5 |
Correct |
4 ms |
14416 KB |
Output is correct |
6 |
Correct |
3 ms |
14416 KB |
Output is correct |
7 |
Correct |
5 ms |
14608 KB |
Output is correct |
8 |
Correct |
4 ms |
14416 KB |
Output is correct |
9 |
Correct |
4 ms |
14416 KB |
Output is correct |
10 |
Correct |
4 ms |
14476 KB |
Output is correct |
11 |
Correct |
4 ms |
14584 KB |
Output is correct |
12 |
Correct |
4 ms |
14416 KB |
Output is correct |
13 |
Correct |
49 ms |
23116 KB |
Output is correct |
14 |
Correct |
41 ms |
22680 KB |
Output is correct |
15 |
Correct |
44 ms |
23368 KB |
Output is correct |
16 |
Correct |
47 ms |
23368 KB |
Output is correct |
17 |
Correct |
47 ms |
23112 KB |
Output is correct |
18 |
Correct |
51 ms |
23204 KB |
Output is correct |
19 |
Correct |
49 ms |
23348 KB |
Output is correct |
20 |
Correct |
54 ms |
24648 KB |
Output is correct |
21 |
Correct |
50 ms |
23368 KB |
Output is correct |
22 |
Correct |
54 ms |
24508 KB |
Output is correct |
23 |
Correct |
50 ms |
23368 KB |
Output is correct |
24 |
Correct |
45 ms |
22856 KB |
Output is correct |
25 |
Correct |
56 ms |
23880 KB |
Output is correct |
26 |
Correct |
50 ms |
24508 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
14416 KB |
Output is correct |
2 |
Correct |
4 ms |
14416 KB |
Output is correct |
3 |
Correct |
4 ms |
14416 KB |
Output is correct |
4 |
Correct |
4 ms |
14416 KB |
Output is correct |
5 |
Correct |
4 ms |
14416 KB |
Output is correct |
6 |
Correct |
3 ms |
14416 KB |
Output is correct |
7 |
Correct |
5 ms |
14608 KB |
Output is correct |
8 |
Correct |
4 ms |
14416 KB |
Output is correct |
9 |
Correct |
4 ms |
14416 KB |
Output is correct |
10 |
Correct |
4 ms |
14476 KB |
Output is correct |
11 |
Correct |
4 ms |
14584 KB |
Output is correct |
12 |
Correct |
4 ms |
14416 KB |
Output is correct |
13 |
Correct |
49 ms |
23116 KB |
Output is correct |
14 |
Correct |
41 ms |
22680 KB |
Output is correct |
15 |
Correct |
44 ms |
23368 KB |
Output is correct |
16 |
Correct |
47 ms |
23368 KB |
Output is correct |
17 |
Correct |
47 ms |
23112 KB |
Output is correct |
18 |
Correct |
51 ms |
23204 KB |
Output is correct |
19 |
Correct |
49 ms |
23348 KB |
Output is correct |
20 |
Correct |
4 ms |
14416 KB |
Output is correct |
21 |
Correct |
4 ms |
14600 KB |
Output is correct |
22 |
Correct |
46 ms |
21576 KB |
Output is correct |
23 |
Correct |
54 ms |
22096 KB |
Output is correct |
24 |
Correct |
925 ms |
71908 KB |
Output is correct |
25 |
Correct |
833 ms |
70612 KB |
Output is correct |
26 |
Correct |
571 ms |
54960 KB |
Output is correct |
27 |
Correct |
4 ms |
14416 KB |
Output is correct |
28 |
Correct |
4 ms |
14416 KB |
Output is correct |
29 |
Correct |
54 ms |
24648 KB |
Output is correct |
30 |
Correct |
50 ms |
23368 KB |
Output is correct |
31 |
Correct |
54 ms |
24508 KB |
Output is correct |
32 |
Correct |
50 ms |
23368 KB |
Output is correct |
33 |
Correct |
45 ms |
22856 KB |
Output is correct |
34 |
Correct |
56 ms |
23880 KB |
Output is correct |
35 |
Correct |
50 ms |
24508 KB |
Output is correct |
36 |
Correct |
1295 ms |
68072 KB |
Output is correct |
37 |
Correct |
1491 ms |
87640 KB |
Output is correct |
38 |
Correct |
1323 ms |
87220 KB |
Output is correct |
39 |
Correct |
171 ms |
42412 KB |
Output is correct |
40 |
Correct |
1054 ms |
87612 KB |
Output is correct |
41 |
Correct |
567 ms |
86696 KB |
Output is correct |
42 |
Correct |
512 ms |
85932 KB |
Output is correct |
43 |
Correct |
374 ms |
71936 KB |
Output is correct |
44 |
Correct |
377 ms |
71932 KB |
Output is correct |
45 |
Correct |
1012 ms |
85900 KB |
Output is correct |
46 |
Correct |
860 ms |
80052 KB |
Output is correct |
47 |
Correct |
811 ms |
80296 KB |
Output is correct |
48 |
Correct |
1469 ms |
88244 KB |
Output is correct |