Esempio n. 1
0
    public void Solve()
    {
        Pair[] P = new Pair[N];
        for (int i = 0; i < N; i++)
        {
            P[i] = new Pair(i, R[i] - L[i] + 1);
        }
        Array.Sort(P, (p, q) => p.Len.CompareTo(q.Len));

        var ST     = new SegTree(M + 1);
        int bigger = N;
        int ptr    = 0;
        var ans    = new List <long>();

        for (int i = 1; i <= M; i++)
        {
            long cnt = 0;
            while (ptr < N && P[ptr].Len <= i)
            {
                ST.AddRange(L[P[ptr].Idx], R[P[ptr].Idx] + 1, 1);
                bigger--;
                ptr++;
            }
            cnt += bigger;
            for (int j = 0; j <= M; j += i)
            {
                cnt += ST.At(j);
            }
            ans.Add(cnt);
        }

        Console.WriteLine(String.Join("\n", ans));
    }