結果

問題 No.9005 実行時間/使用メモリテスト(テスト用)
ユーザー eitahoeitaho
提出日時 2016-11-30 11:59:43
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 736 ms / 3,000 ms
コード長 11,525 bytes
コンパイル時間 1,014 ms
コンパイル使用メモリ 113,280 KB
実行使用メモリ 49,024 KB
最終ジャッジ日時 2024-11-27 13:56:16
合計ジャッジ時間 4,110 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 736 ms
48,896 KB
testcase_01 AC 524 ms
48,896 KB
testcase_02 AC 253 ms
48,896 KB
testcase_03 AC 220 ms
49,024 KB
testcase_04 AC 235 ms
49,024 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc)
Copyright (C) Microsoft Corporation. All rights reserved.

ソースコード

diff #

using System;
using System.IO;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Collections.Generic;
using System.Diagnostics;
using System.Numerics;
using Enu = System.Linq.Enumerable;

public class Program
{
    public void Solve()
    {
        int N = 1000000;
        int Q = N;
        var random = new XorShift();
        var V = new long[N];
        int[] L = new int[Q], R = new int[Q];

        for (int i = 0; i < N; i++)
            V[i] = random.Next(N);
        for (int i = 0; i < Q; i++)
        {
            L[i] = random.Next(N);
            R[i] = random.Next(L[i] + 1, N + 1);
        }
        switch (Reader.Int())
        {
            case 1:
                {
                    var seg = new MinSegTreeRec(V);
                    for (int i = 0; i < Q; i++)
                        seg.Min(L[i], R[i]);
                }
                break;
            case 2:
                {
                    var seg = new MinSegTreeRecPruning(V);
                    for (int i = 0; i < Q; i++)
                        seg.Min(L[i], R[i]);
                }
                break;
            case 3:
                {
                    var seg = new MinSegTreeBFS1(V);
                    for (int i = 0; i < Q; i++)
                        seg.Min(L[i], R[i]);
                }
                break;
            case 4:
                {
                    var seg = new MinSegTreeBFS2(V);
                    for (int i = 0; i < Q; i++)
                        seg.Min(L[i], R[i]);
                }
                break;
            case 5:
                {
                    var seg = new MinSegTreeBFS3(V);
                    for (int i = 0; i < Q; i++)
                        seg.Min(L[i], R[i]);
                }
                break;
        }

        Console.WriteLine(0);
    }
}

public class XorShift
{
    uint m = 2463534242;
    public XorShift(int seed = 0) { if (seed != 0) m = (uint)seed; }
    public uint NextU() { m = m ^ m << 13; m = m ^ m >> 17; return m = m ^ m << 5; }
    public int Next() { return (int)(NextU() & int.MaxValue); }
    public int Next(int max) { return max <= 0 ? 0 : (int)(NextU() % (uint)max); }
    public int Next(int min, int max) { return min + Next(max - min); }
    public double NextDouble() { return (double)NextU() / uint.MaxValue; }
}


class MinSegTreeRec
{
    public static readonly long INF = (long)1e18;
    public readonly int N;
    private readonly long[] Val;

    public MinSegTreeRec(int n)
    {
        for (N = 2; N < n;) N *= 2;
        Val = new long[N * 2];
        for (int i = 0; i < Val.Length; i++) Val[i] = INF;
    }
    public MinSegTreeRec(long[] A)
    {
        for (N = 2; N < A.Length;) N *= 2;
        Val = new long[N * 2];
        for (int i = 0; i <= N; i++)
            Val[N - 1 + i] = (i < A.Length) ? A[i] : INF;
        for (int i = N - 2; i >= 0; i--)
            Val[i] = Math.Min(Val[(i << 1) + 1], Val[(i << 1) + 2]);
    }

    public void Set(int index, long val)
    {
        index += N - 1;
        Val[index] = val;
        while (index > 0)
        {
            index = (index - 1) / 2;
            Val[index] = Math.Min(Val[index * 2 + 1], Val[index * 2 + 2]);
        }
    }
    // [L, R)
    public long Min(int L, int R) { return Rec(0, 0, N, L, R); }
    private long Rec(int index, int currL, int currR, int L, int R)
    {
        if (currL >= R || currR <= L) return INF;
        if (currL >= L && currR <= R) return Val[index];
        int mid = (currL + currR) / 2;
        long vl = Rec(index * 2 + 1, currL, mid, L, R);
        long vr = Rec(index * 2 + 2, mid, currR, L, R);
        return Math.Min(vl, vr);
    }
}


