Submission #492561

#TimeUsernameProblemLanguageResultExecution timeMemory
492561anonymousCryptography (NOI20_crypto)C++14
35 / 100
96 ms9104 KiB
#include <iostream> #include <algorithm> #define MAXN 300005 #define LL long long #define MOD 1000000007 using namespace std; int N,P[MAXN], Lookup[MAXN]; LL fac[MAXN]={1}, ans; class Fenwick { int BIT[MAXN]; public: void upd(int x) { for (; x<=N; x+= x&(-x)) {BIT[x]++;} } int ask(int p) { int res = 0; for (; p>0; p-=p&(-p)) {res += BIT[p];} return res; } } FT; int main() { //freopen("cryptin.txt","r",stdin); scanf("%d",&N); for (LL i=1; i<=N; i++) { scanf("%d",&P[i]); Lookup[i] = P[i]; fac[i] = (i*fac[i-1]) % MOD; } sort(Lookup+1, Lookup+N+1); for (int i=1; i<=N; i++) { LL ord = lower_bound(Lookup+1, Lookup+N+1, P[i]) - Lookup; ans = (ans + fac[N-i]*(ord-1-FT.ask(ord))) % MOD; FT.upd(ord); } printf("%lld", ans+1); }

Compilation message (stderr)

Crypto.cpp: In function 'int main()':
Crypto.cpp:26:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   26 |     scanf("%d",&N);
      |     ~~~~~^~~~~~~~~
Crypto.cpp:28:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   28 |         scanf("%d",&P[i]);
      |         ~~~~~^~~~~~~~~~~~
#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...