답안 #798244

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
798244 2023-07-30T14:08:28 Z vjudge1 Cryptography (NOI20_crypto) C++17
100 / 100
360 ms 39644 KB
#include <bits/stdc++.h>
using namespace std;
#define futaba ios_base::sync_with_stdio(false); cin.tie(NULL);
#define rio return 0;
#define ll long long

const ll mod = 1e9 + 7;

// Fun things are fun. //

ll a[300005], b[300005], fac[300005], seg[1200005];

ll merge(ll a, ll b) {
    return a + b;
}

void build(int l, int r, int v) {
    if(l == r) seg[v] = 1;
    else {
        int mid = l + (r - l) / 2;
        build(l, mid, 2 * v);
        build(mid + 1, r, (2 * v) + 1);
        seg[v] = merge(seg[2 * v], seg[(2 * v) + 1]);
    }
}

void update(int l, int r, int v, int pos) {
    if(l == r) seg[v] = 0;
    else {
        int mid = l + (r - l) / 2;
        if(pos <= mid) update(l, mid, 2 * v, pos);
        else update(mid + 1, r, (2 * v) + 1, pos);
        seg[v]--; 
    }
}

ll query(int l, int r, int v, int lq, int rq) {
    if(lq <= l and r <= rq) return seg[v];
    if(lq > r or rq < l) return 0;
    int mid = l + (r - l) / 2;
    return merge(query(l, mid, 2 * v, lq, rq), query(mid + 1, r, (2 * v) + 1, lq, rq));
}

