結果
| 問題 |
No.696 square1001 and Permutation 5
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2018-06-08 23:30:03 |
| 言語 | C#(csc) (csc 3.9.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 3,192 bytes |
| コンパイル時間 | 928 ms |
| コンパイル使用メモリ | 112,424 KB |
| 実行使用メモリ | 33,352 KB |
| 最終ジャッジ日時 | 2024-06-30 11:08:23 |
| 合計ジャッジ時間 | 2,095 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 1 WA * 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;
//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);
BIT bit = new BIT(N + 3);
long 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;
long[] fact; //階乗
void setFact(int N)
{
fact = new long[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;
}
}