class MinSegTreeRecPruning
{
    public static readonly long INF = (long)1e18;
    public readonly int N;
    private readonly long[] Val;

    public MinSegTreeRecPruning(int n)
    {
        for (N = 2; N < n;) N *= 2;
        Val = new long[N * 2];
        for (int i = 0; i < Val.Length; i++) Val[i] = INF;
    }
    public MinSegTreeRecPruning(long[] A)
    {
        for (N = 2; N < A.Length;) N *= 2;
        Val = new long[N * 2];
        for (int i = 0; i <= N; i++)
            Val[N - 1 + i] = (i < A.Length) ? A[i] : INF;
        for (int i = N - 2; i >= 0; i--)
            Val[i] = Math.Min(Val[(i << 1) + 1], Val[(i << 1) + 2]);
    }

    public void Set(int index, long val)
    {
        index += N - 1;
        Val[index] = val;
        while (index > 0)
        {
            index = (index - 1) / 2;
            Val[index] = Math.Min(Val[index * 2 + 1], Val[index * 2 + 2]);
        }
    }
    // [L, R)
    public long Min(int L, int R)
    {
        long res = INF;
        Rec(0, 0, N, L, R, ref res);
        return res;
    }
    private void Rec(int index, int currL, int currR, int L, int R, ref long res)
    {
        if (currL >= L && currR <= R) res = Math.Min(res, Val[index]);
        if (Val[index] >= res) return;
        int mid = (currL + currR) / 2;
        if (L < mid) Rec(index * 2 + 1, currL, mid, L, R, ref res);
        if (R > mid) Rec(index * 2 + 2, mid, currR, L, R, ref res);
    }
}


class MinSegTreeBFS1
{
    public static readonly long INF = (long)1e18;
    static readonly int[] Q = new int[200];
    public readonly int N;
    readonly long[] Val;

    public MinSegTreeBFS1(int n)
    {
        for (N = 2; N < n;) N *= 2;
        Val = new long[N * 2];
        for (int i = 0; i < Val.Length; i++) Val[i] = INF;
    }
    public MinSegTreeBFS1(long[] A)
    {
        for (N = 2; N < A.Length;) N *= 2;
        Val = new long[N * 2];
        for (int i = 0; i <= N; i++)
            Val[N - 1 + i] = (i < A.Length) ? A[i] : INF;
        for (int i = N - 2; i >= 0; i--)
            Val[i] = Math.Min(Val[(i << 1) + 1], Val[(i << 1) + 2]);
    }

    public void Set(int index, long val)
    {
        index += N - 1;
        Val[index] = val;
        for (int i = index - 1 >> 1; i >= 0; i = i - 1 >> 1)
            Val[i] = Math.Min(Val[(i << 1) + 1], Val[(i << 1) + 2]);
    }

    public long Min(int L = 0, int R = int.MaxValue)
    {
        long res = INF;
        Q[0] = 0; Q[1] = 0; Q[2] = N;
        for (int QL = 0, QR = 3; QL != QR; QL += 3)
        {
            int i = Q[QL], a = Q[QL + 1], b = Q[QL + 2];
            if (a >= L && b <= R) { res = Math.Min(res, Val[i]); continue; }
            if (Val[i] >= res) continue;
            int mid = a + b >> 1;
            if (L < mid) { Q[QR] = (i << 1) + 1; Q[QR + 1] = a; Q[QR + 2] = mid; QR += 3; }
            if (R > mid) { Q[QR] = (i << 1) + 2; Q[QR + 1] = mid; Q[QR + 2] = b; QR += 3; }
        }
        return res;
    }
}


class MinSegTreeBFS2
{
    public static readonly long INF = (long)1e18;
    static readonly int[] Q = new int[200];
    public readonly int N;
    readonly long[] Val;

    public MinSegTreeBFS2(int n)
    {
        for (N = 2; N < n;) N *= 2;
        Val = new long[N * 2];
        for (int i = 0; i < Val.Length; i++) Val[i] = INF;
    }
    public MinSegTreeBFS2(long[] A)
    {
        for (N = 2; N < A.Length;) N *= 2;
        Val = new long[N * 2];
        for (int i = 0; i <= N; i++)
            Val[N - 1 + i] = (i < A.Length) ? A[i] : INF;
        for (int i = N - 2; i >= 0; i--)
            Val[i] = Math.Min(Val[(i << 1) + 1], Val[(i << 1) + 2]);
    }

