結果

問題 No.696 square1001 and Permutation 5
ユーザー claw88claw88
提出日時 2018-06-08 23:32:16
言語 C#(csc)
(csc 3.9.0)
結果
MLE  
実行時間 -
コード長 3,170 bytes
コンパイル時間 4,390 ms
コンパイル使用メモリ 105,140 KB
実行使用メモリ 813,396 KB
最終ジャッジ日時 2023-09-13 00:21:50
合計ジャッジ時間 9,046 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 MLE -
testcase_01 -- -
testcase_02 -- -
testcase_03 -- -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
権限があれば一括ダウンロードができます
コンパイルメッセージ
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.Collections;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Numerics;

class Myon
{
    public Myon() { }
    public static int Main()
    {
        new Myon().calc();
        return 0;
    }

    Scanner cin;

    void calc()
    {
        cin = new Scanner();
        int N = cin.nextInt();
        int[] ar = cin.ArrayInt(N);
        setFact(N + 3);
        BIT bit = new BIT(N + 3);

        BigInteger ans = 1;

        for (int i = 0; i < N; i++)
        {
            ans += fact[N - i - 1] * (ar[i] - bit.bitCal(ar[i]) - 1);
            //ans %= mod;
            bit.bitUpdate(ar[i], 1);
        }

        Console.WriteLine(ans);
    }

    //long mod = 1000000007;


    BigInteger[] fact; //階乗
    void setFact(int N)
    {
        fact = new BigInteger[N];
        fact[0] = 1;
        for (int i = 1; i < N; i++)
        {
            fact[i] = fact[i - 1] * i;
            //fact[i] %= mod;
        }
    }

    class BIT
    {
        int bitA;
        int[] bit;
        const int INF = int.MaxValue - 10;

        public BIT(int maxa)
        {
            bitA = maxa;
            bit = new int[bitA + 1];
            for (int i = 0; i < bitA; i++)
            {
                bit[i] = 0;
            }
        }

        public void bitUpdate(int a, int val)
        {
            for (int i = a; i <= bitA; i += i & -i)
            {
                bit[i] += val;
            }
        }

        public int bitCal(int max, int min)
        {
            return bitCal(max) - bitCal(min - 1);
        }

        public int bitCal(int a)
        {
            int ret = 0;
            for (int i = a; i > 0; i &= i - 1)
            {
                ret += bit[i];
            }
            return ret;
        }
    }



}

class Scanner
{
    string[] s;
    int i;

    char[] cs = new char[] { ' ' };

    public Scanner()
    {
        s = new string[0];
        i = 0;
    }

    public string next()
    {
        if (i < s.Length) return s[i++];
        string st = Console.ReadLine();
        while (st == "") st = Console.ReadLine();
        s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
        if (s.Length == 0) return next();
        i = 0;
        return s[i++];
    }

    public int nextInt()
    {
        return int.Parse(next());
    }
    public int[] ArrayInt(int N, int add = 0)
    {
        int[] Array = new int[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextInt() + add;
        }
        return Array;
    }

    public long nextLong()
    {
        return long.Parse(next());
    }

    public long[] ArrayLong(int N, long add = 0)
    {
        long[] Array = new long[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextLong() + add;
        }
        return Array;
    }

    public double nextDouble()
    {
        return double.Parse(next());
    }


    public double[] ArrayDouble(int N, double add = 0)
    {
        double[] Array = new double[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextDouble() + add;
        }
        return Array;
    }
}
0