Run ID | 作者 | 问题 | 语言 | 测评结果 | 分数 | 时间 | 内存 | 代码长度 | 提交时间 |
---|---|---|---|---|---|---|---|---|---|
1829 | 16级钟煜奇 | 【S】T3 分块 | C++ | 运行超时 | 30 | 2000 MS | 1428 KB | 822 | 2020-11-16 11:14:27 |
#include <iostream> #include <cstdio> using namespace std; const int MAX=1e5+5; int B,n,m; int belong[MAX],q[2][MAX],ans; void init(int n) { ans=0; for(int i=1;i<=n;i++)belong[i]=(i-1)/B+1; } void query(int l,int r) { if(belong[l]==belong[r]) { ans+=r-l+1; // for(int i=l;i<=r;i++)++ans; return; } ans+=belong[r]-(belong[l]+1);//for(int i=belong[l]+1;i<belong[r];i++)++ans; int R=belong[l]*B,L=(belong[r]-1)*B+1; ans+=r-L+1;//for(int i=L;i<=r;i++)++ans; ans+=R-l+1;//for(int i=l;i<=R;i++)++ans; } int main() { scanf("%d %d",&n,&m); for(int i=1;i<=m;i++)scanf("%d %d",&q[0][i],&q[1][i]); for(int i=1;i<=n;i++){ B=i; init(n); for(int j=1;j<=m;j++)query(q[0][j],q[1][j]); printf("%d ",ans); } }