Submission #539389

#TimeUsernameProblemLanguageResultExecution timeMemory
539389singlabharatCryptography (NOI20_crypto)C++17
100 / 100
481 ms29132 KiB
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> using namespace std; using namespace __gnu_pbds; #define int long long using vi = vector<int>; using vs = vector<string>; using vb = vector<bool>; using vvi = vector<vector<int>>; using pii = pair<int, int>; using vpii = vector<pair<int, int>>; using si = set<int>; using mii = map<int, int>; template<typename T> using pbds = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; #define sz(x) (int)size(x) #define pb emplace_back #define all(x) begin(x), end(x) #define rall(x) rbegin(x), rend(x) #define fr first #define sc second #define f(i, end) for (int i = 0; i < end; i++) #define ff(i, start, end) for (int i = start; i < end; i++) template<typename T, typename U> inline void domin(T &x, U y) {if (y < x) x = y;} template<typename T, typename U> inline void domax(T &x, U y) {if (y > x) x = y;} template<typename T, typename U> ostream& operator<<(ostream &os, const pair<T, U> &p) { return os << '(' << p.first << ", " << p.second << ')'; } template < typename T_container, typename T = typename enable_if < !is_same<T_container, string>::value, typename T_container::value_type >::type > ostream & operator<<(ostream &os, const T_container &a) { os << '{'; string sep; for (const T &x : a) os << sep << x, sep = ", "; return os << '}';} void debug() {cerr << endl;} template <typename Head, typename... Tail> void debug(Head h, Tail... t) {cerr << h << ' '; debug(t...);} #ifdef singlabharat #define debug(...) cerr << "(" << #__VA_ARGS__ << ") : ", debug(__VA_ARGS__) #else #define debug(...) #endif #define endl '\n' const int MX = 3e5 + 2, INF = 1e18, MOD = 1e9 + 7; void solve() { vi fact(MX); fact[0] = 1; ff(i, 1, MX) fact[i] = (fact[i - 1] * i) % MOD; int n; cin >> n; vi a(n); f(i, n) cin >> a[i]; pbds<int> os; vi dp(n + 1); //dp[i] -> #permutations of a[i..] <= a[i..] dp[n] = 1; for (int i = n - 1; i >= 0; i--) { dp[i] = os.order_of_key(a[i]) * fact[n - i - 1] + dp[i + 1]; dp[i] %= MOD; os.insert(a[i]); } cout << dp[0]; } int32_t main() { #ifdef singlabharat freopen("error.txt", "w", stderr); #endif cin.tie(0)->sync_with_stdio(0); int t = 1; // cin >> t; for (int tc = 0; tc < t; tc++) solve(); }
#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...