답안 #826493

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
826493 2023-08-15T15:57:25 Z nasir_bashirov Cryptography (NOI20_crypto) C++11
100 / 100
387 ms 31404 KB
#include "bits/stdc++.h"
using namespace std;

#define int long long

#define endl '\n'
#define ll long long
#define pii pair<int, int>
#define pll pair<ll, ll>
#define vi vector<int>
#define vl vector<ll>
#define vii vector<pii>
#define vll vector<pll>
#define all(x)    x.begin(), x.end()
#define fastio\
    ios_base::sync_with_stdio(0);\
    cin.tie(0);\
    cout.tie(0)\

const int sz = 3e5 + 5;
ll a[sz], b[sz], f[sz], n, ind;
const int mod = 1e9 + 7;
map<int, int> mp;

struct fenwickTree{
    int n;
    vi BIT;
    fenwickTree(int sz){
        n = sz;
        BIT.resize(n + 1, 0);
    }
    void update(int i, int v){
        if(i == 0)    return;
        while(i <= n){
            BIT[i] += v;
            i += i & (-i);
        }
    }
    int query(int l, int r){
        if(l > r)   return 0;   
        if(l != 1)    return query(1, r) - query(1, l - 1);
        int res = 0;
        while(r > 0){
            res += BIT[r];
            r -= r & (-r);
        }
        return res;
    }
};

void preComp(){
    f[0] = 1;
    for(ll i = 1; i <= 300000; i++){
        f[i] = f[i - 1] * i % mod;
    }
}

