답안 #795733

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
795733 2023-07-27T13:49:02 Z vjudge1 Cryptography (NOI20_crypto) C++17
100 / 100
334 ms 26220 KB
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define ull unsigned long long
#define fi first
#define se second

const int N = 3e5 + 5;
const int mod = 1e9 + 7;

ll fact[N];
int n, a[N], b[N];
map<int, int> m;

struct segtree {

    int st[4 * N];

    void build(int x, int tl, int tr) {
        if (tl == tr) st[x] = 1;
        else {
            int tm = (tl + tr) / 2;
            build(2 * x, tl, tm);
            build(2 * x + 1, tm + 1, tr);
            st[x] = st[2 * x] + st[2 * x + 1];
        }
    }

    void update(int x, int tl, int tr, int pos) {
        if (tl == tr) st[x] = 0;
        else {
            int tm = (tl + tr) / 2;
            if (pos <= tm) update(2 * x, tl, tm, pos);
            else update(2 * x + 1, tm + 1, tr, pos);
            st[x]--;
        }
    }

    int get(int x, int tl, int tr, int l, int r) {
        if (l <= tl and tr <= r) return st[x];
        if (l > tr or r < tl) return 0;
        int tm = (tl + tr) / 2;
        return get(2 * x, tl, tm, l, r) + get(2 * x + 1, tm + 1, tr, l, r);
    }

} t;

