結果

問題 No.742 にゃんにゃんにゃん 猫の挨拶
ユーザー bluemeganebluemegane
提出日時 2018-10-08 15:36:07
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 37 ms / 2,500 ms
コード長 820 bytes
コンパイル時間 2,649 ms
コンパイル使用メモリ 103,680 KB
実行使用メモリ 18,712 KB
最終ジャッジ日時 2024-04-20 18:36:25
合計ジャッジ時間 1,853 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 24 ms
17,536 KB
testcase_01 AC 22 ms
17,792 KB
testcase_02 AC 24 ms
17,536 KB
testcase_03 AC 23 ms
17,664 KB
testcase_04 AC 23 ms
17,920 KB
testcase_05 AC 23 ms
17,664 KB
testcase_06 AC 23 ms
17,920 KB
testcase_07 AC 23 ms
17,792 KB
testcase_08 AC 24 ms
17,920 KB
testcase_09 AC 23 ms
17,536 KB
testcase_10 AC 23 ms
17,664 KB
testcase_11 AC 37 ms
18,596 KB
testcase_12 AC 36 ms
18,712 KB
testcase_13 AC 24 ms
17,792 KB
testcase_14 AC 23 ms
17,152 KB
testcase_15 AC 24 ms
17,664 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc)
Copyright (C) Microsoft Corporation. All rights reserved.

ソースコード

diff #

using System;

public class Hello
{
    public static void Main()
    {
        var n = int.Parse(Console.ReadLine().Trim());
        var a = new int[n];
        for (int i = 0; i < n; i++) a[i] =  int.Parse(Console.ReadLine().Trim());
        var bit = new int[n + 1];
        var ans = 0;
        for (int i = 0; i < n; i++)
        {
            ans += i - getSum(a[i], bit);
            addix(a[i], 1, bit, n);
        }
        Console.WriteLine(ans);

    }
    public static int getSum(int i, int[] bit)
    {
        var s = 0;
        while (i > 0)
        {
            s += bit[i];
            i -= i & -i;
        }
        return s;
    }
    public static void addix(int i, int x, int[] bit, int n)
    {
        while (i <= n)
        {
            bit[i] += x;
            i += i & -i;
        }
    }
}
0