    public void Set(int index, long val)
    {
        index += N - 1;
        Val[index] = val;
        for (int i = index - 1 >> 1; i >= 0; i = i - 1 >> 1)
            Val[i] = Math.Min(Val[(i << 1) + 1], Val[(i << 1) + 2]);
    }

    public long Min(int L = 0, int R = int.MaxValue)
    {
        long res = INF;
        Q[0] = 0; Q[1] = 0;
        for (int QL = 0, QR = 2, len = N, first = 2; QL != QR; QL += 2)
        {
            int i = Q[QL], a = Q[QL + 1];
            if (QL == first) { len >>= 1; first = QR; }
            if (a >= L && a + len <= R) { res = Math.Min(res, Val[i]); continue; }
            if (Val[i] >= res) continue;
            int mid = a + (len >> 1);
            if (L < mid) { Q[QR] = (i << 1) + 1; Q[QR + 1] = a; QR += 2; }
            if (R > mid) { Q[QR] = (i << 1) + 2; Q[QR + 1] = mid; QR += 2; }
        }
        return res;
    }
}


class MinSegTreeBFS3
{
    public static readonly long INF = (long)1e18;
    static readonly long[] Q = new long[100];
    public readonly int N;
    readonly long[] Val;

    public MinSegTreeBFS3(int n)
    {
        for (N = 2; N < n;) N *= 2;
        Val = new long[N * 2];
        for (int i = 0; i < Val.Length; i++) Val[i] = INF;
    }
    public MinSegTreeBFS3(long[] A)
    {
        for (N = 2; N < A.Length;) N *= 2;
        Val = new long[N * 2];
        for (int i = 0; i <= N; i++)
            Val[N - 1 + i] = (i < A.Length) ? A[i] : INF;
        for (int i = N - 2; i >= 0; i--)
            Val[i] = Math.Min(Val[(i << 1) + 1], Val[(i << 1) + 2]);
    }

    public void Set(int index, long val)
    {
        index += N - 1;
        Val[index] = val;
        for (int i = index - 1 >> 1; i >= 0; i = i - 1 >> 1)
            Val[i] = Math.Min(Val[(i << 1) + 1], Val[(i << 1) + 2]);
    }

    public long Min(int L = 0, int R = int.MaxValue)
    {
        long res = INF;
        Q[0] = 0;
        for (int QL = 0, QR = 1, len = N, first = 1; QL != QR; ++QL)
        {
            int i = (int)(Q[QL] >> 32), a = (int)Q[QL];
            if (QL == first) { len >>= 1; first = QR; }
            if (a >= L && a + len <= R) { res = Math.Min(res, Val[i]); continue; }
            if (Val[i] >= res) continue;
            int mid = a + (len >> 1);
            if (L < mid) Q[QR++] = ((long)(i << 1) + 1 << 32) + a;
            if (R > mid) Q[QR++] = ((long)(i << 1) + 2 << 32) + mid;
        }
        return res;
    }
}


class Entry { static void Main() { new Program().Solve(); } }
class Reader
{
    static TextReader reader = Console.In;
    static readonly char[] separator = { ' ' };
    static readonly StringSplitOptions op = StringSplitOptions.RemoveEmptyEntries;
    static string[] A = new string[0];
    static int i;
    static void Init() { A = new string[0]; }
    public static void Set(TextReader r) { reader = r; Init(); }
    public static void Set(string file) { reader = new StreamReader(file); Init(); }
    public static bool HasNext() { return CheckNext(); }
    public static string String() { return Next(); }
    public static int Int() { return int.Parse(Next()); }
    public static long Long() { return long.Parse(Next()); }
    public static double Double() { return double.Parse(Next()); }
    public static int[] IntLine() { return Array.ConvertAll(Split(Line()), int.Parse); }
    public static int[] IntArray(int N) { return Range(N, Int); }
    public static int[][] IntTable(int H) { return Range(H, IntLine); }
    public static string[] StringArray(int N) { return Range(N, Next); }
    public static string[][] StringTable(int N) { return Range(N, () => Split(Line())); }
    public static string Line() { return reader.ReadLine().Trim(); }
    public static T[] Range<T>(int N, Func<T> f) { var r = new T[N]; for (int i = 0; i < N; r[i++] = f()) ; return r; }
    static string[] Split(string s) { return s.Split(separator, op); }
    static string Next() { CheckNext(); return A[i++]; }
    static bool CheckNext()
    {
        if (i < A.Length) return true;
        string line = reader.ReadLine();
        if (line == null) return false;
        if (line == "") return CheckNext();
        A = Split(line);
        i = 0;
        return true;
    }
}
0