中文题意没啥好说的
我们要怎么做呢 暴力枚举左边的点 然后二分树状数组找到符合条件的最大右坐标
我们就可以进行取maxx操作了
/*
hdoj 5700
*/
#include <cstdio>
#include <cstring>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <queue>
#include <map>
#include <set>
#include <stack>
#include <sstream>
using namespace std;
#define dbg(x) ;
//cout<<#x<<" = "<< (x)<< endl
const int MAX_N = 100024;
long long c_[MAX_N];
int c[MAX_N];
long long a[MAX_N];
struct node {
int l,r;
bool operator < (const node other) const
{
if(l==other.l) return r <other.l;
return l < other.l;
}
}arr[MAX_N];
void add(int x,int v){
for(;x<MAX_N;x+=x&(-x))
c[x]+=v;
}
long long getsum(int x){
long long ans = 0;
for(;x;x-=x&(-x))
ans+=c[x];
return ans;
}
void add_(int x,long long v){
for(;x<MAX_N;x+=x&(-x))
c_[x]+=v;
}
long long getsum_(long long x){
long long ans = 0;
for(;x;x-=x&(-x))
ans+=c_[x];
return ans;
}
int main(){
int n,k,m;
while(scanf("%d%d%d",&n,&k,&m)==3){
memset(c,0,sizeof(c));
memset(c_,0,sizeof(c_));
for(int i = 1;i<=n;++i){
scanf("%lld",&a[i]);
add_(i,a[i]);
}
for(int i = 1;i<=m;++i){
scanf("%d%d",&arr[i].l,&arr[i].r);
}
sort(arr+1,arr+1+m);
long long maxx = 0;
for(int i = 1;i<=m;++i){
add(arr[i].l,1);
add(arr[i].r+1,-1);
if(getsum(arr[i].l)<k) continue;
else {
int l = arr[i].l,r = arr[i].r;
while(l<=r){
int mid = (l+r)>>1;
if(getsum(mid)>=k) l = mid + 1;
else r = mid - 1;
}
dbg(r);
dbg(arr[i].l);
maxx = max(maxx,getsum_(r)-getsum_(arr[i].l-1));
dbg(getsum_(r));
dbg(getsum_(arr[i].l-1));
}
}
printf("%lld\n",maxx);
}
return 0;
}