int main() { 
    ios_base::sync_with_stdio(false); cin.tie(NULL);
    ll ans = 0;
    cin >> n;
    fact[0] = 1;
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
        b[i] = a[i], fact[i] = (fact[i - 1] * i) % mod;;
    }
    sort(b + 1, b + n + 1);
    for (int i = 1; i <= n; i++) m[b[i]] = i;
    for (int i = 1; i <= n; i++) a[i] = m[a[i]];
    t.build(1, 1, n);
    for (int i = 1; i <= n; i++) {
        ans += 1ll * fact[n - i] * t.get(1, 1, n, 1, a[i] - 1);
        ans %= mod;
        t.update(1, 1, n, a[i]);
    }
    cout << (ans + 1) % mod << "\n"; 
}  
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 0 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 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 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 1 ms 340 KB Output is correct
13 Correct 1 ms 340 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 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 468 KB Output is correct
20 Correct 0 ms 340 KB Output is correct
21 Correct 0 ms 344 KB Output is correct
22 Correct 0 ms 340 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 148 ms 26100 KB Output is correct
3 Correct 147 ms 26108 KB Output is correct
4 Correct 153 ms 26188 KB Output is correct
5 Correct 147 ms 26104 KB Output is correct
6 Correct 146 ms 26060 KB Output is correct
7 Correct 145 ms 26108 KB Output is correct
8 Correct 155 ms 26112 KB Output is correct
9 Correct 148 ms 26100 KB Output is correct
10 Correct 144 ms 25984 KB Output is correct
11 Correct 160 ms 26108 KB Output is correct
12 Correct 153 ms 25992 KB Output is correct
13 Correct 147 ms 26052 KB Output is correct
14 Correct 144 ms 26112 KB Output is correct
15 Correct 147 ms 26072 KB Output is correct
16 Correct 162 ms 26032 KB Output is correct
17 Correct 143 ms 25996 KB Output is correct
18 Correct 143 ms 26060 KB Output is correct
19 Correct 149 ms 26024 KB Output is correct
20 Correct 147 ms 26108 KB Output is correct
21 Correct 144 ms 26112 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 141 ms 25140 KB Output is correct
3 Correct 143 ms 25276 KB Output is correct
4 Correct 141 ms 25140 KB Output is correct
5 Correct 138 ms 25036 KB Output is correct
6 Correct 138 ms 25148 KB Output is correct
7 Correct 143 ms 25144 KB Output is correct
8 Correct 141 ms 25148 KB Output is correct
9 Correct 139 ms 25060 KB Output is correct
10 Correct 140 ms 25036 KB Output is correct
11 Correct 140 ms 25152 KB Output is correct
12 Correct 138 ms 25148 KB Output is correct
13 Correct 139 ms 25148 KB Output is correct
14 Correct 138 ms 25152 KB Output is correct
15 Correct 156 ms 25036 KB Output is correct
16 Correct 139 ms 25152 KB Output is correct
17 Correct 153 ms 25088 KB Output is correct
18 Correct 139 ms 25152 KB Output is correct
19 Correct 148 ms 25040 KB Output is correct
20 Correct 140 ms 25144 KB Output is correct
21 Correct 139 ms 25156 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 2 ms 468 KB Output is correct
3 Correct 2 ms 468 KB Output is correct
4 Correct 2 ms 596 KB Output is correct
5 Correct 2 ms 476 KB Output is correct
6 Correct 2 ms 468 KB Output is correct
7 Correct 2 ms 468 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 468 KB Output is correct
12 Correct 2 ms 476 KB Output is correct
13 Correct 2 ms 468 KB Output is correct
14 Correct 2 ms 596 KB Output is correct
15 Correct 1 ms 336 KB Output is correct
16 Correct 2 ms 468 KB Output is correct
17 Correct 2 ms 468 KB Output is correct
18 Correct 2 ms 468 KB Output is correct
19 Correct 2 ms 480 KB Output is correct
20 Correct 2 ms 468 KB Output is correct
21 Correct 2 ms 468 KB Output is correct
22 Correct 2 ms 468 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 0 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 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 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 1 ms 340 KB Output is correct
13 Correct 1 ms 340 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 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 468 KB Output is correct
20 Correct 0 ms 340 KB Output is correct
21 Correct 0 ms 344 KB Output is correct
22 Correct 0 ms 340 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 0 ms 340 KB Output is correct
26 Correct 2 ms 468 KB Output is correct
27 Correct 2 ms 468 KB Output is correct
28 Correct 2 ms 596 KB Output is correct
29 Correct 2 ms 476 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 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 468 KB Output is correct
36 Correct 2 ms 476 KB Output is correct
37 Correct 2 ms 468 KB Output is correct
38 Correct 2 ms 596 KB Output is correct
39 Correct 1 ms 336 KB Output is correct
40 Correct 2 ms 468 KB Output is correct
41 Correct 2 ms 468 KB Output is correct
42 Correct 2 ms 468 KB Output is correct
43 Correct 2 ms 480 KB Output is correct
44 Correct 2 ms 468 KB Output is correct
45 Correct 2 ms 468 KB Output is correct
46 Correct 2 ms 468 KB Output is correct
47 Correct 1 ms 340 KB Output is correct
48 Correct 2 ms 596 KB Output is correct
49 Correct 2 ms 596 KB Output is correct
50 Correct 2 ms 596 KB Output is correct
51 Correct 2 ms 596 KB Output is correct
52 Correct 2 ms 596 KB Output is correct
53 Correct 2 ms 596 KB Output is correct
54 Correct 2 ms 596 KB Output is correct
55 Correct 2 ms 596 KB Output is correct
56 Correct 2 ms 596 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 524 KB Output is correct
60 Correct 2 ms 520 KB Output is correct
61 Correct 0 ms 340 KB Output is correct
62 Correct 2 ms 724 KB Output is correct
63 Correct 2 ms 476 KB Output is correct
64 Correct 2 ms 596 KB Output is correct
65 Correct 2 ms 612 KB Output is correct
66 Correct 2 ms 612 KB Output is correct
67 Correct 2 ms 596 KB Output is correct
68 Correct 2 ms 480 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 141 ms 25140 KB Output is correct
3 Correct 143 ms 25276 KB Output is correct
4 Correct 141 ms 25140 KB Output is correct
5 Correct 138 ms 25036 KB Output is correct
6 Correct 138 ms 25148 KB Output is correct
7 Correct 143 ms 25144 KB Output is correct
8 Correct 141 ms 25148 KB Output is correct
9 Correct 139 ms 25060 KB Output is correct
10 Correct 140 ms 25036 KB Output is correct
11 Correct 140 ms 25152 KB Output is correct
12 Correct 138 ms 25148 KB Output is correct
13 Correct 139 ms 25148 KB Output is correct
14 Correct 138 ms 25152 KB Output is correct
15 Correct 156 ms 25036 KB Output is correct
16 Correct 139 ms 25152 KB Output is correct
17 Correct 153 ms 25088 KB Output is correct
18 Correct 139 ms 25152 KB Output is correct
19 Correct 148 ms 25040 KB Output is correct
20 Correct 140 ms 25144 KB Output is correct
21 Correct 139 ms 25156 KB Output is correct
22 Correct 0 ms 340 KB Output is correct
23 Correct 2 ms 468 KB Output is correct
24 Correct 2 ms 468 KB Output is correct
25 Correct 2 ms 596 KB Output is correct
26 Correct 2 ms 476 KB Output is correct
27 Correct 2 ms 468 KB Output is correct
28 Correct 2 ms 468 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 468 KB Output is correct
33 Correct 2 ms 476 KB Output is correct
34 Correct 2 ms 468 KB Output is correct
35 Correct 2 ms 596 KB Output is correct
36 Correct 1 ms 336 KB Output is correct
37 Correct 2 ms 468 KB Output is correct
38 Correct 2 ms 468 KB Output is correct
39 Correct 2 ms 468 KB Output is correct
40 Correct 2 ms 480 KB Output is correct
41 Correct 2 ms 468 KB Output is correct
42 Correct 2 ms 468 KB Output is correct
43 Correct 2 ms 468 KB Output is correct
44 Correct 0 ms 344 KB Output is correct
45 Correct 269 ms 25148 KB Output is correct
46 Correct 264 ms 25144 KB Output is correct
47 Correct 284 ms 25140 KB Output is correct
48 Correct 300 ms 25156 KB Output is correct
49 Correct 253 ms 25152 KB Output is correct
50 Correct 266 ms 25180 KB Output is correct
51 Correct 260 ms 25056 KB Output is correct
52 Correct 255 ms 25152 KB Output is correct
53 Correct 253 ms 25152 KB Output is correct
54 Correct 255 ms 25152 KB Output is correct
55 Correct 273 ms 25188 KB Output is correct
56 Correct 250 ms 25028 KB Output is correct
57 Correct 257 ms 25120 KB Output is correct
58 Correct 0 ms 340 KB Output is correct
59 Correct 277 ms 25144 KB Output is correct
60 Correct 257 ms 25148 KB Output is correct
61 Correct 261 ms 25268 KB Output is correct
62 Correct 262 ms 25148 KB Output is correct
63 Correct 273 ms 25148 KB Output is correct
64 Correct 264 ms 25156 KB Output is correct
65 Correct 275 ms 25032 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 0 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 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 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 1 ms 340 KB Output is correct
13 Correct 1 ms 340 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 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 468 KB Output is correct
20 Correct 0 ms 340 KB Output is correct
21 Correct 0 ms 344 KB Output is correct
22 Correct 0 ms 340 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 148 ms 26100 KB Output is correct
27 Correct 147 ms 26108 KB Output is correct
28 Correct 153 ms 26188 KB Output is correct
29 Correct 147 ms 26104 KB Output is correct
30 Correct 146 ms 26060 KB Output is correct
31 Correct 145 ms 26108 KB Output is correct
32 Correct 155 ms 26112 KB Output is correct
33 Correct 148 ms 26100 KB Output is correct
34 Correct 144 ms 25984 KB Output is correct
35 Correct 160 ms 26108 KB Output is correct
36 Correct 153 ms 25992 KB Output is correct
37 Correct 147 ms 26052 KB Output is correct
38 Correct 144 ms 26112 KB Output is correct
39 Correct 147 ms 26072 KB Output is correct
40 Correct 162 ms 26032 KB Output is correct
41 Correct 143 ms 25996 KB Output is correct
42 Correct 143 ms 26060 KB Output is correct
43 Correct 149 ms 26024 KB Output is correct
44 Correct 147 ms 26108 KB Output is correct
45 Correct 144 ms 26112 KB Output is correct
46 Correct 0 ms 340 KB Output is correct
47 Correct 141 ms 25140 KB Output is correct
48 Correct 143 ms 25276 KB Output is correct
49 Correct 141 ms 25140 KB Output is correct
50 Correct 138 ms 25036 KB Output is correct
51 Correct 138 ms 25148 KB Output is correct
52 Correct 143 ms 25144 KB Output is correct
53 Correct 141 ms 25148 KB Output is correct
54 Correct 139 ms 25060 KB Output is correct
55 Correct 140 ms 25036 KB Output is correct
56 Correct 140 ms 25152 KB Output is correct
57 Correct 138 ms 25148 KB Output is correct
58 Correct 139 ms 25148 KB Output is correct
59 Correct 138 ms 25152 KB Output is correct
60 Correct 156 ms 25036 KB Output is correct
61 Correct 139 ms 25152 KB Output is correct
62 Correct 153 ms 25088 KB Output is correct
63 Correct 139 ms 25152 KB Output is correct
64 Correct 148 ms 25040 KB Output is correct
65 Correct 140 ms 25144 KB Output is correct
66 Correct 139 ms 25156 KB Output is correct
67 Correct 0 ms 340 KB Output is correct
68 Correct 2 ms 468 KB Output is correct
69 Correct 2 ms 468 KB Output is correct
70 Correct 2 ms 596 KB Output is correct
71 Correct 2 ms 476 KB Output is correct
72 Correct 2 ms 468 KB Output is correct
73 Correct 2 ms 468 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 468 KB Output is correct
78 Correct 2 ms 476 KB Output is correct
79 Correct 2 ms 468 KB Output is correct
80 Correct 2 ms 596 KB Output is correct
81 Correct 1 ms 336 KB Output is correct
82 Correct 2 ms 468 KB Output is correct
83 Correct 2 ms 468 KB Output is correct
84 Correct 2 ms 468 KB Output is correct
85 Correct 2 ms 480 KB Output is correct
86 Correct 2 ms 468 KB Output is correct
87 Correct 2 ms 468 KB Output is correct
88 Correct 2 ms 468 KB Output is correct
89 Correct 1 ms 340 KB Output is correct
90 Correct 2 ms 596 KB Output is correct
91 Correct 2 ms 596 KB Output is correct
92 Correct 2 ms 596 KB Output is correct
93 Correct 2 ms 596 KB Output is correct
94 Correct 2 ms 596 KB Output is correct
95 Correct 2 ms 596 KB Output is correct
96 Correct 2 ms 596 KB Output is correct
97 Correct 2 ms 596 KB Output is correct
98 Correct 2 ms 596 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 524 KB Output is correct
102 Correct 2 ms 520 KB Output is correct
103 Correct 0 ms 340 KB Output is correct
104 Correct 2 ms 724 KB Output is correct
105 Correct 2 ms 476 KB Output is correct
106 Correct 2 ms 596 KB Output is correct
107 Correct 2 ms 612 KB Output is correct
108 Correct 2 ms 612 KB Output is correct
109 Correct 2 ms 596 KB Output is correct
110 Correct 2 ms 480 KB Output is correct
111 Correct 0 ms 344 KB Output is correct
112 Correct 269 ms 25148 KB Output is correct
113 Correct 264 ms 25144 KB Output is correct
114 Correct 284 ms 25140 KB Output is correct
115 Correct 300 ms 25156 KB Output is correct
116 Correct 253 ms 25152 KB Output is correct
117 Correct 266 ms 25180 KB Output is correct
118 Correct 260 ms 25056 KB Output is correct
119 Correct 255 ms 25152 KB Output is correct
120 Correct 253 ms 25152 KB Output is correct
121 Correct 255 ms 25152 KB Output is correct
122 Correct 273 ms 25188 KB Output is correct
123 Correct 250 ms 25028 KB Output is correct
124 Correct 257 ms 25120 KB Output is correct
125 Correct 0 ms 340 KB Output is correct
126 Correct 277 ms 25144 KB Output is correct
127 Correct 257 ms 25148 KB Output is correct
128 Correct 261 ms 25268 KB Output is correct
129 Correct 262 ms 25148 KB Output is correct
130 Correct 273 ms 25148 KB Output is correct
131 Correct 264 ms 25156 KB Output is correct
132 Correct 275 ms 25032 KB Output is correct
133 Correct 1 ms 340 KB Output is correct
134 Correct 257 ms 26068 KB Output is correct
135 Correct 334 ms 26084 KB Output is correct
136 Correct 256 ms 26104 KB Output is correct
137 Correct 292 ms 26148 KB Output is correct
138 Correct 263 ms 26108 KB Output is correct
139 Correct 263 ms 25992 KB Output is correct
140 Correct 284 ms 26100 KB Output is correct
141 Correct 260 ms 26100 KB Output is correct
142 Correct 266 ms 26104 KB Output is correct
143 Correct 270 ms 26072 KB Output is correct
144 Correct 260 ms 26108 KB Output is correct
145 Correct 286 ms 26068 KB Output is correct
146 Correct 275 ms 26108 KB Output is correct
147 Correct 1 ms 336 KB Output is correct
148 Correct 267 ms 26108 KB Output is correct
149 Correct 277 ms 26108 KB Output is correct
150 Correct 271 ms 26108 KB Output is correct
151 Correct 267 ms 26220 KB Output is correct
152 Correct 264 ms 26100 KB Output is correct
153 Correct 265 ms 26032 KB Output is correct
154 Correct 262 ms 26048 KB Output is correct