Submission #1833213


Source Code Expand

import std.stdio, std.string, std.conv, std.algorithm, std.numeric;
import std.range, std.array, std.math, std.typecons, std.container, core.bitop;

alias Seg = Tuple!(int, "l", int, "r");

void main() {
    int n, m;
    scan(n, m);

    auto ft = fenwickTree(m + 1);
    auto sgs = new Seg[](n);

    foreach (i ; 0 .. n) {
        int li, ri;
        scan(li, ri);
        sgs[i] = Seg(li, ri);
    }

    sgs.sort!"a.r - a.l < b.r - b.l"();

    debug {
        writeln(sgs);
    }

    writeln(n);

    foreach (d ; 2 .. m + 1) {
        while (!sgs.empty && sgs[0].r - sgs[0].l + 1 < d) {
            ft.add(sgs[0].l, 1);
            ft.add(sgs[0].r + 1, -1);
            sgs.popFront();
        }

        int ans;

        for (int i = d; i <= m; i += d) {
            ans += ft.psum(i);
        }

        ans += sgs.length.to!int;

        writeln(ans);
    }
}

struct fenwickTree {
    private {
        int N;
        int[] data;
    }

    this (int n) {
        N = n;
        data = new int[](N + 1);
    }

    void add(int i, int x) {
        while (i <= N) {
            data[i] += x;
            i += i & (-i);
        }
    }

    int psum(int r) {
        return r > 0 ? psum(r - (r & (-r))) + data[r] : 0;
    }
}

void scan(T...)(ref T args) {
    string[] line = readln.split;
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront();
    }
    assert(line.empty);
}


void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}

Submission Info

Submission Time
Task E - Snuke Line
User nanae
Language D (DMD64 v2.070.1)
Score 700
Code Size 1725 Byte
Status AC
Exec Time 358 ms
Memory 5884 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 700 / 700
Status
AC × 2
AC × 39
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 1 ms 256 KB
00_example_02.txt AC 1 ms 256 KB
01.txt AC 1 ms 256 KB
02.txt AC 3 ms 508 KB
03.txt AC 1 ms 256 KB
04.txt AC 1 ms 256 KB
05.txt AC 1 ms 256 KB
06.txt AC 1 ms 256 KB
07.txt AC 1 ms 256 KB
08.txt AC 1 ms 256 KB
09.txt AC 2 ms 380 KB
10.txt AC 1 ms 256 KB
11.txt AC 316 ms 4988 KB
12.txt AC 357 ms 5756 KB
13.txt AC 294 ms 4092 KB
14.txt AC 300 ms 3964 KB
15.txt AC 293 ms 3708 KB
16.txt AC 309 ms 3964 KB
17.txt AC 346 ms 4604 KB
18.txt AC 300 ms 3836 KB
19.txt AC 346 ms 5116 KB
20.txt AC 348 ms 4604 KB
21.txt AC 347 ms 5884 KB
22.txt AC 348 ms 5884 KB
23.txt AC 348 ms 4604 KB
24.txt AC 350 ms 4732 KB
25.txt AC 308 ms 4988 KB
26.txt AC 298 ms 3708 KB
27.txt AC 347 ms 5756 KB
28.txt AC 305 ms 5116 KB
29.txt AC 358 ms 5756 KB
30.txt AC 310 ms 4988 KB
31.txt AC 356 ms 4732 KB
32.txt AC 300 ms 4476 KB
33.txt AC 289 ms 4604 KB
34.txt AC 342 ms 5756 KB
35.txt AC 342 ms 5884 KB
36.txt AC 1 ms 256 KB
37.txt AC 43 ms 892 KB