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<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 (stderr)
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 |
---|
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... |