結果
| 問題 |
No.696 square1001 and Permutation 5
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2018-06-09 00:18:51 |
| 言語 | C#(csc) (csc 3.9.0) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 3,463 bytes |
| コンパイル時間 | 959 ms |
| コンパイル使用メモリ | 110,736 KB |
| 実行使用メモリ | 67,680 KB |
| 最終ジャッジ日時 | 2024-06-30 11:44:11 |
| 合計ジャッジ時間 | 23,417 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | -- * 2 |
| other | TLE * 1 -- * 11 |
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc) Copyright (C) Microsoft Corporation. All rights reserved.
ソースコード
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Numerics;
//https://beta.atcoder.jp/contests/chokudai_S001/submissions/1607681
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);
//Array.Reverse(ar);
BIT bit = new BIT(N + 3);
BigInteger ans = 1;
BigInteger fact = 1;
//for (int i = 1; i < N; i++)
//{
// fact *= i;
//}
for (int i = N - 1; i >= 0; i--)
{
ans += fact * (bit.bitCal(ar[i]));
//ans %= mod;
bit.bitUpdate(ar[i], 1);
fact *= (N - i);
}
Console.WriteLine(ans);
//Console.WriteLine(fact - 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;
}
}