zoj3888
2024-10-18 22:36:56
题解:
维护比这个大的第二大
代码:
#include<cstdio>
#include<algorithm>
#include<queue>
#include<cstring>
using namespace std;
int i,j,n,m,q,c;
struct node
{
int a,b;
}p[];
bool cmp(node a,node b)
{
if(a.a!=b.a) return a.a>b.a;
return a.b>b.b;
}
int sum[];
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=;i<m;i++)scanf("%d%d",&p[i].a,&p[i].b);
sort(p,p+m,cmp);
sum[]=;
int a1,a2;
for (i=n,j=;i>=;i--)
{
for (;j<m;j++)
{
if (i<=p[j].a) que.push(p[j].b);
else break;
}
if ((int)que.size()<)
{
sum[i]=;
continue;
}
a1=que.top();
que.pop();
a2=que.top();
que.pop();
que.push(a1);
que.push(a2);
if(i-a2<) sum[i]=;
else sum[i]=i-a2;
}
while (q--)
{
scanf("%d",&c);
printf("%d\n",sum[c]);
}
}
return ;
}
最新文章
- U盘启动 WinPE系统维护工具 任意安装GHO/WIM/ESD系统映像 无广告专业版
- webpack 入门
- MarkDown初体验
- HTML 导航框架 (使用 Frame )
- 敏捷开发之道(四)Scrum概述
- Chp18: Hard
- winform 五子棋 判断输赢 分类: WinForm 2014-08-07 20:55 256人阅读 评论(0) 收藏
- curl批量伪造数据
- Windows Firewall Setting
- python笔记六(函数的参数、返回值)
- Mysql 设置远程连接
- git中Please enter a commit message to explain why this merge is necessary.
- 【 Gym - 101138F 】GukiZ Height (数学)
- mvc4使用KindEditor文本编辑器
- 2018.10.23 hdu2476String painter(区间dp)
- Angular2,Springboot,Zuul,Shiro跨域CORS请求踩坑实录
- confluence wiki 破解安装操作流程
- intellij IDEA与springboot项目建立
- makefile opencv的案例
- python-无参函数