博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
洛谷 P2709 小B的询问
阅读量:7165 次
发布时间:2019-06-29

本文共 861 字,大约阅读时间需要 2 分钟。

/*显然询问的相邻两个区间左右移动的次数越少越好 那么可以考虑把询问的每个区间抽象成坐标系里的点 让点与点之间的曼哈顿距离最短,但是直接排序还是会超时,所以再加一个分块 */#include
#include
#include
using namespace std;const int N=5e4+7;struct node{ int id,l,r;}q[N];int n,m,k;int a[N],num[N],ans[N],pos[N];int qread(){ int x=0; char ch=getchar(); while(ch<'0' || ch>'9')ch=getchar(); while(ch>='0' && ch<='9'){x=x*10+ch-'0';ch=getchar();} return x;}bool cmp(const node &a,const node &b){ if(pos[a.l]==pos[b.l])return a.r
q[i].l) change(tot,--l,1); while(r
q[i].r) change(tot,r--,-1); ans[q[i].id]=tot; } for(int i=1;i<=m;i++) printf("%d\n",ans[i]); for(int i=1;i<=n;i++) printf("%d ",pos[i]); return 0;}

 

转载于:https://www.cnblogs.com/LeTri/p/8569025.html

你可能感兴趣的文章