Run ID 作者 问题 语言 测评结果 分数 时间 内存 代码长度 提交时间
27922 M0yunAllgor1thm 【S】T3 分块 C++ 通过 100 798 MS 29508 KB 1101 2024-03-31 14:26:31

Tests(20/20):


#include <bits/stdc++.h> #define LL long long using namespace std; const int MAXN=1e6+5; int Lowbit(int x) { return x&(-x); } int N,M; struct Queries { int l,r; bool operator<(const Queries &j) const { return r-l>j.r-j.l; } }q[MAXN]; struct BIT { int tr[MAXN]; void Modify(int x,int k) { while(x<=N) { tr[x]+=k; x+=Lowbit(x); } return; } int Query(int x) { int res=0; while(x) { res+=tr[x]; x-=Lowbit(x); } return res; } }tl,tr; LL ans[MAXN],res=0; int main() { scanf("%d %d",&N,&M); for(int i=1;i<=M;i++) scanf("%d %d",&q[i].l,&q[i].r); sort(q+1,q+M+1); for(int i=1;i<=M;i++) res+=q[i].r-q[i].l+1; for(int i=1;i<=N;i++) ans[i]=res; int ind=1; for(int b=N;b>=1;b--) { while(ind<=M&&q[ind].r-q[ind].l+1>b) { tl.Modify(q[ind].l,1); tr.Modify(q[ind].r,1); ind++; } int tot=(N+b-1)/b; for(int i=1;i<=tot;i++) { int L=(i-1)*b+1,R=min(N,i*b); ans[b]-=1ll*(b-1)*(tl.Query(L-1)-tr.Query(R)); } } for(int i=1;i<=N;i++) printf("%lld ",ans[i]); return 0; }


测评信息: