生活随笔
收集整理的這篇文章主要介紹了
AGC030D - Inversion Sum
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
AGC030D - Inversion Sum
題目描述
Solution
考慮dpdpdp,fi,jf_{i,j}fi,j?表示第iii個位置的數大于第jjj個位置的數的概率。
對于每一個詢問修改貢獻即可。
時間復雜度O(nq+n2)O(nq+n^2)O(nq+n2)。
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <cassert>
#include <string.h>
#define MP(A,B) make_pair(A,B)
#define PB(A) push_back(A)
#define SIZE(A) ((int)A.size())
#define LEN(A) ((int)A.length())
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define fi first
#define se secondusing namespace std
;template<typename T
>inline bool upmin(T
&x
,T y
) { return y
<x
?x
=y
,1:0; }
template<typename T
>inline bool upmax(T
&x
,T y
) { return x
<y
?x
=y
,1:0; }typedef long long ll
;
typedef unsigned long long ull
;
typedef long double lod
;
typedef pair
<int,int> PR
;
typedef vector
<int> VI
;const lod eps
=1e-11;
const lod pi
=acos(-1);
const int oo
=1<<30;
const ll loo
=1ll<<62;
const int mods
=1e9+7;
const int inv2
=(mods
+1)>>1;
const int MAXN
=3005;
const int INF
=0x3f3f3f3f;
inline int read()
{int f
=1,x
=0; char c
=getchar();while (c
<'0'||c
>'9') { if (c
=='-') f
=-1; c
=getchar(); }while (c
>='0'&&c
<='9') { x
=(x
<<3)+(x
<<1)+(c
^48); c
=getchar(); }return x
*f
;
}
int f
[MAXN
][MAXN
],a
[MAXN
];
inline int upd(int x
,int y
){ return x
+y
>=mods
?x
+y
-mods
:x
+y
; }
int main()
{int n
=read(),q
=read();for (int i
=1;i
<=n
;i
++) a
[i
]=read();for (int i
=1;i
<=n
;i
++) for (int j
=1;j
<=n
;j
++)if (a
[i
]>a
[j
]) f
[i
][j
]=1;for (int i
=1;i
<=q
;i
++){int x
=read(),y
=read();f
[x
][y
]=f
[y
][x
]=1ll*upd(f
[x
][y
],f
[y
][x
])*inv2
%mods
;for (int j
=1;j
<=n
;j
++)if (x
!=j
&&y
!=j
)f
[x
][j
]=f
[y
][j
]=1ll*upd(f
[x
][j
],f
[y
][j
])*inv2
%mods
,f
[j
][x
]=f
[j
][y
]=1ll*upd(f
[j
][x
],f
[j
][y
])*inv2
%mods
;}int ans
=0;for (int i
=1;i
<=n
;i
++) for (int j
=i
+1;j
<=n
;j
++) ans
=upd(ans
,f
[i
][j
]);for (int i
=1;i
<=q
;i
++) ans
=upd(ans
,ans
);printf("%d\n",ans
);return 0;
}
創作挑戰賽新人創作獎勵來咯,堅持創作打卡瓜分現金大獎
總結
以上是生活随笔為你收集整理的AGC030D - Inversion Sum的全部內容,希望文章能夠幫你解決所遇到的問題。
如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。