結果

問題 No.9005 実行時間/使用メモリテスト(テスト用)
ユーザー eitahoeitaho
提出日時 2016-11-30 11:35:13
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 253 ms / 3,000 ms
コード長 8,582 bytes
コンパイル時間 2,984 ms
コンパイル使用メモリ 117,820 KB
実行使用メモリ 55,272 KB
最終ジャッジ日時 2024-11-27 13:54:31
合計ジャッジ時間 3,077 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 249 ms
53,220 KB
testcase_01 AC 242 ms
55,100 KB
testcase_02 AC 253 ms
55,272 KB
testcase_03 AC 71 ms
36,792 KB
testcase_04 AC 69 ms
36,912 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 MinSegTree(V);
                    for (int i = 0; i < Q; i++)
                        seg.Min(L[i], R[i]);
                }
                break;
            case 2:
                {
                    var seg = new MinSegTree2(V);
                    for (int i = 0; i < Q; i++)
                        seg.Min(L[i], R[i]);
                }
                break;
            case 3:
                {
                    var seg = new MinSegTree3(V);
                    for (int i = 0; i < Q; i++)
                        seg.Min(L[i], R[i]);
                }
                break;
        }

        Console.WriteLine(0);
    }

    long[] Naive(int[] A, int[] L, int[] R)
    {
        var res = new long[L.Length];

        for (int i = 0; i < L.Length; i++)
        {
            long ans = long.MaxValue;
            for (int x = L[i]; x < R[i]; x++)
                ans = Math.Min(ans, A[x]);
            res[i] = ans;
        }

        return res;
    }
}

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 MinSegTree
{
    public static readonly long INF = (long)1e18;
    static readonly int[] Q = new int[200];
    public readonly int N;
    readonly long[] Val;

    public MinSegTree(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 MinSegTree(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 MinSegTree2
{
    public static readonly long INF = (long)1e18;
    static readonly int[] Q = new int[200];
    public readonly int N;
    readonly long[] Val;

    public MinSegTree2(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 MinSegTree2(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 MinSegTree3
{
    public static readonly long INF = (long)1e18;
    static readonly long[] Q = new long[100];
    public readonly int N;
    readonly long[] Val;

    public MinSegTree3(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 MinSegTree3(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