コード例 #1
0
    static void Main()
    {
        Sc  sc = new Sc();
        int n  = sc.I;
        St2 st = new St2(1, 200000);
        var sb = new StringBuilder();

        for (int i = 0; i < n; i++)
        {
            int[] q = sc.Ia;
            if (q[0] == 1)
            {
                st.Ud(q[1], 1);
            }
            else
            {
                int lb = 0, ub = 200000, mid = 0;
                while (ub - lb > 1)
                {
                    mid = (ub + lb) / 2;
                    if (st.Get(1, mid) > q[1] - 1)
                    {
                        ub = mid;
                    }
                    else
                    {
                        lb = mid;
                    }
                }
                sb.Append(ub + "\n");
                st.Ud(ub, -1);
            }
        }
        Console.Write(sb);
    }
コード例 #2
0
    static void Main()
    {
        Sc sc = new Sc();

        int[]   s = sc.Ia;
        int[][] a = new int[s[0]][];
        for (int i = 0; i < s[0]; i++)
        {
            a[i] = sc.Ia;
        }
        Array.Sort(a, (u, v) => (u[1] - u[0]) - (v[1] - v[0]));
        St2           st = new St2(1, s[1]);
        StringBuilder sb = new StringBuilder();

        for (int i = 1, j = 0; i <= s[1]; i++)
        {
            while (j < s[0] && a[j][1] - a[j][0] < i)
            {
                if (a[j][1] == a[j][0])
                {
                    st.Ud(a[j][0], 1);
                }
                else
                {
                    st.Ud2(a[j][0], a[j][1], 1);
                }
                j++;
            }
            long ans = s[0] - j;
            for (int k = 0; k <= s[1]; k += i)
            {
                ans += st.Get(k, k);
            }
            sb.Append(ans + "\n");
        }
        Console.Write(sb);
    }