题目:
http://acm.hdu.edu.cn/showproblem.php?pid=4417
2012成都网络赛1008
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<string.h>
using namespace std;
const int MAXN=100010;
int c[MAXN];
int n;
int lowbit(int x){
return x&(-x);
}
void add(int i,int val){
while(i<=n){
c[i]+=val;
i+=lowbit(i);
}
}
int sum(int i){
int ans=0;
while(i>0){
ans+=c[i];
i-=lowbit(i);
}
return ans;
}
struct mario{
int s,e;
int h;
int id;
friend bool operator<(const mario &a,const mario &b){
return a.h< b.h;
}
}mario[MAXN];
struct brick{
int index;
int h;
friend bool operator<(const brick &a,const brick &b){
return a.h< b.h;
}
}b[MAXN];
int ans[MAXN];
int main(){
int t,m;
scanf("%d",&t);
for(intcas = 1;cas <=t;cas++){
scanf("%d%d",&n,&m);
for(inti=1;i<=n;i++){
scanf("%d",&b[i].h);
b[i].index=i;
}
for(inti=0;i
scanf("%d%d%d",&mario[i].s,&mario[i].e,&mario[i].h);
mario[i].s++;
mario[i].e++;
mario[i].id=i;
}
memset(c,0,sizeof(c));
sort(mario,mario+m);
sort(b+1,b+1+n);
int i,j;
i=1;
j=0;
while(j
while(i<=n){
if(b[i].h>mario[j].h)break;
add(b[i].index,1);
i++;
}
while(j
if(i<=n&&mario[j].h>=b[i].h)break;
ans[mario[j].id]=sum(mario[j].e)-sum(mario[j].s-1);
j++;
}
}
printf("Case%d:\n",cas);
for(inti=0;i
printf("%d\n",ans[i]);
}
return 0;
}
707

被折叠的 条评论
为什么被折叠?



