Submission #997029

#TimeUsernameProblemLanguageResultExecution timeMemory
997029cpptowinCryptography (NOI20_crypto)C++17
35 / 100
62 ms19652 KiB
#include <bits/stdc++.h> #define fo(i, d, c) for (int i = d; i <= c; i++) #define fod(i, c, d) for (int i = c; i >= d; i--) #define maxn 1000010 #define N 1010 #define fi first #define se second #define pb emplace_back #define en cout << "\n"; #define int long long #define inf (int)1e18 #define pii pair<int, int> #define vii vector<pii> #define lb(x) x & -x #define bit(i, j) ((i >> j) & 1) #define offbit(i, j) (i ^ (1LL << j)) #define onbit(i, j) (i | (1LL << j)) #define vi vector<int> #define all(x) x.begin(),x.end() template <typename T1, typename T2> bool minimize(T1 &a, T2 b) { if (a > b) { a = b; return true; } return false; } template <typename T1, typename T2> bool maximize(T1 &a, T2 b) { if (a < b) { a = b; return true; } return false; } using namespace std; const int nsqrt = 450; const int mod = 1e9 + 7; int n,a[maxn]; vi nen; int f[maxn]; struct BIT { int t[maxn]; void up(int x,int val) { for( ; x < maxn ; x += lb(x)) t[x] += val; } int get(int x) { int ans = 0; for( ; x ; x -= lb(x)) ans += t[x]; return ans; } }t; main() { #define name "TASK" if (fopen(name ".inp", "r")) { freopen(name ".inp", "r", stdin); freopen(name ".out", "w", stdout); } ios_base::sync_with_stdio(false); cin.tie(NULL); cin >> n; fo(i,1,n) { cin >> a[i]; nen.pb(a[i]); } sort(all(nen)); nen.erase(unique(all(nen)),nen.end()); fo(i,1,n) a[i] = lower_bound(all(nen),a[i]) - nen.begin() + 1; f[0] = 1; fo(i,1,n) f[i] = f[i - 1] * i % mod; int ans = 0; fo(i,1,n) { ans = (ans + (a[i] - 1 - t.get(a[i] - 1)) * f[n - i] % mod) % mod; t.up(a[i],1); } cout << ans + 1; }

Compilation message (stderr)

Crypto.cpp:60:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   60 | main()
      | ^~~~
Crypto.cpp: In function 'int main()':
Crypto.cpp:65:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   65 |         freopen(name ".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
Crypto.cpp:66:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   66 |         freopen(name ".out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
#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...