Submission #261288

#TimeUsernameProblemLanguageResultExecution timeMemory
261288Haunted_CppCryptography (NOI20_crypto)C++17
25 / 100
93 ms7976 KiB
/** * author: Haunted_Cpp **/ #include <bits/stdc++.h> using namespace std; #pragma GCC optimize("Ofast") #pragma GCC target("fma,sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native") #pragma GCC optimize("unroll-loops") template<typename T> ostream &operator << (ostream &os, const vector<T> &v) { os << '{'; string sep; for (const auto &x : v) os << sep << x, sep = ", "; return os << '}'; } template<typename T, size_t size> ostream &operator << (ostream &os, const array<T, size> &arr) { os << '{'; string sep; for (const auto &x : arr) os << sep << x, sep = ", "; return os << '}'; } template<typename A, typename B> ostream &operator << (ostream &os, const pair<A, B> &p) { return os << '(' << p.first << ", " << p.second << ')'; } void debug_out() { cerr << endl; } template<typename Head, typename... Tail> void debug_out(Head H, Tail... T) { cerr << ' ' << H; debug_out(T...); } #ifdef LOCAL #define debug(...) cerr << "(" << #__VA_ARGS__ << "):", debug_out(__VA_ARGS__) #else #define debug(...) 47 #endif const int MAX_N = 3e5 + 5; const int MOD = 1e9 + 7; int f[MAX_N], bit[MAX_N]; void update(int idx, int delta) { for (; idx < MAX_N; idx += idx & (- idx)) { bit[idx] += delta; } } int query(int idx) { int res = 0; for (; idx > 0; idx -= idx & (- idx)) { res += bit[idx]; } return res; } int add(int a, int b) { int res = a + b; if (res >= MOD) res += MOD; if (res < 0) res += MOD; return res; } int mult(int a, int b) { long long res = 1LL * a * b; if (res >= MOD) res %= MOD; return res; } int main () { ios::sync_with_stdio(0); cin.tie(0); int n; cin >> n; vector<int> arr(n); vector<int> c(n); for (int i = 0; i < n; i++) { cin >> arr[i]; c[i] = arr[i]; } sort(c.begin(), c.end()); c.erase(unique(c.begin(), c.end()), c.end()); for (auto &to : arr) { to = lower_bound(c.begin(), c.end(), to) - c.begin() + 1; update(to, +1); } f[0] = 1; for (int i = 1; i < MAX_N; i++) { f[i] = mult(f[i - 1], i); } int res = 0; int left = n - 1; for (int i = 0; i < n; left--, i++) { int l = query(arr[i] - 1); res = add(res, mult(l, f[left])); update(arr[i], -1); } cout << add(res, +1) << '\n'; 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...