signed main(){
    fastio;
    cin >> n;
    for(int i = 1; i <= n; i++){
        cin >> a[i];
        b[i] = a[i];
    }
    sort(b + 1, b + n + 1);
    for(int i = 1; i <= n; i++){
        mp[b[i]] = ++ind;
    }
    for(int i = 1; i <= n; i++){
        a[i] = mp[a[i]];
    }
    ll res = 0;
    fenwickTree t(n);
    for(int i = 1; i <= n; i++){
        t.update(i, 1);
    }
    preComp();
    for(int i = 1; i <= n; i++){
        res += f[n - i] * (t.query(1, a[i] - 1)) % mod;
        res %= mod;
        t.update(a[i], -1);
    }
    cout << (res + 1) % mod;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 2644 KB Output is correct
2 Correct 3 ms 2644 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 2644 KB Output is correct
2 Correct 3 ms 2644 KB Output is correct
3 Correct 4 ms 2644 KB Output is correct
4 Correct 3 ms 2644 KB Output is correct
5 Correct 3 ms 2644 KB Output is correct
6 Correct 3 ms 2644 KB Output is correct
7 Correct 3 ms 2644 KB Output is correct
8 Correct 3 ms 2644 KB Output is correct
9 Correct 3 ms 2624 KB Output is correct
10 Correct 3 ms 2644 KB Output is correct
11 Correct 3 ms 2632 KB Output is correct
12 Correct 4 ms 2644 KB Output is correct
13 Correct 3 ms 2688 KB Output is correct
14 Correct 3 ms 2644 KB Output is correct
15 Correct 3 ms 2644 KB Output is correct
16 Correct 3 ms 2576 KB Output is correct
17 Correct 4 ms 2644 KB Output is correct
18 Correct 3 ms 2620 KB Output is correct
19 Correct 3 ms 2644 KB Output is correct
20 Correct 3 ms 2644 KB Output is correct
21 Correct 3 ms 2644 KB Output is correct
22 Correct 4 ms 2624 KB Output is correct
23 Correct 3 ms 2644 KB Output is correct
24 Correct 3 ms 2644 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 2644 KB Output is correct
2 Correct 131 ms 31300 KB Output is correct
3 Correct 128 ms 31308 KB Output is correct
4 Correct 166 ms 31312 KB Output is correct
5 Correct 134 ms 31308 KB Output is correct
6 Correct 129 ms 31308 KB Output is correct
7 Correct 125 ms 31360 KB Output is correct
8 Correct 129 ms 31364 KB Output is correct
9 Correct 127 ms 31404 KB Output is correct
10 Correct 129 ms 31304 KB Output is correct
11 Correct 127 ms 31308 KB Output is correct
12 Correct 128 ms 31404 KB Output is correct
13 Correct 128 ms 31312 KB Output is correct
14 Correct 128 ms 31360 KB Output is correct
15 Correct 125 ms 31404 KB Output is correct
16 Correct 129 ms 31368 KB Output is correct
17 Correct 128 ms 31312 KB Output is correct
18 Correct 127 ms 31400 KB Output is correct
19 Correct 130 ms 31392 KB Output is correct
20 Correct 128 ms 31392 KB Output is correct
21 Correct 133 ms 31368 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 2644 KB Output is correct
2 Correct 121 ms 30352 KB Output is correct
3 Correct 120 ms 30440 KB Output is correct
4 Correct 132 ms 30344 KB Output is correct
5 Correct 123 ms 30344 KB Output is correct
6 Correct 123 ms 30364 KB Output is correct
7 Correct 146 ms 30324 KB Output is correct
8 Correct 131 ms 30356 KB Output is correct
9 Correct 144 ms 30408 KB Output is correct
10 Correct 123 ms 30352 KB Output is correct
11 Correct 120 ms 30360 KB Output is correct
12 Correct 125 ms 30336 KB Output is correct
13 Correct 123 ms 30392 KB Output is correct
14 Correct 131 ms 30344 KB Output is correct
15 Correct 122 ms 30352 KB Output is correct
16 Correct 121 ms 30316 KB Output is correct
17 Correct 122 ms 30360 KB Output is correct
18 Correct 123 ms 30444 KB Output is correct
19 Correct 121 ms 30344 KB Output is correct
20 Correct 118 ms 30336 KB Output is correct
21 Correct 121 ms 30416 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 2644 KB Output is correct
2 Correct 5 ms 2908 KB Output is correct
3 Correct 4 ms 2900 KB Output is correct
4 Correct 4 ms 2900 KB Output is correct
5 Correct 4 ms 2900 KB Output is correct
6 Correct 4 ms 2900 KB Output is correct
7 Correct 5 ms 2900 KB Output is correct
8 Correct 4 ms 2900 KB Output is correct
9 Correct 4 ms 2900 KB Output is correct
10 Correct 4 ms 2900 KB Output is correct
11 Correct 4 ms 2900 KB Output is correct
12 Correct 4 ms 2900 KB Output is correct
13 Correct 4 ms 2900 KB Output is correct
14 Correct 5 ms 2900 KB Output is correct
15 Correct 3 ms 2644 KB Output is correct
16 Correct 4 ms 2892 KB Output is correct
17 Correct 5 ms 2900 KB Output is correct
18 Correct 4 ms 2900 KB Output is correct
19 Correct 4 ms 2900 KB Output is correct
20 Correct 5 ms 2900 KB Output is correct
21 Correct 5 ms 2900 KB Output is correct
22 Correct 4 ms 2900 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 2644 KB Output is correct
2 Correct 3 ms 2644 KB Output is correct
3 Correct 4 ms 2644 KB Output is correct
4 Correct 3 ms 2644 KB Output is correct
5 Correct 3 ms 2644 KB Output is correct
6 Correct 3 ms 2644 KB Output is correct
7 Correct 3 ms 2644 KB Output is correct
8 Correct 3 ms 2644 KB Output is correct
9 Correct 3 ms 2624 KB Output is correct
10 Correct 3 ms 2644 KB Output is correct
11 Correct 3 ms 2632 KB Output is correct
12 Correct 4 ms 2644 KB Output is correct
13 Correct 3 ms 2688 KB Output is correct
14 Correct 3 ms 2644 KB Output is correct
15 Correct 3 ms 2644 KB Output is correct
16 Correct 3 ms 2576 KB Output is correct
17 Correct 4 ms 2644 KB Output is correct
18 Correct 3 ms 2620 KB Output is correct
19 Correct 3 ms 2644 KB Output is correct
20 Correct 3 ms 2644 KB Output is correct
21 Correct 3 ms 2644 KB Output is correct
22 Correct 4 ms 2624 KB Output is correct
23 Correct 3 ms 2644 KB Output is correct
24 Correct 3 ms 2644 KB Output is correct
25 Correct 3 ms 2644 KB Output is correct
26 Correct 5 ms 2908 KB Output is correct
27 Correct 4 ms 2900 KB Output is correct
28 Correct 4 ms 2900 KB Output is correct
29 Correct 4 ms 2900 KB Output is correct
30 Correct 4 ms 2900 KB Output is correct
31 Correct 5 ms 2900 KB Output is correct
32 Correct 4 ms 2900 KB Output is correct
33 Correct 4 ms 2900 KB Output is correct
34 Correct 4 ms 2900 KB Output is correct
35 Correct 4 ms 2900 KB Output is correct
36 Correct 4 ms 2900 KB Output is correct
37 Correct 4 ms 2900 KB Output is correct
38 Correct 5 ms 2900 KB Output is correct
39 Correct 3 ms 2644 KB Output is correct
40 Correct 4 ms 2892 KB Output is correct
41 Correct 5 ms 2900 KB Output is correct
42 Correct 4 ms 2900 KB Output is correct
43 Correct 4 ms 2900 KB Output is correct
44 Correct 5 ms 2900 KB Output is correct
45 Correct 5 ms 2900 KB Output is correct
46 Correct 4 ms 2900 KB Output is correct
47 Correct 3 ms 2636 KB Output is correct
48 Correct 4 ms 2900 KB Output is correct
49 Correct 4 ms 2944 KB Output is correct
50 Correct 4 ms 2900 KB Output is correct
51 Correct 4 ms 2900 KB Output is correct
52 Correct 4 ms 2896 KB Output is correct
53 Correct 4 ms 2892 KB Output is correct
54 Correct 4 ms 2984 KB Output is correct
55 Correct 4 ms 2900 KB Output is correct
56 Correct 4 ms 2900 KB Output is correct
57 Correct 4 ms 2900 KB Output is correct
58 Correct 4 ms 2900 KB Output is correct
59 Correct 4 ms 2944 KB Output is correct
60 Correct 4 ms 2900 KB Output is correct
61 Correct 3 ms 2628 KB Output is correct
62 Correct 4 ms 2900 KB Output is correct
63 Correct 4 ms 2900 KB Output is correct
64 Correct 4 ms 2900 KB Output is correct
65 Correct 4 ms 2896 KB Output is correct
66 Correct 5 ms 2944 KB Output is correct
67 Correct 5 ms 2900 KB Output is correct
68 Correct 5 ms 2900 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 2644 KB Output is correct
2 Correct 121 ms 30352 KB Output is correct
3 Correct 120 ms 30440 KB Output is correct
4 Correct 132 ms 30344 KB Output is correct
5 Correct 123 ms 30344 KB Output is correct
6 Correct 123 ms 30364 KB Output is correct
7 Correct 146 ms 30324 KB Output is correct
8 Correct 131 ms 30356 KB Output is correct
9 Correct 144 ms 30408 KB Output is correct
10 Correct 123 ms 30352 KB Output is correct
11 Correct 120 ms 30360 KB Output is correct
12 Correct 125 ms 30336 KB Output is correct
13 Correct 123 ms 30392 KB Output is correct
14 Correct 131 ms 30344 KB Output is correct
15 Correct 122 ms 30352 KB Output is correct
16 Correct 121 ms 30316 KB Output is correct
17 Correct 122 ms 30360 KB Output is correct
18 Correct 123 ms 30444 KB Output is correct
19 Correct 121 ms 30344 KB Output is correct
20 Correct 118 ms 30336 KB Output is correct
21 Correct 121 ms 30416 KB Output is correct
22 Correct 3 ms 2644 KB Output is correct
23 Correct 5 ms 2908 KB Output is correct
24 Correct 4 ms 2900 KB Output is correct
25 Correct 4 ms 2900 KB Output is correct
26 Correct 4 ms 2900 KB Output is correct
27 Correct 4 ms 2900 KB Output is correct
28 Correct 5 ms 2900 KB Output is correct
29 Correct 4 ms 2900 KB Output is correct
30 Correct 4 ms 2900 KB Output is correct
31 Correct 4 ms 2900 KB Output is correct
32 Correct 4 ms 2900 KB Output is correct
33 Correct 4 ms 2900 KB Output is correct
34 Correct 4 ms 2900 KB Output is correct
35 Correct 5 ms 2900 KB Output is correct
36 Correct 3 ms 2644 KB Output is correct
37 Correct 4 ms 2892 KB Output is correct
38 Correct 5 ms 2900 KB Output is correct
39 Correct 4 ms 2900 KB Output is correct
40 Correct 4 ms 2900 KB Output is correct
41 Correct 5 ms 2900 KB Output is correct
42 Correct 5 ms 2900 KB Output is correct
43 Correct 4 ms 2900 KB Output is correct
44 Correct 3 ms 2644 KB Output is correct
45 Correct 295 ms 30436 KB Output is correct
46 Correct 302 ms 30348 KB Output is correct
47 Correct 281 ms 30344 KB Output is correct
48 Correct 283 ms 30376 KB Output is correct
49 Correct 300 ms 30352 KB Output is correct
50 Correct 275 ms 30348 KB Output is correct
51 Correct 303 ms 30344 KB Output is correct
52 Correct 317 ms 30348 KB Output is correct
53 Correct 321 ms 30352 KB Output is correct
54 Correct 318 ms 30344 KB Output is correct
55 Correct 331 ms 30344 KB Output is correct
56 Correct 313 ms 30396 KB Output is correct
57 Correct 352 ms 30336 KB Output is correct
58 Correct 4 ms 2644 KB Output is correct
59 Correct 285 ms 30348 KB Output is correct
60 Correct 323 ms 30348 KB Output is correct
61 Correct 298 ms 30344 KB Output is correct
62 Correct 279 ms 30352 KB Output is correct
63 Correct 321 ms 30352 KB Output is correct
64 Correct 333 ms 30348 KB Output is correct
65 Correct 301 ms 30424 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 2644 KB Output is correct
2 Correct 3 ms 2644 KB Output is correct
3 Correct 4 ms 2644 KB Output is correct
4 Correct 3 ms 2644 KB Output is correct
5 Correct 3 ms 2644 KB Output is correct
6 Correct 3 ms 2644 KB Output is correct
7 Correct 3 ms 2644 KB Output is correct
8 Correct 3 ms 2644 KB Output is correct
9 Correct 3 ms 2624 KB Output is correct
10 Correct 3 ms 2644 KB Output is correct
11 Correct 3 ms 2632 KB Output is correct
12 Correct 4 ms 2644 KB Output is correct
13 Correct 3 ms 2688 KB Output is correct
14 Correct 3 ms 2644 KB Output is correct
15 Correct 3 ms 2644 KB Output is correct
16 Correct 3 ms 2576 KB Output is correct
17 Correct 4 ms 2644 KB Output is correct
18 Correct 3 ms 2620 KB Output is correct
19 Correct 3 ms 2644 KB Output is correct
20 Correct 3 ms 2644 KB Output is correct
21 Correct 3 ms 2644 KB Output is correct
22 Correct 4 ms 2624 KB Output is correct
23 Correct 3 ms 2644 KB Output is correct
24 Correct 3 ms 2644 KB Output is correct
25 Correct 3 ms 2644 KB Output is correct
26 Correct 131 ms 31300 KB Output is correct
27 Correct 128 ms 31308 KB Output is correct
28 Correct 166 ms 31312 KB Output is correct
29 Correct 134 ms 31308 KB Output is correct
30 Correct 129 ms 31308 KB Output is correct
31 Correct 125 ms 31360 KB Output is correct
32 Correct 129 ms 31364 KB Output is correct
33 Correct 127 ms 31404 KB Output is correct
34 Correct 129 ms 31304 KB Output is correct
35 Correct 127 ms 31308 KB Output is correct
36 Correct 128 ms 31404 KB Output is correct
37 Correct 128 ms 31312 KB Output is correct
38 Correct 128 ms 31360 KB Output is correct
39 Correct 125 ms 31404 KB Output is correct
40 Correct 129 ms 31368 KB Output is correct
41 Correct 128 ms 31312 KB Output is correct
42 Correct 127 ms 31400 KB Output is correct
43 Correct 130 ms 31392 KB Output is correct
44 Correct 128 ms 31392 KB Output is correct
45 Correct 133 ms 31368 KB Output is correct
46 Correct 3 ms 2644 KB Output is correct
47 Correct 121 ms 30352 KB Output is correct
48 Correct 120 ms 30440 KB Output is correct
49 Correct 132 ms 30344 KB Output is correct
50 Correct 123 ms 30344 KB Output is correct
51 Correct 123 ms 30364 KB Output is correct
52 Correct 146 ms 30324 KB Output is correct
53 Correct 131 ms 30356 KB Output is correct
54 Correct 144 ms 30408 KB Output is correct
55 Correct 123 ms 30352 KB Output is correct
56 Correct 120 ms 30360 KB Output is correct
57 Correct 125 ms 30336 KB Output is correct
58 Correct 123 ms 30392 KB Output is correct
59 Correct 131 ms 30344 KB Output is correct
60 Correct 122 ms 30352 KB Output is correct
61 Correct 121 ms 30316 KB Output is correct
62 Correct 122 ms 30360 KB Output is correct
63 Correct 123 ms 30444 KB Output is correct
64 Correct 121 ms 30344 KB Output is correct
65 Correct 118 ms 30336 KB Output is correct
66 Correct 121 ms 30416 KB Output is correct
67 Correct 3 ms 2644 KB Output is correct
68 Correct 5 ms 2908 KB Output is correct
69 Correct 4 ms 2900 KB Output is correct
70 Correct 4 ms 2900 KB Output is correct
71 Correct 4 ms 2900 KB Output is correct
72 Correct 4 ms 2900 KB Output is correct
73 Correct 5 ms 2900 KB Output is correct
74 Correct 4 ms 2900 KB Output is correct
75 Correct 4 ms 2900 KB Output is correct
76 Correct 4 ms 2900 KB Output is correct
77 Correct 4 ms 2900 KB Output is correct
78 Correct 4 ms 2900 KB Output is correct
79 Correct 4 ms 2900 KB Output is correct
80 Correct 5 ms 2900 KB Output is correct
81 Correct 3 ms 2644 KB Output is correct
82 Correct 4 ms 2892 KB Output is correct
83 Correct 5 ms 2900 KB Output is correct
84 Correct 4 ms 2900 KB Output is correct
85 Correct 4 ms 2900 KB Output is correct
86 Correct 5 ms 2900 KB Output is correct
87 Correct 5 ms 2900 KB Output is correct
88 Correct 4 ms 2900 KB Output is correct
89 Correct 3 ms 2636 KB Output is correct
90 Correct 4 ms 2900 KB Output is correct
91 Correct 4 ms 2944 KB Output is correct
92 Correct 4 ms 2900 KB Output is correct
93 Correct 4 ms 2900 KB Output is correct
94 Correct 4 ms 2896 KB Output is correct
95 Correct 4 ms 2892 KB Output is correct
96 Correct 4 ms 2984 KB Output is correct
97 Correct 4 ms 2900 KB Output is correct
98 Correct 4 ms 2900 KB Output is correct
99 Correct 4 ms 2900 KB Output is correct
100 Correct 4 ms 2900 KB Output is correct
101 Correct 4 ms 2944 KB Output is correct
102 Correct 4 ms 2900 KB Output is correct
103 Correct 3 ms 2628 KB Output is correct
104 Correct 4 ms 2900 KB Output is correct
105 Correct 4 ms 2900 KB Output is correct
106 Correct 4 ms 2900 KB Output is correct
107 Correct 4 ms 2896 KB Output is correct
108 Correct 5 ms 2944 KB Output is correct
109 Correct 5 ms 2900 KB Output is correct
110 Correct 5 ms 2900 KB Output is correct
111 Correct 3 ms 2644 KB Output is correct
112 Correct 295 ms 30436 KB Output is correct
113 Correct 302 ms 30348 KB Output is correct
114 Correct 281 ms 30344 KB Output is correct
115 Correct 283 ms 30376 KB Output is correct
116 Correct 300 ms 30352 KB Output is correct
117 Correct 275 ms 30348 KB Output is correct
118 Correct 303 ms 30344 KB Output is correct
119 Correct 317 ms 30348 KB Output is correct
120 Correct 321 ms 30352 KB Output is correct
121 Correct 318 ms 30344 KB Output is correct
122 Correct 331 ms 30344 KB Output is correct
123 Correct 313 ms 30396 KB Output is correct
124 Correct 352 ms 30336 KB Output is correct
125 Correct 4 ms 2644 KB Output is correct
126 Correct 285 ms 30348 KB Output is correct
127 Correct 323 ms 30348 KB Output is correct
128 Correct 298 ms 30344 KB Output is correct
129 Correct 279 ms 30352 KB Output is correct
130 Correct 321 ms 30352 KB Output is correct
131 Correct 333 ms 30348 KB Output is correct
132 Correct 301 ms 30424 KB Output is correct
133 Correct 3 ms 2632 KB Output is correct
134 Correct 339 ms 31308 KB Output is correct
135 Correct 369 ms 31304 KB Output is correct
136 Correct 360 ms 31308 KB Output is correct
137 Correct 333 ms 31336 KB Output is correct
138 Correct 351 ms 31288 KB Output is correct
139 Correct 288 ms 31308 KB Output is correct
140 Correct 260 ms 31344 KB Output is correct
141 Correct 348 ms 31292 KB Output is correct
142 Correct 387 ms 31312 KB Output is correct
143 Correct 342 ms 31332 KB Output is correct
144 Correct 338 ms 31316 KB Output is correct
145 Correct 347 ms 31312 KB Output is correct
146 Correct 351 ms 31284 KB Output is correct
147 Correct 3 ms 2644 KB Output is correct
148 Correct 302 ms 31312 KB Output is correct
149 Correct 369 ms 31308 KB Output is correct
150 Correct 369 ms 31364 KB Output is correct
151 Correct 321 ms 31336 KB Output is correct
152 Correct 344 ms 31308 KB Output is correct
153 Correct 290 ms 31340 KB Output is correct
154 Correct 347 ms 31284 KB Output is correct