Submission #5941784


Source Code Expand

using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using static System.Math;

class Program
{
    static void Main()
    {
        SetOut(new System.IO.StreamWriter(OpenStandardOutput()) { AutoFlush = false });
        var Q = int.Parse(ReadLine());
        var bit = new BIT(2000001);
        for (int i = 0; i < Q; i++)
        {
            var TX = ReadLine().Split();
            var X = int.Parse(TX[1]);
            if (TX[0] == "1")
            {
                bit.Add(X, 1);
            }
            else
            {
                var a = bit.LowerBound(X);
                WriteLine(a);
                bit.Add(a, -1);
            }
        }
        Out.Flush();
    }
}

public class BIT
{
    int[] buffer;
    int root;

    public BIT(int length)
    {
        buffer = new int[length + 1];
        root = 1 << 30;
        while (root > length) root >>= 1;
    }

    public void Add(int index, int value)
    {
        for (int i = index + 1; i < buffer.Length; i += i & -i) buffer[i] += value;
    }

    public int Sum(int index)
    {
        int ret = 0;
        for (int i = index; i > 0; i -= i & -i) ret += buffer[i];
        return ret;
    }

    public int Sum(int l, int r)
    {
        return Sum(r) - Sum(l);
    }

    public int LowerBound(int w)
    {
        int x = 0;
        for (int k = root; k > 0; k >>= 1)
        {
            if (x + k < buffer.Length && buffer[x + k] < w)
            {
                w -= buffer[x + k];
                x += k;
            }
        }
        return x;
    }
}

Submission Info

Submission Time
Task C - データ構造
User iwkjosec
Language C# (Mono 4.6.2.0)
Score 100
Code Size 1668 Byte
Status AC
Exec Time 229 ms
Memory 20536 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 100 / 100
Status
AC × 2
AC × 18
Set Name Test Cases
Sample sample_01.txt, sample_02.txt
All sample_01.txt, sample_02.txt, subtask1_01.txt, subtask1_02.txt, subtask1_03.txt, subtask1_04.txt, subtask1_05.txt, subtask1_06.txt, subtask1_07.txt, subtask1_08.txt, subtask1_09.txt, subtask1_10.txt, subtask1_11.txt, subtask1_12.txt, subtask1_13.txt, subtask1_14.txt, subtask1_15.txt, subtask1_16.txt
Case Name Status Exec Time Memory
sample_01.txt AC 21 ms 13024 KiB
sample_02.txt AC 22 ms 17120 KiB
subtask1_01.txt AC 20 ms 12896 KiB
subtask1_02.txt AC 21 ms 12896 KiB
subtask1_03.txt AC 21 ms 15456 KiB
subtask1_04.txt AC 36 ms 15840 KiB
subtask1_05.txt AC 53 ms 17888 KiB
subtask1_06.txt AC 22 ms 13664 KiB
subtask1_07.txt AC 132 ms 18004 KiB
subtask1_08.txt AC 226 ms 18488 KiB
subtask1_09.txt AC 229 ms 18492 KiB
subtask1_10.txt AC 203 ms 20164 KiB
subtask1_11.txt AC 204 ms 20164 KiB
subtask1_12.txt AC 165 ms 17860 KiB
subtask1_13.txt AC 229 ms 20536 KiB
subtask1_14.txt AC 229 ms 20536 KiB
subtask1_15.txt AC 193 ms 18488 KiB
subtask1_16.txt AC 190 ms 17980 KiB