Submission #294551

#TimeUsernameProblemLanguageResultExecution timeMemory
294551nandonathanielCryptography (NOI20_crypto)C++14
100 / 100
161 ms15976 KiB
#include<bits/stdc++.h> using namespace std; typedef long long LL; typedef pair<LL,LL> pii; const LL MAXN=300005,MOD=1000000007; LL a[MAXN],bit[MAXN],n,fac[MAXN]; void update(LL now){ for(LL i=now;i<=n;i+=(i&(-i)))bit[i]++; } LL query(LL now){ LL ret=0; if(now==0)return ret; for(LL i=now;i>0;i-=(i&(-i)))ret+=bit[i]; return ret; } int main(){ ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL); fac[0]=1; for(LL i=1;i<=MAXN-5;i++)fac[i]=(fac[i-1]*i)%MOD; cin >> n; vector<pii> v; for(LL i=1;i<=n;i++){ cin >> a[i]; v.push_back({a[i],i}); } sort(v.begin(),v.end()); for(int i=0;i<v.size();i++)a[v[i].second]=i+1; LL ans=0; for(int i=1;i<=n;i++){ ans=(ans+(((a[i]-1-query(a[i]-1))*fac[n-i])%MOD))%MOD; update(a[i]); } cout << (ans+1)%MOD << '\n'; return 0; }

Compilation message (stderr)

Crypto.cpp: In function 'int main()':
Crypto.cpp:31:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   31 |  for(int i=0;i<v.size();i++)a[v[i].second]=i+1;
      |              ~^~~~~~~~~
#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...