Submission #949902

#TimeUsernameProblemLanguageResultExecution timeMemory
949902sondos225Cryptography (NOI20_crypto)C++17
100 / 100
503 ms48308 KiB
#include <bits/stdc++.h> #include <ext/pb_ds/tree_policy.hpp> #include <ext/pb_ds/assoc_container.hpp> using namespace std; using namespace __gnu_pbds; template<typename T>using ordered_set = tree<T,null_type,less_equal<T>,rb_tree_tag,tree_order_statistics_node_update>;//find_by_order(ind); //order_of_key() #define int long long #define fast ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL); #define pb push_back #define yes "YES" #define no "NO" #define bigg INT_MAX #define debug(x) cout<<(#x)<<" = " <<x<<endl; #define all(x) x.begin(),x.end() #define sz size() #define nn '\n' #define mms(x,y) memset(x,y,sizeof(x)) #define forr(i,j,n) for (int i=j; i<n; i++) #define forn(i,j,n) for (int i=j; i>n; i--) #define fi first #define se second #define la "LA" #define cinn(x,y) for(int i=0; i<y; i++) cin>>x[i]; #define pii pair<int,int> // //int fact(int x) //{ // int w=1; // forr(i,1,x+1) w*=i; //} signed main() { // #ifndef LOCAL // freopen("lifeguards.in","r",stdin); // freopen("lifeguards.out","w", stdout); // #endif fast int n; cin>>n; int fact[n]; int w=1; int mod=1000000007; fact[0]=0; forr(i,1,n) {w*=i; w%=mod; fact[i]=w;} int a[n]; map<int,int> m; int b[n]; forr(i,0,n) { cin>>a[i]; b[i]=a[i];} sort(b,b+n); forr(i,0,n) m[b[i]]=i+1; forr(i,0,n) { a[i]=m[a[i]]; } ordered_set <int> s; int na2s=n-1; int ans=0; forr(i,0,n) { int x=a[i]-1; //cout<<x<<' '<<s.order_of_key(x)<<endl; x-=s.order_of_key(a[i]); x*=fact[na2s]%mod; x%=mod; // cout<<x<<' '<<endl; ans+=x; ans%=mod; s.insert(a[i]); na2s--; } cout<<(ans+1)%mod; 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...