Run ID | 作者 | 问题 | 语言 | 测评结果 | 分数 | 时间 | 内存 | 代码长度 | 提交时间 |
---|---|---|---|---|---|---|---|---|---|
27911 | 方巾予 | 【S】T3 分块 | C++ | 编译错误 | 0 | 0 MS | 0 KB | 550 | 2024-03-31 14:03:19 |
void init(int n) { B=sqrt(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]) { 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 main() { scanf("%d%d",&n,&m);init(n); for(int i=1,l,r;i<=m;i++) { scanf("%d%d",&l,&r); query(l,r); } cout<<ans<<endl; }