結果
| 問題 |
No.696 square1001 and Permutation 5
|
| コンテスト | |
| ユーザー |
Pulmn
|
| 提出日時 | 2018-05-29 21:17:08 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 2,935 bytes |
| コンパイル時間 | 1,646 ms |
| コンパイル使用メモリ | 173,104 KB |
| 実行使用メモリ | 12,560 KB |
| 最終ジャッジ日時 | 2024-06-30 08:04:29 |
| 合計ジャッジ時間 | 24,183 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | -- * 2 |
| other | TLE * 1 -- * 11 |
ソースコード
#include <bits/stdc++.h>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<30;
const ll INF=1ll<<60;
const double pi=acos(-1);
const double eps=1e-8;
const ll mod=1e9+7;
const int dx[4]={-1,0,1,0},dy[4]={0,-1,0,1};
const ll p=924844033,r=5;
ll Pow(ll n,ll m){
ll res=1;
while(m>0){
if(m&1) (res*=n)%=p;
(n*=n)%=p;
m>>=1;
}
return res;
}
ll Inv(ll x){return Pow(x,p-2);}
void ntt(vl& a,bool B){
int n=a.size(),h=0;
while(1<<h<n) h++;
for(int i=0;i<n;i++){
int j=0;
for(int k=0;k<h;k++) if(i&1<<k) j+=1<<(h-k-1);
if(i<j) swap(a[i],a[j]);
}
for(int i=1;i<n;i*=2){
ll w=Pow(r,(p-1)/(i*2));
if(B) w=Inv(w);
for(int j=0;j<n;j+=i*2){
ll wn=1;
for(int k=0;k<i;k++){
ll s=a[j+k],t=a[i+j+k]*wn%p;
a[j+k]=(s+t)%p;
a[i+j+k]=(s-t+p)%p;
(wn*=w)%=p;
}
}
}
if(B){
ll v=Inv(n);
for(int i=0;i<n;i++) (a[i]*=v)%=p;
}
}
vl Conv(vi a_,vi b_){
int A=a_.size(),B=b_.size();
vl a(A),b(B);
for(int i=0;i<A;i++) a[i]=a_[i];
for(int i=0;i<B;i++) b[i]=b_[i];
int s=A+B-1,t=1;
while(t<s) t*=2;
a.resize(t);
b.resize(t);
ntt(a,0);ntt(b,0);
for(int i=0;i<t;i++) (a[i]*=b[i])%=p;
ntt(a,1);
a.resize(s);
return a;
}
class Segment_Tree{
private:
int n;
vi date;
int Rec(int a,int b,int k,int l,int r){
if(r<=a||b<=l) return 0;
if(a<=l&&r<=b) return date[k];
int m=(l+r)/2;
return Rec(a,b,k*2+1,l,m)+Rec(a,b,k*2+2,m,r);
}
public:
Segment_Tree(int n_){
n=1;
while(n<n_) n*=2;
date=vi(2*n-1);
}
void Update(int k,int x){
k+=n-1;
date[k]+=x;
while(k>0){
k=(k-1)/2;
date[k]=date[k*2+1]+date[k*2+2];
}
}
int Query(int a,int b){
return Rec(a,b,0,0,n);
}
int Open(int k){
return date[k+n-1];
}
};
vi Sum(vi a,vi b){
int A=a.size(),B=b.size(),N=max(A,B),t=0;
vi c(N+1);
for(int i=0;i<N;i++){
t+=(i<A?a[i]:0)+(i<B?b[i]:0);
c[i]=t%10;
t/=10;
}
if(!c[N]) c.pop_back();
return c;
}
vi Mul(vi a,vi b){
vl c=Conv(a,b);
int N=c.size(),t=0;
vi d(N);
for(int i=0;i<N;i++){
t+=c[i];
d[i]=t%10;
t/=10;
}
while(t){
d.push_back(t%10);
t/=10;
}
return d;
}
int n;
vi a,b;
int main(){
cin>>n;
a=b=vi(n);
Segment_Tree st(n);
for(int i=0;i<n;i++) cin>>a[i];
for(int i=0;i<n;i++) st.Update(i,1);
for(int i=0;i<n;i++){
a[i]--;
b[i]=st.Query(0,a[i]);
st.Update(a[i],-1);
}
vi c(1,1),res(1,1);
for(int i=0;i<n;i++){
vi c_=Mul(c,vi(1,b[n-i-1]));
res=Sum(res,c_);
c=Mul(c,vi(1,i+1));
}
reverse(res.begin(),res.end());
for(auto i:res) cout<<i;
cout<<endl;
}
Pulmn