Submission #1421485
Source Code Expand
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<vector>
#define lc (o << 1)
#define rc (o << 1 | 1)
#define mid ((l+r) >> 1)
using namespace std;
typedef pair<int,int> P;
const int maxn = 100009;
int T[maxn<<2], lazy[maxn<<2];
vector<P> q[maxn];
int n, m, cnt = 0, a, b, ans;
inline int read(){
char ch = getchar(); int x = 0;
while (ch < '0' || '9' < ch) ch = getchar();
while ('0' <= ch && ch <= '9') { x = x*10+ch-'0'; ch = getchar(); }
return x;
}
void pushdown(int o, int l, int r){
if (!lazy[o]) return;
T[lc] += lazy[o]*(mid-l+1);
lazy[lc] += lazy[o];
T[rc] += lazy[o]*(r-mid);
lazy[rc] += lazy[o];
lazy[o] = 0;
}
int query(int o, int l, int r, int x){
if (l == r) return T[o];
pushdown(o, l, r);
if (x <= mid) return query(lc, l, mid, x);
return query(rc, mid+1, r, x);
}
void update(int o, int l, int r, int x, int y){
if (l == x && y == r){
T[o] += r-l+1;
lazy[o]++;
return;
}
pushdown(o, l, r);
if (x <= mid) update(lc, l, mid, x, min(y, mid));
if (mid+1 <= y) update(rc, mid+1, r, max(x, mid+1), y);
}
int main(){
n = read(); m = read();
for (int i=1; i<=n; i++){
a = read(); b = read();
q[b-a+1].push_back(make_pair(a, b));
}
for (int i=1; i<=m; i++){
ans = n-cnt;
for (int j=i; j<=m; j+=i)
ans += query(1, 1, m, j);
printf("%d\n", ans);
for (int j=q[i].size()-1; j>=0; j--){
P t = q[i][j]; cnt++;
update(1, 1, m, t.first, t.second);
}
}
return 0;
}
Submission Info
Submission Time |
|
Task |
E - Snuke Line |
User |
Cyanic |
Language |
C++14 (GCC 5.4.1) |
Score |
700 |
Code Size |
1508 Byte |
Status |
AC |
Exec Time |
243 ms |
Memory |
10240 KB |
Judge Result
Set Name |
Sample |
All |
Score / Max Score |
0 / 0 |
700 / 700 |
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, 17.txt, 18.txt, 19.txt, 20.txt, 21.txt, 22.txt, 23.txt, 24.txt, 25.txt, 26.txt, 27.txt, 28.txt, 29.txt, 30.txt, 31.txt, 32.txt, 33.txt, 34.txt, 35.txt, 36.txt, 37.txt |
Case Name |
Status |
Exec Time |
Memory |
00_example_01.txt |
AC |
2 ms |
4352 KB |
00_example_02.txt |
AC |
2 ms |
4352 KB |
01.txt |
AC |
2 ms |
4352 KB |
02.txt |
AC |
3 ms |
4352 KB |
03.txt |
AC |
3 ms |
4352 KB |
04.txt |
AC |
2 ms |
4352 KB |
05.txt |
AC |
3 ms |
4352 KB |
06.txt |
AC |
3 ms |
4352 KB |
07.txt |
AC |
2 ms |
4352 KB |
08.txt |
AC |
3 ms |
4352 KB |
09.txt |
AC |
3 ms |
4352 KB |
10.txt |
AC |
3 ms |
4352 KB |
11.txt |
AC |
138 ms |
8704 KB |
12.txt |
AC |
241 ms |
10112 KB |
13.txt |
AC |
85 ms |
7936 KB |
14.txt |
AC |
65 ms |
7808 KB |
15.txt |
AC |
65 ms |
7680 KB |
16.txt |
AC |
118 ms |
8320 KB |
17.txt |
AC |
239 ms |
10112 KB |
18.txt |
AC |
57 ms |
7804 KB |
19.txt |
AC |
240 ms |
10112 KB |
20.txt |
AC |
241 ms |
10112 KB |
21.txt |
AC |
241 ms |
10240 KB |
22.txt |
AC |
243 ms |
10112 KB |
23.txt |
AC |
241 ms |
10112 KB |
24.txt |
AC |
191 ms |
8316 KB |
25.txt |
AC |
73 ms |
7416 KB |
26.txt |
AC |
60 ms |
7416 KB |
27.txt |
AC |
209 ms |
9088 KB |
28.txt |
AC |
85 ms |
7800 KB |
29.txt |
AC |
221 ms |
8960 KB |
30.txt |
AC |
90 ms |
7796 KB |
31.txt |
AC |
207 ms |
8192 KB |
32.txt |
AC |
90 ms |
7680 KB |
33.txt |
AC |
74 ms |
7808 KB |
34.txt |
AC |
200 ms |
8960 KB |
35.txt |
AC |
200 ms |
8960 KB |
36.txt |
AC |
3 ms |
4352 KB |
37.txt |
AC |
114 ms |
4480 KB |