Run ID | 作者 | 问题 | 语言 | 测评结果 | 分数 | 时间 | 内存 | 代码长度 | 提交时间 |
---|---|---|---|---|---|---|---|---|---|
1823 | 18级赵嘉熠 | 【S】T3 分块 | C++ | 运行超时 | 30 | 2000 MS | 11972 KB | 785 | 2020-11-16 10:36:41 |
#include<bits/stdc++.h> using namespace std; const int N=1e6+6; int ans; int B,n,m; int belong[N]; void init(int p) { B=p; 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]) { for(int i=l;i<=r;i++)++ans; return; } for(int i=belong[l]+1;i<belong[r];i++)++ans; int R=belong[l]*B,L=(belong[r]-1)*B+1; for(int i=L;i<=r;i++)++ans; for(int i=l;i<=R;i++)++ans; } int l[N],r[N]; int main(){ scanf("%d%d",&n,&m); for(int i=1;i<=m;i++){ scanf("%d%d",&l[i],&r[i]); } for(int i=1;i<=n;i++){ init(i); for(int j=1;j<=m;j++){ query(l[j],r[j]); } printf("%d ",ans); } return 0; }