标签:har ace ++ int namespace char operator span names
#include <algorithm> #include <cstdio> #define N 50005 using namespace std; struct node { int id,ans,h; }Q[N]; struct nodee { int id,h; bool operator<(nodee a)const { return h<a.h; } }A[N]; bool cmp(node a,node b) { return a.h<b.h; } bool comp(node a,node b) { return a.id<b.id; } int n,q; bool ym[N]; int Main() { scanf("%d%d",&n,&q); for(int i=1;i<=n;++i) scanf("%d",&A[i].h),A[i].id=i; sort(A+1,A+1+n); for(int i=1;i<=q;++i) { scanf("%d",&Q[i].h); Q[i].id=i; } sort(Q+1,Q+1+q,cmp); int j=1,sum=1; for(int i=1;i<=q;++i) { while(A[j].h<=Q[i].h&&j<=n) { if(A[j].id==1) {if(ym[1]) sum--;} else if(A[j].id==n) {if(ym[n-1]) sum--;} else { if(ym[A[j].id-1]&&ym[A[j].id+1]) sum--; else if(!ym[A[j].id-1]&&!ym[A[j].id+1]) sum++; } ym[A[j].id]=1; j++; } Q[i].ans=sum; } sort(Q+1,Q+1+q,comp); for(int i=1;i<=q;++i) printf("%d\n",Q[i].ans); return 0; } int sb=Main(); int main(int argc,char *argv[]){;}//1276
标签:har ace ++ int namespace char operator span names
原文地址:http://www.cnblogs.com/ruojisun/p/7562994.html