Submission #693713

# Submission time Handle Problem Language Result Execution time Memory
693713 2023-02-03T07:20:43 Z zeroesandones Cryptography (NOI20_crypto) C++17
100 / 100
301 ms 26776 KB
#include "bits/stdc++.h"
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef long double ld;
typedef vector<ll> vi;
typedef pair<ll, ll> pi;
template<typename T> using iset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define FOR(i, j, k) for (ll i = j; i < (ll) k; ++i)
#define FORD(i, j, k) for (ll i = j; i >= (ll) k; --i)
#define nl "\n"
#define sp " "

#define all(x) (x).begin(), (x).end()
#define sc second
#define fr first
#define pb emplace_back

const int mod = 1e9 + 7;

void solve()
{
    ll n;
    cin >> n;

    ll a[n];
    FOR(i, 0, n) {
        cin >> a[i];
    }

    ll fac[n + 1] = {};
    fac[0] = 1;
    FOR(i, 1, n + 1) {
        fac[i] = (fac[i - 1] * i) % mod;
    }

    iset<ll> s;
    ll ans = 0;
    FORD(i, n - 1, 0) {
        ans += (s.order_of_key(a[i]) * fac[n - i - 1]) % mod;
        ans %= mod;
        s.insert(a[i]);
    }
    ++ans;

    cout << ans%mod << nl;
}

signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    ll t = 1;
    // cin >> t;
    while (t--)
    {
        solve();
    }
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 0 ms 212 KB Output is correct
22 Correct 0 ms 212 KB Output is correct
23 Correct 0 ms 212 KB Output is correct
24 Correct 0 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 252 ms 23772 KB Output is correct
3 Correct 252 ms 23780 KB Output is correct
4 Correct 253 ms 23780 KB Output is correct
5 Correct 256 ms 23664 KB Output is correct
6 Correct 266 ms 23764 KB Output is correct
7 Correct 269 ms 23728 KB Output is correct
8 Correct 235 ms 23684 KB Output is correct
9 Correct 255 ms 23720 KB Output is correct
10 Correct 241 ms 23748 KB Output is correct
11 Correct 224 ms 23784 KB Output is correct
12 Correct 266 ms 23796 KB Output is correct
13 Correct 257 ms 23756 KB Output is correct
14 Correct 301 ms 23684 KB Output is correct
15 Correct 226 ms 23672 KB Output is correct
16 Correct 224 ms 23776 KB Output is correct
17 Correct 233 ms 23804 KB Output is correct
18 Correct 213 ms 23712 KB Output is correct
19 Correct 255 ms 23724 KB Output is correct
20 Correct 274 ms 23688 KB Output is correct
21 Correct 253 ms 23680 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 218 ms 23684 KB Output is correct
3 Correct 210 ms 23716 KB Output is correct
4 Correct 211 ms 23684 KB Output is correct
5 Correct 215 ms 23704 KB Output is correct
6 Correct 235 ms 23660 KB Output is correct
7 Correct 231 ms 23792 KB Output is correct
8 Correct 204 ms 23724 KB Output is correct
9 Correct 214 ms 23720 KB Output is correct
10 Correct 209 ms 23744 KB Output is correct
11 Correct 208 ms 23732 KB Output is correct
12 Correct 212 ms 23956 KB Output is correct
13 Correct 209 ms 23760 KB Output is correct
14 Correct 215 ms 23748 KB Output is correct
15 Correct 218 ms 23784 KB Output is correct
16 Correct 201 ms 23656 KB Output is correct
17 Correct 211 ms 23676 KB Output is correct
18 Correct 222 ms 23720 KB Output is correct
19 Correct 214 ms 23724 KB Output is correct
20 Correct 209 ms 23780 KB Output is correct
21 Correct 217 ms 23712 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 468 KB Output is correct
3 Correct 2 ms 460 KB Output is correct
4 Correct 2 ms 452 KB Output is correct
5 Correct 2 ms 468 KB Output is correct
6 Correct 2 ms 468 KB Output is correct
7 Correct 1 ms 460 KB Output is correct
8 Correct 2 ms 468 KB Output is correct
9 Correct 2 ms 468 KB Output is correct
10 Correct 2 ms 468 KB Output is correct
11 Correct 2 ms 464 KB Output is correct
12 Correct 2 ms 468 KB Output is correct
13 Correct 2 ms 468 KB Output is correct
14 Correct 2 ms 468 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 2 ms 468 KB Output is correct
17 Correct 2 ms 468 KB Output is correct
18 Correct 1 ms 468 KB Output is correct
19 Correct 2 ms 468 KB Output is correct
20 Correct 1 ms 460 KB Output is correct
21 Correct 2 ms 468 KB Output is correct
22 Correct 2 ms 468 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 0 ms 212 KB Output is correct
22 Correct 0 ms 212 KB Output is correct
23 Correct 0 ms 212 KB Output is correct
24 Correct 0 ms 212 KB Output is correct
25 Correct 0 ms 212 KB Output is correct
26 Correct 1 ms 468 KB Output is correct
27 Correct 2 ms 460 KB Output is correct
28 Correct 2 ms 452 KB Output is correct
29 Correct 2 ms 468 KB Output is correct
30 Correct 2 ms 468 KB Output is correct
31 Correct 1 ms 460 KB Output is correct
32 Correct 2 ms 468 KB Output is correct
33 Correct 2 ms 468 KB Output is correct
34 Correct 2 ms 468 KB Output is correct
35 Correct 2 ms 464 KB Output is correct
36 Correct 2 ms 468 KB Output is correct
37 Correct 2 ms 468 KB Output is correct
38 Correct 2 ms 468 KB Output is correct
39 Correct 1 ms 340 KB Output is correct
40 Correct 2 ms 468 KB Output is correct
41 Correct 2 ms 468 KB Output is correct
42 Correct 1 ms 468 KB Output is correct
43 Correct 2 ms 468 KB Output is correct
44 Correct 1 ms 460 KB Output is correct
45 Correct 2 ms 468 KB Output is correct
46 Correct 2 ms 468 KB Output is correct
47 Correct 0 ms 212 KB Output is correct
48 Correct 2 ms 456 KB Output is correct
49 Correct 2 ms 468 KB Output is correct
50 Correct 2 ms 468 KB Output is correct
51 Correct 2 ms 460 KB Output is correct
52 Correct 2 ms 468 KB Output is correct
53 Correct 1 ms 456 KB Output is correct
54 Correct 2 ms 460 KB Output is correct
55 Correct 2 ms 468 KB Output is correct
56 Correct 2 ms 468 KB Output is correct
57 Correct 2 ms 468 KB Output is correct
58 Correct 2 ms 468 KB Output is correct
59 Correct 2 ms 468 KB Output is correct
60 Correct 2 ms 460 KB Output is correct
61 Correct 1 ms 212 KB Output is correct
62 Correct 2 ms 468 KB Output is correct
63 Correct 2 ms 456 KB Output is correct
64 Correct 2 ms 468 KB Output is correct
65 Correct 2 ms 468 KB Output is correct
66 Correct 2 ms 468 KB Output is correct
67 Correct 2 ms 584 KB Output is correct
68 Correct 2 ms 460 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 218 ms 23684 KB Output is correct
3 Correct 210 ms 23716 KB Output is correct
4 Correct 211 ms 23684 KB Output is correct
5 Correct 215 ms 23704 KB Output is correct
6 Correct 235 ms 23660 KB Output is correct
7 Correct 231 ms 23792 KB Output is correct
8 Correct 204 ms 23724 KB Output is correct
9 Correct 214 ms 23720 KB Output is correct
10 Correct 209 ms 23744 KB Output is correct
11 Correct 208 ms 23732 KB Output is correct
12 Correct 212 ms 23956 KB Output is correct
13 Correct 209 ms 23760 KB Output is correct
14 Correct 215 ms 23748 KB Output is correct
15 Correct 218 ms 23784 KB Output is correct
16 Correct 201 ms 23656 KB Output is correct
17 Correct 211 ms 23676 KB Output is correct
18 Correct 222 ms 23720 KB Output is correct
19 Correct 214 ms 23724 KB Output is correct
20 Correct 209 ms 23780 KB Output is correct
21 Correct 217 ms 23712 KB Output is correct
22 Correct 0 ms 212 KB Output is correct
23 Correct 1 ms 468 KB Output is correct
24 Correct 2 ms 460 KB Output is correct
25 Correct 2 ms 452 KB Output is correct
26 Correct 2 ms 468 KB Output is correct
27 Correct 2 ms 468 KB Output is correct
28 Correct 1 ms 460 KB Output is correct
29 Correct 2 ms 468 KB Output is correct
30 Correct 2 ms 468 KB Output is correct
31 Correct 2 ms 468 KB Output is correct
32 Correct 2 ms 464 KB Output is correct
33 Correct 2 ms 468 KB Output is correct
34 Correct 2 ms 468 KB Output is correct
35 Correct 2 ms 468 KB Output is correct
36 Correct 1 ms 340 KB Output is correct
37 Correct 2 ms 468 KB Output is correct
38 Correct 2 ms 468 KB Output is correct
39 Correct 1 ms 468 KB Output is correct
40 Correct 2 ms 468 KB Output is correct
41 Correct 1 ms 460 KB Output is correct
42 Correct 2 ms 468 KB Output is correct
43 Correct 2 ms 468 KB Output is correct
44 Correct 1 ms 340 KB Output is correct
45 Correct 252 ms 25736 KB Output is correct
46 Correct 263 ms 25660 KB Output is correct
47 Correct 245 ms 25676 KB Output is correct
48 Correct 274 ms 25708 KB Output is correct
49 Correct 239 ms 25676 KB Output is correct
50 Correct 245 ms 25712 KB Output is correct
51 Correct 284 ms 25720 KB Output is correct
52 Correct 234 ms 25620 KB Output is correct
53 Correct 270 ms 25760 KB Output is correct
54 Correct 271 ms 25668 KB Output is correct
55 Correct 252 ms 25676 KB Output is correct
56 Correct 281 ms 25664 KB Output is correct
57 Correct 246 ms 25728 KB Output is correct
58 Correct 0 ms 212 KB Output is correct
59 Correct 273 ms 25688 KB Output is correct
60 Correct 275 ms 25700 KB Output is correct
61 Correct 261 ms 25660 KB Output is correct
62 Correct 245 ms 25724 KB Output is correct
63 Correct 259 ms 25728 KB Output is correct
64 Correct 275 ms 25688 KB Output is correct
65 Correct 252 ms 25780 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 0 ms 212 KB Output is correct
22 Correct 0 ms 212 KB Output is correct
23 Correct 0 ms 212 KB Output is correct
24 Correct 0 ms 212 KB Output is correct
25 Correct 1 ms 212 KB Output is correct
26 Correct 252 ms 23772 KB Output is correct
27 Correct 252 ms 23780 KB Output is correct
28 Correct 253 ms 23780 KB Output is correct
29 Correct 256 ms 23664 KB Output is correct
30 Correct 266 ms 23764 KB Output is correct
31 Correct 269 ms 23728 KB Output is correct
32 Correct 235 ms 23684 KB Output is correct
33 Correct 255 ms 23720 KB Output is correct
34 Correct 241 ms 23748 KB Output is correct
35 Correct 224 ms 23784 KB Output is correct
36 Correct 266 ms 23796 KB Output is correct
37 Correct 257 ms 23756 KB Output is correct
38 Correct 301 ms 23684 KB Output is correct
39 Correct 226 ms 23672 KB Output is correct
40 Correct 224 ms 23776 KB Output is correct
41 Correct 233 ms 23804 KB Output is correct
42 Correct 213 ms 23712 KB Output is correct
43 Correct 255 ms 23724 KB Output is correct
44 Correct 274 ms 23688 KB Output is correct
45 Correct 253 ms 23680 KB Output is correct
46 Correct 0 ms 212 KB Output is correct
47 Correct 218 ms 23684 KB Output is correct
48 Correct 210 ms 23716 KB Output is correct
49 Correct 211 ms 23684 KB Output is correct
50 Correct 215 ms 23704 KB Output is correct
51 Correct 235 ms 23660 KB Output is correct
52 Correct 231 ms 23792 KB Output is correct
53 Correct 204 ms 23724 KB Output is correct
54 Correct 214 ms 23720 KB Output is correct
55 Correct 209 ms 23744 KB Output is correct
56 Correct 208 ms 23732 KB Output is correct
57 Correct 212 ms 23956 KB Output is correct
58 Correct 209 ms 23760 KB Output is correct
59 Correct 215 ms 23748 KB Output is correct
60 Correct 218 ms 23784 KB Output is correct
61 Correct 201 ms 23656 KB Output is correct
62 Correct 211 ms 23676 KB Output is correct
63 Correct 222 ms 23720 KB Output is correct
64 Correct 214 ms 23724 KB Output is correct
65 Correct 209 ms 23780 KB Output is correct
66 Correct 217 ms 23712 KB Output is correct
67 Correct 0 ms 212 KB Output is correct
68 Correct 1 ms 468 KB Output is correct
69 Correct 2 ms 460 KB Output is correct
70 Correct 2 ms 452 KB Output is correct
71 Correct 2 ms 468 KB Output is correct
72 Correct 2 ms 468 KB Output is correct
73 Correct 1 ms 460 KB Output is correct
74 Correct 2 ms 468 KB Output is correct
75 Correct 2 ms 468 KB Output is correct
76 Correct 2 ms 468 KB Output is correct
77 Correct 2 ms 464 KB Output is correct
78 Correct 2 ms 468 KB Output is correct
79 Correct 2 ms 468 KB Output is correct
80 Correct 2 ms 468 KB Output is correct
81 Correct 1 ms 340 KB Output is correct
82 Correct 2 ms 468 KB Output is correct
83 Correct 2 ms 468 KB Output is correct
84 Correct 1 ms 468 KB Output is correct
85 Correct 2 ms 468 KB Output is correct
86 Correct 1 ms 460 KB Output is correct
87 Correct 2 ms 468 KB Output is correct
88 Correct 2 ms 468 KB Output is correct
89 Correct 0 ms 212 KB Output is correct
90 Correct 2 ms 456 KB Output is correct
91 Correct 2 ms 468 KB Output is correct
92 Correct 2 ms 468 KB Output is correct
93 Correct 2 ms 460 KB Output is correct
94 Correct 2 ms 468 KB Output is correct
95 Correct 1 ms 456 KB Output is correct
96 Correct 2 ms 460 KB Output is correct
97 Correct 2 ms 468 KB Output is correct
98 Correct 2 ms 468 KB Output is correct
99 Correct 2 ms 468 KB Output is correct
100 Correct 2 ms 468 KB Output is correct
101 Correct 2 ms 468 KB Output is correct
102 Correct 2 ms 460 KB Output is correct
103 Correct 1 ms 212 KB Output is correct
104 Correct 2 ms 468 KB Output is correct
105 Correct 2 ms 456 KB Output is correct
106 Correct 2 ms 468 KB Output is correct
107 Correct 2 ms 468 KB Output is correct
108 Correct 2 ms 468 KB Output is correct
109 Correct 2 ms 584 KB Output is correct
110 Correct 2 ms 460 KB Output is correct
111 Correct 1 ms 340 KB Output is correct
112 Correct 252 ms 25736 KB Output is correct
113 Correct 263 ms 25660 KB Output is correct
114 Correct 245 ms 25676 KB Output is correct
115 Correct 274 ms 25708 KB Output is correct
116 Correct 239 ms 25676 KB Output is correct
117 Correct 245 ms 25712 KB Output is correct
118 Correct 284 ms 25720 KB Output is correct
119 Correct 234 ms 25620 KB Output is correct
120 Correct 270 ms 25760 KB Output is correct
121 Correct 271 ms 25668 KB Output is correct
122 Correct 252 ms 25676 KB Output is correct
123 Correct 281 ms 25664 KB Output is correct
124 Correct 246 ms 25728 KB Output is correct
125 Correct 0 ms 212 KB Output is correct
126 Correct 273 ms 25688 KB Output is correct
127 Correct 275 ms 25700 KB Output is correct
128 Correct 261 ms 25660 KB Output is correct
129 Correct 245 ms 25724 KB Output is correct
130 Correct 259 ms 25728 KB Output is correct
131 Correct 275 ms 25688 KB Output is correct
132 Correct 252 ms 25780 KB Output is correct
133 Correct 1 ms 320 KB Output is correct
134 Correct 248 ms 26680 KB Output is correct
135 Correct 273 ms 26576 KB Output is correct
136 Correct 246 ms 26668 KB Output is correct
137 Correct 298 ms 26564 KB Output is correct
138 Correct 243 ms 26564 KB Output is correct
139 Correct 252 ms 26572 KB Output is correct
140 Correct 257 ms 26688 KB Output is correct
141 Correct 269 ms 26680 KB Output is correct
142 Correct 256 ms 26580 KB Output is correct
143 Correct 258 ms 26688 KB Output is correct
144 Correct 247 ms 26572 KB Output is correct
145 Correct 268 ms 26776 KB Output is correct
146 Correct 300 ms 26688 KB Output is correct
147 Correct 0 ms 212 KB Output is correct
148 Correct 263 ms 26576 KB Output is correct
149 Correct 269 ms 26680 KB Output is correct
150 Correct 262 ms 26684 KB Output is correct
151 Correct 287 ms 26676 KB Output is correct
152 Correct 255 ms 26676 KB Output is correct
153 Correct 244 ms 26684 KB Output is correct
154 Correct 259 ms 26692 KB Output is correct