Submission #951643

# Submission time Handle Problem Language Result Execution time Memory
951643 2024-03-22T08:33:16 Z Irate Cryptography (NOI20_crypto) C++17
100 / 100
74 ms 11544 KB
#include<bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
const int mxN = 3e5 + 5;
int fact[mxN];
struct FenwickTree{
    vector<int>fen;
    int sz;
    FenwickTree(int n){
        sz = n;
        fen.resize(n + 1);
    }
    void Update(int pos){
        while(pos <= sz){
            fen[pos]++;
            pos += (pos & -pos);
        }
    }
    int Sum(int pos){
        int sum = 0;
        while(pos > 0){
            sum += fen[pos];
            pos -= (pos & -pos);
        }
        return sum;
    }
};
int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    fact[0] = 1;
    for(int i = 1;i < mxN;++i){
        fact[i] = (long long)fact[i - 1] * i % MOD;
    }
    int n;
    cin >> n;
    vector<int>v(n);
    vector<pair<int, int>>compress;
    for(int i = 0;i < n;++i){
        cin >> v[i];
        compress.push_back({v[i], i});
    }
    sort(compress.begin(), compress.end());
    int num = 1;
    v[compress[0].second] = num;
    FenwickTree tree(n);
    for(int i = 1;i < n;++i){
        if(compress[i].first != compress[i - 1].first)num++;
        v[compress[i].second] = num;
    }    
    int res = 1;
    for(int i = 1;i <= n;++i){
        int k = v[i - 1] - tree.Sum(v[i - 1]);
        res += (long long)fact[n - i] * (k - 1) % MOD;
        tree.Update(v[i - 1]);
        res %= MOD;
    }
    cout << res << '\n';
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 1372 KB Output is correct
2 Correct 2 ms 1372 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 1372 KB Output is correct
2 Correct 2 ms 1372 KB Output is correct
3 Correct 2 ms 1372 KB Output is correct
4 Correct 2 ms 1628 KB Output is correct
5 Correct 3 ms 1628 KB Output is correct
6 Correct 2 ms 1624 KB Output is correct
7 Correct 2 ms 1372 KB Output is correct
8 Correct 2 ms 1368 KB Output is correct
9 Correct 2 ms 1372 KB Output is correct
10 Correct 2 ms 1628 KB Output is correct
11 Correct 2 ms 1372 KB Output is correct
12 Correct 2 ms 1628 KB Output is correct
13 Correct 2 ms 1628 KB Output is correct
14 Correct 2 ms 1628 KB Output is correct
15 Correct 2 ms 1372 KB Output is correct
16 Correct 2 ms 1624 KB Output is correct
17 Correct 2 ms 1628 KB Output is correct
18 Correct 2 ms 1628 KB Output is correct
19 Correct 3 ms 1628 KB Output is correct
20 Correct 2 ms 1628 KB Output is correct
21 Correct 2 ms 1372 KB Output is correct
22 Correct 2 ms 1368 KB Output is correct
23 Correct 2 ms 1628 KB Output is correct
24 Correct 2 ms 1628 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 1628 KB Output is correct
2 Correct 37 ms 7456 KB Output is correct
3 Correct 37 ms 9904 KB Output is correct
4 Correct 39 ms 11212 KB Output is correct
5 Correct 37 ms 9676 KB Output is correct
6 Correct 38 ms 9676 KB Output is correct
7 Correct 38 ms 10964 KB Output is correct
8 Correct 39 ms 10012 KB Output is correct
9 Correct 40 ms 11468 KB Output is correct
10 Correct 39 ms 9940 KB Output is correct
11 Correct 38 ms 10028 KB Output is correct
12 Correct 37 ms 10692 KB Output is correct
13 Correct 39 ms 9932 KB Output is correct
14 Correct 38 ms 10956 KB Output is correct
15 Correct 38 ms 10192 KB Output is correct
16 Correct 39 ms 10440 KB Output is correct
17 Correct 40 ms 11240 KB Output is correct
18 Correct 39 ms 10188 KB Output is correct
19 Correct 37 ms 9932 KB Output is correct
20 Correct 38 ms 11468 KB Output is correct
21 Correct 38 ms 10568 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 1624 KB Output is correct
2 Correct 33 ms 7888 KB Output is correct
3 Correct 32 ms 7632 KB Output is correct
4 Correct 33 ms 7120 KB Output is correct
5 Correct 34 ms 7112 KB Output is correct
6 Correct 32 ms 8904 KB Output is correct
7 Correct 34 ms 6972 KB Output is correct
8 Correct 36 ms 8148 KB Output is correct
9 Correct 35 ms 7380 KB Output is correct
10 Correct 35 ms 7376 KB Output is correct
11 Correct 33 ms 7892 KB Output is correct
12 Correct 33 ms 8916 KB Output is correct
13 Correct 34 ms 7892 KB Output is correct
14 Correct 41 ms 8404 KB Output is correct
15 Correct 32 ms 7892 KB Output is correct
16 Correct 33 ms 8436 KB Output is correct
17 Correct 32 ms 6992 KB Output is correct
18 Correct 34 ms 7380 KB Output is correct
19 Correct 35 ms 7368 KB Output is correct
20 Correct 32 ms 7120 KB Output is correct
21 Correct 34 ms 8912 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 1368 KB Output is correct
2 Correct 3 ms 1628 KB Output is correct
3 Correct 3 ms 1628 KB Output is correct
4 Correct 3 ms 1628 KB Output is correct
5 Correct 2 ms 1628 KB Output is correct
6 Correct 3 ms 1628 KB Output is correct
7 Correct 3 ms 1628 KB Output is correct
8 Correct 3 ms 1628 KB Output is correct
9 Correct 2 ms 1624 KB Output is correct
10 Correct 3 ms 1628 KB Output is correct
11 Correct 3 ms 1724 KB Output is correct
12 Correct 2 ms 1628 KB Output is correct
13 Correct 3 ms 1644 KB Output is correct
14 Correct 3 ms 1628 KB Output is correct
15 Correct 2 ms 1628 KB Output is correct
16 Correct 3 ms 1624 KB Output is correct
17 Correct 3 ms 1624 KB Output is correct
18 Correct 3 ms 1628 KB Output is correct
19 Correct 3 ms 1628 KB Output is correct
20 Correct 2 ms 1628 KB Output is correct
21 Correct 3 ms 1628 KB Output is correct
22 Correct 3 ms 1628 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 1372 KB Output is correct
2 Correct 2 ms 1372 KB Output is correct
3 Correct 2 ms 1372 KB Output is correct
4 Correct 2 ms 1628 KB Output is correct
5 Correct 3 ms 1628 KB Output is correct
6 Correct 2 ms 1624 KB Output is correct
7 Correct 2 ms 1372 KB Output is correct
8 Correct 2 ms 1368 KB Output is correct
9 Correct 2 ms 1372 KB Output is correct
10 Correct 2 ms 1628 KB Output is correct
11 Correct 2 ms 1372 KB Output is correct
12 Correct 2 ms 1628 KB Output is correct
13 Correct 2 ms 1628 KB Output is correct
14 Correct 2 ms 1628 KB Output is correct
15 Correct 2 ms 1372 KB Output is correct
16 Correct 2 ms 1624 KB Output is correct
17 Correct 2 ms 1628 KB Output is correct
18 Correct 2 ms 1628 KB Output is correct
19 Correct 3 ms 1628 KB Output is correct
20 Correct 2 ms 1628 KB Output is correct
21 Correct 2 ms 1372 KB Output is correct
22 Correct 2 ms 1368 KB Output is correct
23 Correct 2 ms 1628 KB Output is correct
24 Correct 2 ms 1628 KB Output is correct
25 Correct 2 ms 1368 KB Output is correct
26 Correct 3 ms 1628 KB Output is correct
27 Correct 3 ms 1628 KB Output is correct
28 Correct 3 ms 1628 KB Output is correct
29 Correct 2 ms 1628 KB Output is correct
30 Correct 3 ms 1628 KB Output is correct
31 Correct 3 ms 1628 KB Output is correct
32 Correct 3 ms 1628 KB Output is correct
33 Correct 2 ms 1624 KB Output is correct
34 Correct 3 ms 1628 KB Output is correct
35 Correct 3 ms 1724 KB Output is correct
36 Correct 2 ms 1628 KB Output is correct
37 Correct 3 ms 1644 KB Output is correct
38 Correct 3 ms 1628 KB Output is correct
39 Correct 2 ms 1628 KB Output is correct
40 Correct 3 ms 1624 KB Output is correct
41 Correct 3 ms 1624 KB Output is correct
42 Correct 3 ms 1628 KB Output is correct
43 Correct 3 ms 1628 KB Output is correct
44 Correct 2 ms 1628 KB Output is correct
45 Correct 3 ms 1628 KB Output is correct
46 Correct 3 ms 1628 KB Output is correct
47 Correct 2 ms 1628 KB Output is correct
48 Correct 3 ms 1628 KB Output is correct
49 Correct 3 ms 1628 KB Output is correct
50 Correct 3 ms 1624 KB Output is correct
51 Correct 3 ms 1624 KB Output is correct
52 Correct 3 ms 1628 KB Output is correct
53 Correct 3 ms 1740 KB Output is correct
54 Correct 3 ms 1628 KB Output is correct
55 Correct 3 ms 1624 KB Output is correct
56 Correct 3 ms 1628 KB Output is correct
57 Correct 3 ms 1628 KB Output is correct
58 Correct 3 ms 1712 KB Output is correct
59 Correct 3 ms 1628 KB Output is correct
60 Correct 3 ms 1628 KB Output is correct
61 Correct 2 ms 1628 KB Output is correct
62 Correct 3 ms 1644 KB Output is correct
63 Correct 3 ms 1628 KB Output is correct
64 Correct 3 ms 1628 KB Output is correct
65 Correct 3 ms 1628 KB Output is correct
66 Correct 3 ms 1624 KB Output is correct
67 Correct 3 ms 1648 KB Output is correct
68 Correct 3 ms 1724 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 1624 KB Output is correct
2 Correct 33 ms 7888 KB Output is correct
3 Correct 32 ms 7632 KB Output is correct
4 Correct 33 ms 7120 KB Output is correct
5 Correct 34 ms 7112 KB Output is correct
6 Correct 32 ms 8904 KB Output is correct
7 Correct 34 ms 6972 KB Output is correct
8 Correct 36 ms 8148 KB Output is correct
9 Correct 35 ms 7380 KB Output is correct
10 Correct 35 ms 7376 KB Output is correct
11 Correct 33 ms 7892 KB Output is correct
12 Correct 33 ms 8916 KB Output is correct
13 Correct 34 ms 7892 KB Output is correct
14 Correct 41 ms 8404 KB Output is correct
15 Correct 32 ms 7892 KB Output is correct
16 Correct 33 ms 8436 KB Output is correct
17 Correct 32 ms 6992 KB Output is correct
18 Correct 34 ms 7380 KB Output is correct
19 Correct 35 ms 7368 KB Output is correct
20 Correct 32 ms 7120 KB Output is correct
21 Correct 34 ms 8912 KB Output is correct
22 Correct 2 ms 1368 KB Output is correct
23 Correct 3 ms 1628 KB Output is correct
24 Correct 3 ms 1628 KB Output is correct
25 Correct 3 ms 1628 KB Output is correct
26 Correct 2 ms 1628 KB Output is correct
27 Correct 3 ms 1628 KB Output is correct
28 Correct 3 ms 1628 KB Output is correct
29 Correct 3 ms 1628 KB Output is correct
30 Correct 2 ms 1624 KB Output is correct
31 Correct 3 ms 1628 KB Output is correct
32 Correct 3 ms 1724 KB Output is correct
33 Correct 2 ms 1628 KB Output is correct
34 Correct 3 ms 1644 KB Output is correct
35 Correct 3 ms 1628 KB Output is correct
36 Correct 2 ms 1628 KB Output is correct
37 Correct 3 ms 1624 KB Output is correct
38 Correct 3 ms 1624 KB Output is correct
39 Correct 3 ms 1628 KB Output is correct
40 Correct 3 ms 1628 KB Output is correct
41 Correct 2 ms 1628 KB Output is correct
42 Correct 3 ms 1628 KB Output is correct
43 Correct 3 ms 1628 KB Output is correct
44 Correct 2 ms 1628 KB Output is correct
45 Correct 59 ms 9532 KB Output is correct
46 Correct 57 ms 9564 KB Output is correct
47 Correct 58 ms 8916 KB Output is correct
48 Correct 63 ms 10452 KB Output is correct
49 Correct 59 ms 10056 KB Output is correct
50 Correct 57 ms 10452 KB Output is correct
51 Correct 57 ms 10196 KB Output is correct
52 Correct 67 ms 9428 KB Output is correct
53 Correct 57 ms 10812 KB Output is correct
54 Correct 58 ms 9332 KB Output is correct
55 Correct 69 ms 10704 KB Output is correct
56 Correct 57 ms 10700 KB Output is correct
57 Correct 57 ms 10964 KB Output is correct
58 Correct 2 ms 1628 KB Output is correct
59 Correct 58 ms 9480 KB Output is correct
60 Correct 58 ms 9676 KB Output is correct
61 Correct 59 ms 10708 KB Output is correct
62 Correct 58 ms 10184 KB Output is correct
63 Correct 57 ms 9428 KB Output is correct
64 Correct 65 ms 8904 KB Output is correct
65 Correct 56 ms 8912 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 1372 KB Output is correct
2 Correct 2 ms 1372 KB Output is correct
3 Correct 2 ms 1372 KB Output is correct
4 Correct 2 ms 1628 KB Output is correct
5 Correct 3 ms 1628 KB Output is correct
6 Correct 2 ms 1624 KB Output is correct
7 Correct 2 ms 1372 KB Output is correct
8 Correct 2 ms 1368 KB Output is correct
9 Correct 2 ms 1372 KB Output is correct
10 Correct 2 ms 1628 KB Output is correct
11 Correct 2 ms 1372 KB Output is correct
12 Correct 2 ms 1628 KB Output is correct
13 Correct 2 ms 1628 KB Output is correct
14 Correct 2 ms 1628 KB Output is correct
15 Correct 2 ms 1372 KB Output is correct
16 Correct 2 ms 1624 KB Output is correct
17 Correct 2 ms 1628 KB Output is correct
18 Correct 2 ms 1628 KB Output is correct
19 Correct 3 ms 1628 KB Output is correct
20 Correct 2 ms 1628 KB Output is correct
21 Correct 2 ms 1372 KB Output is correct
22 Correct 2 ms 1368 KB Output is correct
23 Correct 2 ms 1628 KB Output is correct
24 Correct 2 ms 1628 KB Output is correct
25 Correct 2 ms 1628 KB Output is correct
26 Correct 37 ms 7456 KB Output is correct
27 Correct 37 ms 9904 KB Output is correct
28 Correct 39 ms 11212 KB Output is correct
29 Correct 37 ms 9676 KB Output is correct
30 Correct 38 ms 9676 KB Output is correct
31 Correct 38 ms 10964 KB Output is correct
32 Correct 39 ms 10012 KB Output is correct
33 Correct 40 ms 11468 KB Output is correct
34 Correct 39 ms 9940 KB Output is correct
35 Correct 38 ms 10028 KB Output is correct
36 Correct 37 ms 10692 KB Output is correct
37 Correct 39 ms 9932 KB Output is correct
38 Correct 38 ms 10956 KB Output is correct
39 Correct 38 ms 10192 KB Output is correct
40 Correct 39 ms 10440 KB Output is correct
41 Correct 40 ms 11240 KB Output is correct
42 Correct 39 ms 10188 KB Output is correct
43 Correct 37 ms 9932 KB Output is correct
44 Correct 38 ms 11468 KB Output is correct
45 Correct 38 ms 10568 KB Output is correct
46 Correct 2 ms 1624 KB Output is correct
47 Correct 33 ms 7888 KB Output is correct
48 Correct 32 ms 7632 KB Output is correct
49 Correct 33 ms 7120 KB Output is correct
50 Correct 34 ms 7112 KB Output is correct
51 Correct 32 ms 8904 KB Output is correct
52 Correct 34 ms 6972 KB Output is correct
53 Correct 36 ms 8148 KB Output is correct
54 Correct 35 ms 7380 KB Output is correct
55 Correct 35 ms 7376 KB Output is correct
56 Correct 33 ms 7892 KB Output is correct
57 Correct 33 ms 8916 KB Output is correct
58 Correct 34 ms 7892 KB Output is correct
59 Correct 41 ms 8404 KB Output is correct
60 Correct 32 ms 7892 KB Output is correct
61 Correct 33 ms 8436 KB Output is correct
62 Correct 32 ms 6992 KB Output is correct
63 Correct 34 ms 7380 KB Output is correct
64 Correct 35 ms 7368 KB Output is correct
65 Correct 32 ms 7120 KB Output is correct
66 Correct 34 ms 8912 KB Output is correct
67 Correct 2 ms 1368 KB Output is correct
68 Correct 3 ms 1628 KB Output is correct
69 Correct 3 ms 1628 KB Output is correct
70 Correct 3 ms 1628 KB Output is correct
71 Correct 2 ms 1628 KB Output is correct
72 Correct 3 ms 1628 KB Output is correct
73 Correct 3 ms 1628 KB Output is correct
74 Correct 3 ms 1628 KB Output is correct
75 Correct 2 ms 1624 KB Output is correct
76 Correct 3 ms 1628 KB Output is correct
77 Correct 3 ms 1724 KB Output is correct
78 Correct 2 ms 1628 KB Output is correct
79 Correct 3 ms 1644 KB Output is correct
80 Correct 3 ms 1628 KB Output is correct
81 Correct 2 ms 1628 KB Output is correct
82 Correct 3 ms 1624 KB Output is correct
83 Correct 3 ms 1624 KB Output is correct
84 Correct 3 ms 1628 KB Output is correct
85 Correct 3 ms 1628 KB Output is correct
86 Correct 2 ms 1628 KB Output is correct
87 Correct 3 ms 1628 KB Output is correct
88 Correct 3 ms 1628 KB Output is correct
89 Correct 2 ms 1628 KB Output is correct
90 Correct 3 ms 1628 KB Output is correct
91 Correct 3 ms 1628 KB Output is correct
92 Correct 3 ms 1624 KB Output is correct
93 Correct 3 ms 1624 KB Output is correct
94 Correct 3 ms 1628 KB Output is correct
95 Correct 3 ms 1740 KB Output is correct
96 Correct 3 ms 1628 KB Output is correct
97 Correct 3 ms 1624 KB Output is correct
98 Correct 3 ms 1628 KB Output is correct
99 Correct 3 ms 1628 KB Output is correct
100 Correct 3 ms 1712 KB Output is correct
101 Correct 3 ms 1628 KB Output is correct
102 Correct 3 ms 1628 KB Output is correct
103 Correct 2 ms 1628 KB Output is correct
104 Correct 3 ms 1644 KB Output is correct
105 Correct 3 ms 1628 KB Output is correct
106 Correct 3 ms 1628 KB Output is correct
107 Correct 3 ms 1628 KB Output is correct
108 Correct 3 ms 1624 KB Output is correct
109 Correct 3 ms 1648 KB Output is correct
110 Correct 3 ms 1724 KB Output is correct
111 Correct 2 ms 1628 KB Output is correct
112 Correct 59 ms 9532 KB Output is correct
113 Correct 57 ms 9564 KB Output is correct
114 Correct 58 ms 8916 KB Output is correct
115 Correct 63 ms 10452 KB Output is correct
116 Correct 59 ms 10056 KB Output is correct
117 Correct 57 ms 10452 KB Output is correct
118 Correct 57 ms 10196 KB Output is correct
119 Correct 67 ms 9428 KB Output is correct
120 Correct 57 ms 10812 KB Output is correct
121 Correct 58 ms 9332 KB Output is correct
122 Correct 69 ms 10704 KB Output is correct
123 Correct 57 ms 10700 KB Output is correct
124 Correct 57 ms 10964 KB Output is correct
125 Correct 2 ms 1628 KB Output is correct
126 Correct 58 ms 9480 KB Output is correct
127 Correct 58 ms 9676 KB Output is correct
128 Correct 59 ms 10708 KB Output is correct
129 Correct 58 ms 10184 KB Output is correct
130 Correct 57 ms 9428 KB Output is correct
131 Correct 65 ms 8904 KB Output is correct
132 Correct 56 ms 8912 KB Output is correct
133 Correct 2 ms 1624 KB Output is correct
134 Correct 61 ms 9676 KB Output is correct
135 Correct 61 ms 10700 KB Output is correct
136 Correct 63 ms 11256 KB Output is correct
137 Correct 63 ms 10444 KB Output is correct
138 Correct 61 ms 9928 KB Output is correct
139 Correct 63 ms 10652 KB Output is correct
140 Correct 60 ms 10312 KB Output is correct
141 Correct 61 ms 10104 KB Output is correct
142 Correct 60 ms 9932 KB Output is correct
143 Correct 60 ms 10508 KB Output is correct
144 Correct 60 ms 9928 KB Output is correct
145 Correct 60 ms 9672 KB Output is correct
146 Correct 63 ms 10324 KB Output is correct
147 Correct 2 ms 1628 KB Output is correct
148 Correct 62 ms 10304 KB Output is correct
149 Correct 60 ms 11544 KB Output is correct
150 Correct 62 ms 10264 KB Output is correct
151 Correct 74 ms 9904 KB Output is correct
152 Correct 61 ms 10952 KB Output is correct
153 Correct 60 ms 10696 KB Output is correct
154 Correct 61 ms 10700 KB Output is correct