int main() {
    /* freopen(".txt", "r", stdin);
    freopen(".txt", "w", stdout); */
    futaba
    int n;
    cin >> n;
    for(int i = 1; i <= n; i++) {
        cin >> a[i];
        b[i] = a[i];
    }
    sort(b + 1, b + n + 1);
    map<ll, int> mp;
    for(int i = 1; i <= n; i++) mp[b[i]] = i;
    vector<ll> v(n + 1);
    for(int i = 1; i <= n; i++) v[i] = mp[a[i]];
    fac[0] = 1;
    for(int i = 1; i <= n; i++) fac[i] = (fac[i - 1] * i) % mod;
    build(1, n, 1);
    ll ans = 1;
    for(int i = 1; i <= n; i++) {
        ans += fac[n - i] * query(1, n, 1, 1, v[i] - 1);
        ans %= mod;
        update(1, n, 1, v[i]);
    }
    if(ans < 0) ans += mod;
    cout << ans << '\n';
    rio
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 0 ms 328 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 0 ms 332 KB Output is correct
13 Correct 0 ms 332 KB Output is correct
14 Correct 0 ms 340 KB Output is correct
15 Correct 0 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 0 ms 332 KB Output is correct
18 Correct 0 ms 324 KB Output is correct
19 Correct 0 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 0 ms 340 KB Output is correct
22 Correct 0 ms 328 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 0 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 161 ms 39604 KB Output is correct
3 Correct 161 ms 39508 KB Output is correct
4 Correct 165 ms 39500 KB Output is correct
5 Correct 170 ms 39604 KB Output is correct
6 Correct 165 ms 39512 KB Output is correct
7 Correct 174 ms 39580 KB Output is correct
8 Correct 164 ms 39496 KB Output is correct
9 Correct 158 ms 39508 KB Output is correct
10 Correct 167 ms 39556 KB Output is correct
11 Correct 163 ms 39564 KB Output is correct
12 Correct 175 ms 39552 KB Output is correct
13 Correct 179 ms 39492 KB Output is correct
14 Correct 168 ms 39560 KB Output is correct
15 Correct 169 ms 39556 KB Output is correct
16 Correct 204 ms 39500 KB Output is correct
17 Correct 190 ms 39596 KB Output is correct
18 Correct 158 ms 39560 KB Output is correct
19 Correct 169 ms 39552 KB Output is correct
20 Correct 164 ms 39560 KB Output is correct
21 Correct 169 ms 39520 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 166 ms 38652 KB Output is correct
3 Correct 158 ms 38552 KB Output is correct
4 Correct 158 ms 38604 KB Output is correct
5 Correct 159 ms 38640 KB Output is correct
6 Correct 156 ms 38584 KB Output is correct
7 Correct 155 ms 38592 KB Output is correct
8 Correct 156 ms 38584 KB Output is correct
9 Correct 158 ms 38624 KB Output is correct
10 Correct 154 ms 38600 KB Output is correct
11 Correct 155 ms 38600 KB Output is correct
12 Correct 154 ms 38636 KB Output is correct
13 Correct 159 ms 38680 KB Output is correct
14 Correct 157 ms 38576 KB Output is correct
15 Correct 165 ms 38568 KB Output is correct
16 Correct 156 ms 38600 KB Output is correct
17 Correct 156 ms 38632 KB Output is correct
18 Correct 155 ms 38576 KB Output is correct
19 Correct 155 ms 38568 KB Output is correct
20 Correct 155 ms 38616 KB Output is correct
21 Correct 156 ms 38724 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 2 ms 596 KB Output is correct
3 Correct 2 ms 596 KB Output is correct
4 Correct 2 ms 596 KB Output is correct
5 Correct 2 ms 596 KB Output is correct
6 Correct 2 ms 596 KB Output is correct
7 Correct 2 ms 596 KB Output is correct
8 Correct 2 ms 596 KB Output is correct
9 Correct 2 ms 596 KB Output is correct
10 Correct 2 ms 596 KB Output is correct
11 Correct 2 ms 596 KB Output is correct
12 Correct 2 ms 684 KB Output is correct
13 Correct 2 ms 596 KB Output is correct
14 Correct 2 ms 596 KB Output is correct
15 Correct 0 ms 340 KB Output is correct
16 Correct 2 ms 596 KB Output is correct
17 Correct 2 ms 596 KB Output is correct
18 Correct 2 ms 596 KB Output is correct
19 Correct 2 ms 596 KB Output is correct
20 Correct 3 ms 596 KB Output is correct
21 Correct 2 ms 596 KB Output is correct
22 Correct 2 ms 596 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 0 ms 328 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 0 ms 332 KB Output is correct
13 Correct 0 ms 332 KB Output is correct
14 Correct 0 ms 340 KB Output is correct
15 Correct 0 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 0 ms 332 KB Output is correct
18 Correct 0 ms 324 KB Output is correct
19 Correct 0 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 0 ms 340 KB Output is correct
22 Correct 0 ms 328 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 0 ms 340 KB Output is correct
25 Correct 0 ms 340 KB Output is correct
26 Correct 2 ms 596 KB Output is correct
27 Correct 2 ms 596 KB Output is correct
28 Correct 2 ms 596 KB Output is correct
29 Correct 2 ms 596 KB Output is correct
30 Correct 2 ms 596 KB Output is correct
31 Correct 2 ms 596 KB Output is correct
32 Correct 2 ms 596 KB Output is correct
33 Correct 2 ms 596 KB Output is correct
34 Correct 2 ms 596 KB Output is correct
35 Correct 2 ms 596 KB Output is correct
36 Correct 2 ms 684 KB Output is correct
37 Correct 2 ms 596 KB Output is correct
38 Correct 2 ms 596 KB Output is correct
39 Correct 0 ms 340 KB Output is correct
40 Correct 2 ms 596 KB Output is correct
41 Correct 2 ms 596 KB Output is correct
42 Correct 2 ms 596 KB Output is correct
43 Correct 2 ms 596 KB Output is correct
44 Correct 3 ms 596 KB Output is correct
45 Correct 2 ms 596 KB Output is correct
46 Correct 2 ms 596 KB Output is correct
47 Correct 0 ms 340 KB Output is correct
48 Correct 2 ms 724 KB Output is correct
49 Correct 2 ms 728 KB Output is correct
50 Correct 2 ms 724 KB Output is correct
51 Correct 2 ms 596 KB Output is correct
52 Correct 2 ms 724 KB Output is correct
53 Correct 2 ms 724 KB Output is correct
54 Correct 2 ms 724 KB Output is correct
55 Correct 2 ms 692 KB Output is correct
56 Correct 2 ms 724 KB Output is correct
57 Correct 2 ms 596 KB Output is correct
58 Correct 2 ms 596 KB Output is correct
59 Correct 2 ms 724 KB Output is correct
60 Correct 2 ms 724 KB Output is correct
61 Correct 0 ms 332 KB Output is correct
62 Correct 2 ms 724 KB Output is correct
63 Correct 2 ms 724 KB Output is correct
64 Correct 2 ms 724 KB Output is correct
65 Correct 2 ms 724 KB Output is correct
66 Correct 2 ms 596 KB Output is correct
67 Correct 2 ms 724 KB Output is correct
68 Correct 2 ms 724 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 166 ms 38652 KB Output is correct
3 Correct 158 ms 38552 KB Output is correct
4 Correct 158 ms 38604 KB Output is correct
5 Correct 159 ms 38640 KB Output is correct
6 Correct 156 ms 38584 KB Output is correct
7 Correct 155 ms 38592 KB Output is correct
8 Correct 156 ms 38584 KB Output is correct
9 Correct 158 ms 38624 KB Output is correct
10 Correct 154 ms 38600 KB Output is correct
11 Correct 155 ms 38600 KB Output is correct
12 Correct 154 ms 38636 KB Output is correct
13 Correct 159 ms 38680 KB Output is correct
14 Correct 157 ms 38576 KB Output is correct
15 Correct 165 ms 38568 KB Output is correct
16 Correct 156 ms 38600 KB Output is correct
17 Correct 156 ms 38632 KB Output is correct
18 Correct 155 ms 38576 KB Output is correct
19 Correct 155 ms 38568 KB Output is correct
20 Correct 155 ms 38616 KB Output is correct
21 Correct 156 ms 38724 KB Output is correct
22 Correct 0 ms 340 KB Output is correct
23 Correct 2 ms 596 KB Output is correct
24 Correct 2 ms 596 KB Output is correct
25 Correct 2 ms 596 KB Output is correct
26 Correct 2 ms 596 KB Output is correct
27 Correct 2 ms 596 KB Output is correct
28 Correct 2 ms 596 KB Output is correct
29 Correct 2 ms 596 KB Output is correct
30 Correct 2 ms 596 KB Output is correct
31 Correct 2 ms 596 KB Output is correct
32 Correct 2 ms 596 KB Output is correct
33 Correct 2 ms 684 KB Output is correct
34 Correct 2 ms 596 KB Output is correct
35 Correct 2 ms 596 KB Output is correct
36 Correct 0 ms 340 KB Output is correct
37 Correct 2 ms 596 KB Output is correct
38 Correct 2 ms 596 KB Output is correct
39 Correct 2 ms 596 KB Output is correct
40 Correct 2 ms 596 KB Output is correct
41 Correct 3 ms 596 KB Output is correct
42 Correct 2 ms 596 KB Output is correct
43 Correct 2 ms 596 KB Output is correct
44 Correct 1 ms 340 KB Output is correct
45 Correct 342 ms 38596 KB Output is correct
46 Correct 336 ms 38600 KB Output is correct
47 Correct 321 ms 38584 KB Output is correct
48 Correct 323 ms 38536 KB Output is correct
49 Correct 360 ms 38600 KB Output is correct
50 Correct 348 ms 38600 KB Output is correct
51 Correct 322 ms 38596 KB Output is correct
52 Correct 315 ms 38608 KB Output is correct
53 Correct 325 ms 38716 KB Output is correct
54 Correct 332 ms 38548 KB Output is correct
55 Correct 334 ms 38656 KB Output is correct
56 Correct 314 ms 38628 KB Output is correct
57 Correct 323 ms 38580 KB Output is correct
58 Correct 0 ms 340 KB Output is correct
59 Correct 310 ms 38544 KB Output is correct
60 Correct 320 ms 38604 KB Output is correct
61 Correct 356 ms 38608 KB Output is correct
62 Correct 326 ms 38580 KB Output is correct
63 Correct 351 ms 38676 KB Output is correct
64 Correct 321 ms 38608 KB Output is correct
65 Correct 333 ms 38608 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 0 ms 328 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 0 ms 332 KB Output is correct
13 Correct 0 ms 332 KB Output is correct
14 Correct 0 ms 340 KB Output is correct
15 Correct 0 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 0 ms 332 KB Output is correct
18 Correct 0 ms 324 KB Output is correct
19 Correct 0 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 0 ms 340 KB Output is correct
22 Correct 0 ms 328 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 0 ms 340 KB Output is correct
25 Correct 0 ms 332 KB Output is correct
26 Correct 161 ms 39604 KB Output is correct
27 Correct 161 ms 39508 KB Output is correct
28 Correct 165 ms 39500 KB Output is correct
29 Correct 170 ms 39604 KB Output is correct
30 Correct 165 ms 39512 KB Output is correct
31 Correct 174 ms 39580 KB Output is correct
32 Correct 164 ms 39496 KB Output is correct
33 Correct 158 ms 39508 KB Output is correct
34 Correct 167 ms 39556 KB Output is correct
35 Correct 163 ms 39564 KB Output is correct
36 Correct 175 ms 39552 KB Output is correct
37 Correct 179 ms 39492 KB Output is correct
38 Correct 168 ms 39560 KB Output is correct
39 Correct 169 ms 39556 KB Output is correct
40 Correct 204 ms 39500 KB Output is correct
41 Correct 190 ms 39596 KB Output is correct
42 Correct 158 ms 39560 KB Output is correct
43 Correct 169 ms 39552 KB Output is correct
44 Correct 164 ms 39560 KB Output is correct
45 Correct 169 ms 39520 KB Output is correct
46 Correct 1 ms 340 KB Output is correct
47 Correct 166 ms 38652 KB Output is correct
48 Correct 158 ms 38552 KB Output is correct
49 Correct 158 ms 38604 KB Output is correct
50 Correct 159 ms 38640 KB Output is correct
51 Correct 156 ms 38584 KB Output is correct
52 Correct 155 ms 38592 KB Output is correct
53 Correct 156 ms 38584 KB Output is correct
54 Correct 158 ms 38624 KB Output is correct
55 Correct 154 ms 38600 KB Output is correct
56 Correct 155 ms 38600 KB Output is correct
57 Correct 154 ms 38636 KB Output is correct
58 Correct 159 ms 38680 KB Output is correct
59 Correct 157 ms 38576 KB Output is correct
60 Correct 165 ms 38568 KB Output is correct
61 Correct 156 ms 38600 KB Output is correct
62 Correct 156 ms 38632 KB Output is correct
63 Correct 155 ms 38576 KB Output is correct
64 Correct 155 ms 38568 KB Output is correct
65 Correct 155 ms 38616 KB Output is correct
66 Correct 156 ms 38724 KB Output is correct
67 Correct 0 ms 340 KB Output is correct
68 Correct 2 ms 596 KB Output is correct
69 Correct 2 ms 596 KB Output is correct
70 Correct 2 ms 596 KB Output is correct
71 Correct 2 ms 596 KB Output is correct
72 Correct 2 ms 596 KB Output is correct
73 Correct 2 ms 596 KB Output is correct
74 Correct 2 ms 596 KB Output is correct
75 Correct 2 ms 596 KB Output is correct
76 Correct 2 ms 596 KB Output is correct
77 Correct 2 ms 596 KB Output is correct
78 Correct 2 ms 684 KB Output is correct
79 Correct 2 ms 596 KB Output is correct
80 Correct 2 ms 596 KB Output is correct
81 Correct 0 ms 340 KB Output is correct
82 Correct 2 ms 596 KB Output is correct
83 Correct 2 ms 596 KB Output is correct
84 Correct 2 ms 596 KB Output is correct
85 Correct 2 ms 596 KB Output is correct
86 Correct 3 ms 596 KB Output is correct
87 Correct 2 ms 596 KB Output is correct
88 Correct 2 ms 596 KB Output is correct
89 Correct 0 ms 340 KB Output is correct
90 Correct 2 ms 724 KB Output is correct
91 Correct 2 ms 728 KB Output is correct
92 Correct 2 ms 724 KB Output is correct
93 Correct 2 ms 596 KB Output is correct
94 Correct 2 ms 724 KB Output is correct
95 Correct 2 ms 724 KB Output is correct
96 Correct 2 ms 724 KB Output is correct
97 Correct 2 ms 692 KB Output is correct
98 Correct 2 ms 724 KB Output is correct
99 Correct 2 ms 596 KB Output is correct
100 Correct 2 ms 596 KB Output is correct
101 Correct 2 ms 724 KB Output is correct
102 Correct 2 ms 724 KB Output is correct
103 Correct 0 ms 332 KB Output is correct
104 Correct 2 ms 724 KB Output is correct
105 Correct 2 ms 724 KB Output is correct
106 Correct 2 ms 724 KB Output is correct
107 Correct 2 ms 724 KB Output is correct
108 Correct 2 ms 596 KB Output is correct
109 Correct 2 ms 724 KB Output is correct
110 Correct 2 ms 724 KB Output is correct
111 Correct 1 ms 340 KB Output is correct
112 Correct 342 ms 38596 KB Output is correct
113 Correct 336 ms 38600 KB Output is correct
114 Correct 321 ms 38584 KB Output is correct
115 Correct 323 ms 38536 KB Output is correct
116 Correct 360 ms 38600 KB Output is correct
117 Correct 348 ms 38600 KB Output is correct
118 Correct 322 ms 38596 KB Output is correct
119 Correct 315 ms 38608 KB Output is correct
120 Correct 325 ms 38716 KB Output is correct
121 Correct 332 ms 38548 KB Output is correct
122 Correct 334 ms 38656 KB Output is correct
123 Correct 314 ms 38628 KB Output is correct
124 Correct 323 ms 38580 KB Output is correct
125 Correct 0 ms 340 KB Output is correct
126 Correct 310 ms 38544 KB Output is correct
127 Correct 320 ms 38604 KB Output is correct
128 Correct 356 ms 38608 KB Output is correct
129 Correct 326 ms 38580 KB Output is correct
130 Correct 351 ms 38676 KB Output is correct
131 Correct 321 ms 38608 KB Output is correct
132 Correct 333 ms 38608 KB Output is correct
133 Correct 0 ms 340 KB Output is correct
134 Correct 352 ms 39496 KB Output is correct
135 Correct 322 ms 39572 KB Output is correct
136 Correct 323 ms 39528 KB Output is correct
137 Correct 325 ms 39552 KB Output is correct
138 Correct 329 ms 39624 KB Output is correct
139 Correct 345 ms 39560 KB Output is correct
140 Correct 345 ms 39564 KB Output is correct
141 Correct 332 ms 39532 KB Output is correct
142 Correct 339 ms 39644 KB Output is correct
143 Correct 331 ms 39500 KB Output is correct
144 Correct 332 ms 39576 KB Output is correct
145 Correct 332 ms 39528 KB Output is correct
146 Correct 323 ms 39584 KB Output is correct
147 Correct 1 ms 340 KB Output is correct
148 Correct 339 ms 39556 KB Output is correct
149 Correct 322 ms 39540 KB Output is correct
150 Correct 331 ms 39644 KB Output is correct
151 Correct 328 ms 39532 KB Output is correct
152 Correct 336 ms 39628 KB Output is correct
153 Correct 329 ms 39528 KB Output is correct
154 Correct 360 ms 39564 KB Output is correct