結果

問題 No.696 square1001 and Permutation 5
ユーザー beetbeet
提出日時 2018-06-08 23:57:14
言語 Java21
(openjdk 21)
結果
TLE  
実行時間 -
コード長 791 bytes
コンパイル時間 3,545 ms
コンパイル使用メモリ 74,084 KB
実行使用メモリ 84,868 KB
最終ジャッジ日時 2023-09-13 00:35:17
合計ジャッジ時間 25,315 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 TLE -
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 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;
import java.lang.*;
import java.math.*;

public class Main {
    int n;
    int[] bit;
    int sum(int i){
	int s=bit[0];
	for(int x=i;x>0;x-=(x&-x))
	    s+=bit[x];
	return s;
    }
    void add(int i,int a){
	if(i==0) return;
	for(int x=i;x<=n;x+=(x&-x))
	    bit[x]+=a;
    }

    void run(){
	Scanner cin = new Scanner(System.in);
	n = cin.nextInt();
	int[] p = new int[n];
	for(int i=0;i<n;i++) p[i]=cin.nextInt();    
	
	bit = new int[n+100];
	
	BigInteger ans = BigInteger.ONE, x = BigInteger.ONE;
	for(int i=1;i<=n;i++){
	    ans = ans.add(x.multiply(BigInteger.valueOf(sum(p[n-i]))));
	    add(p[n-i], 1);
	    x = x.multiply(BigInteger.valueOf(i));
	}
	System.out.println(ans);
    }
    
    public static void main(String[] args) {
	new Main().run();
    }
}
0