提交时间:2020-11-16 19:17:47
运行 ID: 1893
#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, sum, ans[N], s[N]; struct node{ int num, L, R; }q1[N], q2[N]; int cnt1, cnt2; inline void Minus(int x, int y){ cnt1 = cnt2 = 0; for(int l = 1, r;l <= x;l = r + 1){ r = x / (x / l); ans[l] -= x / l; ans[r + 1] += x / l; q1[++cnt1] = (node){x / l, l, r}; } for(int l = 1, r;l <= y;l = r + 1){ r = y / (y / l); ans[l] += y / l; ans[r + 1] -= y / l; q2[++cnt2] = (node){y / l, l, r}; } int now = 0; for(int i = 1;i <= cnt1;i++){ while(now < cnt2 && q2[now + 1].num >= q1[i].num) ++now; if(q2[now].num == q1[i].num){ int l = max(q1[i].L, q2[now].L), r = min(q1[i].R, q2[now].R); if(r >= l) ++s[l], --s[r + 1]; } } ++s[max(x, y) + 1]; } signed main() { read(n); read(m); for(int i = 1;i <= m;i++){ int l, r; read(l); read(r); Minus(l - 1, r - 1); sum += r - l; } for(int i = 1;i <= n;i++) ans[i] += ans[i - 1], s[i] += s[i - 1]; for(int i = 1;i <= n;i++){ ans[i] = ans[i] * (1 - i) + sum + i * m; s[i] *= (1 - i); } for(int i = 1;i <= n;i++) print(ans[i] + s[i]), putchar(' '); return 0; }