Submission #1011982

#TimeUsernameProblemLanguageResultExecution timeMemory
1011982kaopjCryptography (NOI20_crypto)C++17
100 / 100
259 ms31640 KiB
#include <iostream> #include <vector> #include <algorithm> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace __gnu_pbds; #define int long long #define orderedset tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> #define lgm cin.tie(0)->sync_with_stdio(0); const int mod = 1e9+7; using namespace std; signed main() { lgm; orderedset s; int n; cin >> n; vector<pair<int,int>> o(n); vector<int> num(n); for (int i=0;i<n;i++) { cin >> num[i]; o[i]={num[i],i}; } sort(o.begin(),o.end()); int ans=0; for (int i=0;i<n;i++) { num[o[i].second]=i; } int f[n]; f[0]=1; for (int i=1;i<n;i++) { f[i]=i*f[i-1]%mod; } for (int i=n-1;i>=0;i--) { int l=s.order_of_key(num[i]); s.insert(num[i]); ans=(ans+f[n-i-1]*l%mod)%mod; } cout << (ans+1)%mod; }
#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...