Submission #739899

#TimeUsernameProblemLanguageResultExecution timeMemory
739899MODDICryptography (NOI20_crypto)C++14
100 / 100
855 ms43220 KiB
#include <bits/stdc++.h> using namespace std; #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace __gnu_pbds; #define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> #define pb push_back #define mp make_pair typedef long long ll; typedef pair<long long, long long> pll; typedef pair<int,int> pii; typedef vector<long long> vl; typedef vector<int> vi; int n; vl arr, p; const int mod = 1e9 + 7; ll power[300100]; int main(){ cin>>n; arr.resize(n); for(int i = 0; i < n; i++){ cin>>arr[i]; p.pb(arr[i]); } memset(power, 0, sizeof power); power[1] = 1; for(int i =2; i < n; i++){ power[i] = i * power[i-1]; power[i] %= mod; } sort(p.begin(), p.end()); map<ll, ll> lower; for(int i = 0; i < n; i++) lower[p[i]] = i; int ele = n - 1; ll ans = 0; ordered_set o_set; for(int i = 0; i < n; i++){ ll here = lower[arr[i]] - o_set.order_of_key(arr[i]); // cout<<here<<" "; // cout<<here<<" "<<power[ele]<<" "<<ele<<endl; ans += (here * power[ele]) % mod; ans %= mod; ele--; o_set.insert(arr[i]); } // cout<<endl; cout<<(ans+1)%mod<<endl; return 0; }
#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...