标签:scan vector ret div pre clu name print size
题解:
维护比这个大的第二大
代码:
#include<cstdio> #include<algorithm> #include<queue> #include<cstring> using namespace std; int i,j,n,m,q,c; struct node { int a,b; }p[50010]; bool cmp(node a,node b) { if(a.a!=b.a) return a.a>b.a; return a.b>b.b; } int sum[50010]; priority_queue<int, vector<int>, greater<int> > que; int main() { while (~scanf("%d%d%d",&n,&m,&q)) { while (!que.empty())que.pop(); for (i=0;i<m;i++)scanf("%d%d",&p[i].a,&p[i].b); sort(p,p+m,cmp); sum[1]=0; int a1,a2; for (i=n,j=0;i>=2;i--) { for (;j<m;j++) { if (i<=p[j].a) que.push(p[j].b); else break; } if ((int)que.size()<2) { sum[i]=0; continue; } a1=que.top(); que.pop(); a2=que.top(); que.pop(); que.push(a1); que.push(a2); if(i-a2<0) sum[i]=0; else sum[i]=i-a2; } while (q--) { scanf("%d",&c); printf("%d\n",sum[c]); } } return 0; }
标签:scan vector ret div pre clu name print size
原文地址:http://www.cnblogs.com/xuanyiming/p/7930307.html