Submission #329823

#TimeUsernameProblemLanguageResultExecution timeMemory
329823JiratQCryptography (NOI20_crypto)C++14
100 / 100
262 ms35668 KiB
#include<bits/stdc++.h> #define int long long using namespace std; int dp[300010]; int fw[300010]; int fac(int n){ if(dp[n]!=0) return dp[n]; if(n==0) return 1; return dp[n]=(fac(n-1)%1000000007*n)%1000000007; } void update(int node,int val){ while(node<300010){ fw[node] += val; node += (node&-node); } } int qs(int node){ int sum=0; while(node>0){ sum += fw[node]; node -= (node&-node); } return sum; } main(){ int n; cin >> n; vector<int> vec; for(int i=0;i<n;i++){ int k; scanf("%lld",&k); vec.emplace_back(k); } vector<int> v=vec; sort(v.begin(),v.end()); unordered_map<int,int> mapp; int cnt=1; for(int i=0;i<n;i++){ mapp[v[i]]=cnt; cnt++; } for(int i=0;i<n;i++){ vec[i]=mapp[vec[i]]; } int ans=1; for(int i=0;i<n;i++){ int c=qs(vec[i]); update(vec[i],1); ans += ((vec[i]-1-c) * fac(n-1-i)); ans %= 1000000007; } cout << ans; }

Compilation message (stderr)

Crypto.cpp:29:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   29 | main(){
      |      ^
Crypto.cpp: In function 'int main()':
Crypto.cpp:35:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   35 |         scanf("%lld",&k);
      |         ~~~~~^~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...