标签:font rip play lin ble ane element 测试数据 const
Time Limit: 8000/4000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 1162 Accepted Submission(s): 456
1 #include<bits/stdc++.h> 2 using namespace std; 3 typedef long long ll; 4 const int N=1e5+10; 5 6 struct node{ 7 int x,y; 8 }a[N]; 9 ll s[N]; 10 int n,k,m; 11 bool cmp(node p,node q){ 12 return p.y>q.y; 13 } 14 15 struct nn{ 16 int l,r; 17 ll sum; 18 }e[N*4]; 19 void build(int x,int L,int R){ 20 e[x].l=L;e[x].r=R; 21 if(L==R){ 22 e[x].sum=0;return ; 23 } 24 int mid=(L+R)>>1; 25 build(2*x,L,mid); 26 build(2*x+1,mid+1,R); 27 e[x].sum=e[x*2].sum+e[2*x+1].sum; 28 } 29 void update(int v,int x){ 30 if(e[x].l==e[x].r){ 31 e[x].sum++;return ; 32 } 33 int mid=(e[x].l+e[x].r)>>1; 34 if(v<=mid) update(v,2*x); 35 else update(v,2*x+1); 36 e[x].sum=e[x*2].sum+e[2*x+1].sum; 37 } 38 39 int query(int v,int x){ 40 if(e[x].l==e[x].r){ 41 return e[x].l; 42 } 43 if(e[2*x].sum>=v) query(v,2*x); 44 else query(v-e[x*2].sum,2*x+1); 45 } 46 int main(){ 47 while(scanf("%d%d%d",&n,&k,&m)!=EOF){ 48 ll x; 49 build(1,1,n); 50 for(int i=1;i<=n;i++){ 51 scanf("%lld",&x);s[i]=s[i-1]+x; 52 } 53 for(int i=1;i<=m;i++){ 54 scanf("%d%d",&a[i].x,&a[i].y); 55 } 56 sort(a+1,a+1+m,cmp); 57 for(int i=1;i<=k-1;i++){ 58 update(a[i].x,1); 59 } 60 ll Max=0; 61 for(int i=k;i<=m;i++){ 62 update(a[i].x,1); 63 // cout<<e[1].sum<<endl; 64 int xx=query(k,1); 65 //cout<<xx<<" "<<a[i].y<<endl; 66 if(xx<=a[i].y){ 67 Max=max(Max,s[a[i].y]-s[xx-1]); 68 } 69 } 70 cout<<Max<<endl; 71 } 72 return 0; 73 }
标签:font rip play lin ble ane element 测试数据 const
原文地址:http://www.cnblogs.com/hhxj/p/7103719.html