Run ID 作者 问题 语言 测评结果 分数 时间 内存 代码长度 提交时间
2023 16级赵子潇 【S】T3 分块 C++ 通过 100 1055 MS 49092 KB 1537 2020-11-18 21:50:40

Tests(20/20):


#include <bits/stdc++.h> using namespace std; #define int long long char buf[1 << 21], *p1 = buf, *p2 = buf; inline char getc(){ return p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1 << 21, stdin), p1 == p2) ? EOF : *p1++; } inline void read(int &x){ x = 0; char s = getc(); while(s < '0' || s > '9') s = getc(); while('0' <= s && s <= '9'){ x = (x << 3) + (x << 1) + (s ^ 48); s = getc(); } } void print(const int &x){ if(x > 9) print(x / 10); putchar(x % 10 + '0'); } const int N = 1000010; int n, m, ans[N]; struct node{ int l, r; friend bool operator < (const node &A, const node &B){ return A.r - A.l > B.r - B.l; } }Q[N]; int c[N][2]; inline int lowbit(const int &x){ return x & (-x); } inline void add(int x, int op){ for(int i = x;i <= n;i += lowbit(i)) ++c[i][op]; } inline int query(int x, int op){ int sum = 0; for(int i = x;i;i -= lowbit(i)) sum += c[i][op]; return sum; } signed main() { read(n); read(m); int tmp = 0; for(int i = 1;i <= m;i++){ read(Q[i].l); read(Q[i].r); tmp += Q[i].r - Q[i].l + 1; } for(int i = 1;i <= n;i++) ans[i] = tmp; sort(Q + 1, Q + 1 + m); int now = 0; for(int B = n;B >= 1;B--){ while(now < m && Q[now + 1].r - Q[now + 1].l + 1 > B){ ++now; add(Q[now].l, 0); add(Q[now].r, 1); } for(int s = 1;s <= n;s += B){ int t = min(n, s + B - 1); int sum = query(s - 1, 0) - query(t, 1); ans[B] -= sum * (B - 1); } } for(int i = 1;i <= n;i++) print(ans[i]), putchar(' '); return 0; }


测评信息: