Submission #1319792

#TimeUsernameProblemLanguageResultExecution timeMemory
1319792discontinuousCryptography (NOI20_crypto)C++20
35 / 100
202 ms34872 KiB
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace std;


#define pb push_back
#define int long long


#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>



const int MOD = 1e9 + 7;
const int INF = 1e15;
const int N = 1e6;

int n, m, k, a, b, c, d, h, l, r, q, u, v, x, y;
vector<int> arr(N);
vector<int> fact(N);

void solve() {
    cin >> n;

    ordered_set all;

    for(int i = 1; i<=n; i++) {
        cin >> arr[i];
        all.insert(arr[i]);
    }

    c = 0;
    for(int i = 1; i<n; i++) {
        // cout << all.order_of_key(arr[i]) << "\n";
        c += (all.order_of_key(arr[i])*fact[n-i])%MOD;
        c %= MOD;
        all.erase(arr[i]);
    }

    cout << c+1;
}

int32_t main() {
    ios::sync_with_stdio(false);
    cout.tie(0); cin.tie(0);

    fact[0] = 1;
    for(int i = 1; i<N; i++) {
        fact[i] = (fact[i-1]*i)%MOD;
    }

    int tc = 1;

    while(tc--) {
        solve();
        cout << "\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...