您的位置:首页 > 其它

LightOJ1089

2016-04-10 09:27 225 查看
题目链接:http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=26806

题目大意:略

题目思路:前缀和与离散化

可用线段树做,但是前缀和更简单

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <cstring>
#include <stack>
#include <cctype>
#include <queue>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <climits>
#define lson root<<1,l,mid
#define rson root<<1|1,mid+1,r
#define fi first
#define se second
#define ping(x,y) ((x-y)*(x-y))
#define mst(x,y) memset(x,y,sizeof(x))
#define Min(x,y) (x<y?x:y)
#define Max(x,y) (x>y?x:y)
using namespace std;
#define gamma 0.5772156649015328606065120 //欧拉常数
#define MOD 100000007
#define inf 0x3f3f3f3f
#define N 50010
#define maxn 10001000
typedef long long LL;
typedef pair<int,int> PII;

int n,m,a[N<<1],res[N<<1];
PII p
;

int main()
{
int i,x,y,v,group,Case=0;
//freopen("in.txt","r",stdin);
scanf("%d",&group);
while(group--)
{
mst(res,0);
int cnt=0;
scanf("%d%d",&n,&m);
for(i=0; i<n; ++i)
{
scanf("%d%d",&p[i].fi,&p[i].se);
a[cnt++]=p[i].fi;
a[cnt++]=++p[i].se;
}
stable_sort(a,a+cnt);
cnt=unique(a,a+cnt)-a;
for(i=0; i<n; ++i)
{
int l=lower_bound(a,a+cnt,p[i].fi)-a;
int r=lower_bound(a,a+cnt,p[i].se)-a;
++res[l];--res[r];
}
for(i=1; i<cnt; ++i)
res[i]+=res[i-1];
printf("Case %d:\n",++Case);
for(i=0; i<m; ++i)
{
scanf("%d",&x);
int pos=upper_bound(a,a+cnt,x)-a;
printf("%d\n",res[pos-1]);
}
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: