Submission #1694675
Source Code Expand
#include <cstdio>
#include <iostream>
#include <algorithm>
#define fir first
#define sec second
#define mid ((L + R) >> 1)
using namespace std;
const int N = 3e5 + 5;
const int M = 5e6 + 6;
int n, m, base = 0;
pair <int, int> seg[N];
int rt[N], lc[M], rc[M], key[M], S = 0;
template <typename T> void Read(T &x) {
x = 0; char ch;
while (!isdigit(ch = getchar()));
do {x = (x << 1) + (x << 3) + ch - '0';} while (isdigit(ch = getchar()));
}
inline void add(int x, int y, int L, int R, int p) {
key[y] = key[x] + 1;
if (L == R) return;
if (p <= mid) {
rc[y] = rc[x];
lc[y] = ++ S;
add(lc[x], lc[y], L, mid, p);
}
else {
lc[y] = lc[x];
rc[y] = ++ S;
add(rc[x], rc[y], mid + 1, R, p);
}
}
inline int query(int x, int y, int L, int R, int low) {
if (low > R) return 0;
if (L == R) return key[y] - key[x];
if (low <= mid) return query(lc[x], lc[y], L, mid, low) + key[rc[y]] - key[rc[x]];
else return query(rc[x], rc[y], mid + 1, R, low);
}
int main() {
int t = 0;
Read(n); Read(m);
for (int i = 1, l, r; i <= n; i ++) {
Read(l); Read(r);
if (l == 0) base ++;
else seg[++ t] = make_pair(l, r);
}
sort(seg + 1, seg + t + 1);
int p = 0;
for (int i = 1, tmp; i <= t; i ++) {
while (p < seg[i].fir) rt[p + 1] = rt[p], p ++;
tmp = ++ S;
add(rt[p], tmp, 1, m, seg[i].sec);
rt[p] = tmp;
}
while (p < m) rt[p + 1] = rt[p], p ++;
int ans = 0;
for (int i = 1; i <= m; i ++) {
ans = base;
for (int j = 0; j <= m; j += i)
ans += query(rt[j], rt[min(j + i, m)], 1, m, j + i);
printf("%d\n", ans);
}
return 0;
}
Submission Info
Judge Result
Set Name |
Sample |
All |
Score / Max Score |
0 / 0 |
0 / 300 |
Status |
|
|
Set Name |
Test Cases |
Sample |
00_example_01.txt, 00_example_02.txt |
All |
00_example_01.txt, 00_example_02.txt, 01.txt, 02.txt, 03.txt, 04.txt, 05.txt, 06.txt, 07.txt, 08.txt, 09.txt, 10.txt, 11.txt, 12.txt, 13.txt, 14.txt, 15.txt, 16.txt |
Case Name |
Status |
Exec Time |
Memory |
00_example_01.txt |
TLE |
2103 ms |
256 KB |
00_example_02.txt |
TLE |
2103 ms |
256 KB |
01.txt |
TLE |
2103 ms |
256 KB |
02.txt |
TLE |
2107 ms |
256 KB |
03.txt |
TLE |
2103 ms |
256 KB |
04.txt |
TLE |
2103 ms |
256 KB |
05.txt |
TLE |
2103 ms |
256 KB |
06.txt |
TLE |
2103 ms |
256 KB |
07.txt |
TLE |
2103 ms |
256 KB |
08.txt |
TLE |
2103 ms |
256 KB |
09.txt |
TLE |
2103 ms |
256 KB |
10.txt |
TLE |
2103 ms |
256 KB |
11.txt |
TLE |
2103 ms |
256 KB |
12.txt |
TLE |
2103 ms |
256 KB |
13.txt |
TLE |
2103 ms |
256 KB |
14.txt |
TLE |
2103 ms |
256 KB |
15.txt |
TLE |
2103 ms |
256 KB |
16.txt |
TLE |
2103 ms |
256 KB |