답안 #693817

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
693817 2023-02-03T08:54:19 Z saayan007 Cryptography (NOI20_crypto) C++17
100 / 100
87 ms 15124 KB
#include <bits/stdc++.h>
using namespace std;

using ll = long long;
using pi = pair<int, int>;
using pl = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vpi = vector<pi>;
using vpl = vector<pl>;

#define fur(i, a, b) for(ll i = a; i <= (ll) b; ++i)
#define ruf(i, a, b) for(ll i = a; i >= (ll) b; --i)
#define fr first
#define sc second
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define nl "\n"

const ll mod = 1e9L + 7;
const ll mxn = 3e5L + 5;

ll n;
pl p[mxn];
ll fact[mxn];

ll mul(const ll &a, const ll &b) {
    ll c = (a % mod) * (b % mod);
    c %= mod;
    if(c < 0)
        c += mod;
    return c;
}

ll sum(const ll &a, const ll &b) {
    ll c = (a % mod) + (b % mod);
    c %= mod;
    if(c < 0)
        c += mod;
    return c;
}

ll fen[mxn] = {};

void upd(ll pos, ll val) {
    while(pos <= n) {
        fen[pos] += val;
        pos += pos & -pos;
    }
}

ll qry(ll pos) {
    ll res = 0;
    while(pos >= 1) {
        res += fen[pos];
        pos -= pos & -pos;
    }
    return res;
}

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);

    cin >> n;
    fur(i, 1, n) {
        cin >> p[i].fr;
        p[i].sc = i;
    }
    sort(p + 1, p + n + 1);
    ll a[n + 1];
    fur(i, 1, n) {
        a[p[i].sc] = i;
    }

    fact[0] = fact[1] = 1;
    fur(i, 2, n) {
        fact[i] = mul(fact[i - 1], i);
    }

    fur(i, 1, n)
        upd(i, 1);
    ll dp[n + 1] = {};
    ll res = 0;
    fur(i, 1, n) {
        ll smaller = qry(a[i] - 1);
        dp[i] = mul(smaller, fact[n - i]);
        res = sum(res, dp[i]);
        upd(a[i], -1);
    }
    res = sum(res, 1);
    cout << res << nl;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 328 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 328 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 328 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 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 340 KB Output is correct
13 Correct 0 ms 340 KB Output is correct
14 Correct 0 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 300 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 0 ms 340 KB Output is correct
23 Correct 1 ms 324 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 56 ms 14900 KB Output is correct
3 Correct 62 ms 14896 KB Output is correct
4 Correct 51 ms 14860 KB Output is correct
5 Correct 51 ms 14820 KB Output is correct
6 Correct 55 ms 14924 KB Output is correct
7 Correct 53 ms 14896 KB Output is correct
8 Correct 53 ms 14896 KB Output is correct
9 Correct 52 ms 14776 KB Output is correct
10 Correct 53 ms 14780 KB Output is correct
11 Correct 53 ms 14856 KB Output is correct
12 Correct 53 ms 14784 KB Output is correct
13 Correct 59 ms 14880 KB Output is correct
14 Correct 52 ms 14804 KB Output is correct
15 Correct 53 ms 14900 KB Output is correct
16 Correct 53 ms 14796 KB Output is correct
17 Correct 56 ms 14860 KB Output is correct
18 Correct 52 ms 14836 KB Output is correct
19 Correct 55 ms 14856 KB Output is correct
20 Correct 52 ms 14792 KB Output is correct
21 Correct 57 ms 14900 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 328 KB Output is correct
2 Correct 47 ms 14864 KB Output is correct
3 Correct 47 ms 14900 KB Output is correct
4 Correct 49 ms 14780 KB Output is correct
5 Correct 49 ms 14832 KB Output is correct
6 Correct 47 ms 14796 KB Output is correct
7 Correct 48 ms 14796 KB Output is correct
8 Correct 57 ms 14800 KB Output is correct
9 Correct 48 ms 14896 KB Output is correct
10 Correct 47 ms 14800 KB Output is correct
11 Correct 46 ms 14884 KB Output is correct
12 Correct 47 ms 14812 KB Output is correct
13 Correct 47 ms 14804 KB Output is correct
14 Correct 46 ms 14804 KB Output is correct
15 Correct 48 ms 14780 KB Output is correct
16 Correct 47 ms 14800 KB Output is correct
17 Correct 47 ms 14892 KB Output is correct
18 Correct 48 ms 14884 KB Output is correct
19 Correct 51 ms 14792 KB Output is correct
20 Correct 46 ms 14880 KB Output is correct
21 Correct 48 ms 14796 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 324 KB Output is correct
2 Correct 1 ms 468 KB Output is correct
3 Correct 1 ms 468 KB Output is correct
4 Correct 1 ms 464 KB Output is correct
5 Correct 1 ms 468 KB Output is correct
6 Correct 1 ms 468 KB Output is correct
7 Correct 1 ms 468 KB Output is correct
8 Correct 1 ms 468 KB Output is correct
9 Correct 2 ms 468 KB Output is correct
10 Correct 1 ms 468 KB Output is correct
11 Correct 1 ms 468 KB Output is correct
12 Correct 1 ms 468 KB Output is correct
13 Correct 1 ms 468 KB Output is correct
14 Correct 1 ms 468 KB Output is correct
15 Correct 0 ms 340 KB Output is correct
16 Correct 1 ms 468 KB Output is correct
17 Correct 1 ms 468 KB Output is correct
18 Correct 1 ms 468 KB Output is correct
19 Correct 1 ms 468 KB Output is correct
20 Correct 1 ms 468 KB Output is correct
21 Correct 1 ms 468 KB Output is correct
22 Correct 1 ms 464 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 328 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 328 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 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 340 KB Output is correct
13 Correct 0 ms 340 KB Output is correct
14 Correct 0 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 300 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 0 ms 340 KB Output is correct
23 Correct 1 ms 324 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 0 ms 324 KB Output is correct
26 Correct 1 ms 468 KB Output is correct
27 Correct 1 ms 468 KB Output is correct
28 Correct 1 ms 464 KB Output is correct
29 Correct 1 ms 468 KB Output is correct
30 Correct 1 ms 468 KB Output is correct
31 Correct 1 ms 468 KB Output is correct
32 Correct 1 ms 468 KB Output is correct
33 Correct 2 ms 468 KB Output is correct
34 Correct 1 ms 468 KB Output is correct
35 Correct 1 ms 468 KB Output is correct
36 Correct 1 ms 468 KB Output is correct
37 Correct 1 ms 468 KB Output is correct
38 Correct 1 ms 468 KB Output is correct
39 Correct 0 ms 340 KB Output is correct
40 Correct 1 ms 468 KB Output is correct
41 Correct 1 ms 468 KB Output is correct
42 Correct 1 ms 468 KB Output is correct
43 Correct 1 ms 468 KB Output is correct
44 Correct 1 ms 468 KB Output is correct
45 Correct 1 ms 468 KB Output is correct
46 Correct 1 ms 464 KB Output is correct
47 Correct 1 ms 340 KB Output is correct
48 Correct 1 ms 468 KB Output is correct
49 Correct 1 ms 468 KB Output is correct
50 Correct 1 ms 468 KB Output is correct
51 Correct 2 ms 468 KB Output is correct
52 Correct 1 ms 468 KB Output is correct
53 Correct 1 ms 468 KB Output is correct
54 Correct 1 ms 504 KB Output is correct
55 Correct 1 ms 468 KB Output is correct
56 Correct 1 ms 468 KB Output is correct
57 Correct 1 ms 464 KB Output is correct
58 Correct 1 ms 464 KB Output is correct
59 Correct 1 ms 388 KB Output is correct
60 Correct 1 ms 480 KB Output is correct
61 Correct 1 ms 352 KB Output is correct
62 Correct 1 ms 468 KB Output is correct
63 Correct 2 ms 468 KB Output is correct
64 Correct 1 ms 480 KB Output is correct
65 Correct 2 ms 424 KB Output is correct
66 Correct 1 ms 480 KB Output is correct
67 Correct 1 ms 516 KB Output is correct
68 Correct 1 ms 480 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 328 KB Output is correct
2 Correct 47 ms 14864 KB Output is correct
3 Correct 47 ms 14900 KB Output is correct
4 Correct 49 ms 14780 KB Output is correct
5 Correct 49 ms 14832 KB Output is correct
6 Correct 47 ms 14796 KB Output is correct
7 Correct 48 ms 14796 KB Output is correct
8 Correct 57 ms 14800 KB Output is correct
9 Correct 48 ms 14896 KB Output is correct
10 Correct 47 ms 14800 KB Output is correct
11 Correct 46 ms 14884 KB Output is correct
12 Correct 47 ms 14812 KB Output is correct
13 Correct 47 ms 14804 KB Output is correct
14 Correct 46 ms 14804 KB Output is correct
15 Correct 48 ms 14780 KB Output is correct
16 Correct 47 ms 14800 KB Output is correct
17 Correct 47 ms 14892 KB Output is correct
18 Correct 48 ms 14884 KB Output is correct
19 Correct 51 ms 14792 KB Output is correct
20 Correct 46 ms 14880 KB Output is correct
21 Correct 48 ms 14796 KB Output is correct
22 Correct 0 ms 324 KB Output is correct
23 Correct 1 ms 468 KB Output is correct
24 Correct 1 ms 468 KB Output is correct
25 Correct 1 ms 464 KB Output is correct
26 Correct 1 ms 468 KB Output is correct
27 Correct 1 ms 468 KB Output is correct
28 Correct 1 ms 468 KB Output is correct
29 Correct 1 ms 468 KB Output is correct
30 Correct 2 ms 468 KB Output is correct
31 Correct 1 ms 468 KB Output is correct
32 Correct 1 ms 468 KB Output is correct
33 Correct 1 ms 468 KB Output is correct
34 Correct 1 ms 468 KB Output is correct
35 Correct 1 ms 468 KB Output is correct
36 Correct 0 ms 340 KB Output is correct
37 Correct 1 ms 468 KB Output is correct
38 Correct 1 ms 468 KB Output is correct
39 Correct 1 ms 468 KB Output is correct
40 Correct 1 ms 468 KB Output is correct
41 Correct 1 ms 468 KB Output is correct
42 Correct 1 ms 468 KB Output is correct
43 Correct 1 ms 464 KB Output is correct
44 Correct 0 ms 352 KB Output is correct
45 Correct 74 ms 15028 KB Output is correct
46 Correct 76 ms 15064 KB Output is correct
47 Correct 74 ms 14976 KB Output is correct
48 Correct 73 ms 14912 KB Output is correct
49 Correct 77 ms 15060 KB Output is correct
50 Correct 71 ms 15124 KB Output is correct
51 Correct 71 ms 15004 KB Output is correct
52 Correct 72 ms 14948 KB Output is correct
53 Correct 71 ms 14996 KB Output is correct
54 Correct 74 ms 15004 KB Output is correct
55 Correct 87 ms 14904 KB Output is correct
56 Correct 81 ms 14924 KB Output is correct
57 Correct 76 ms 14964 KB Output is correct
58 Correct 1 ms 332 KB Output is correct
59 Correct 74 ms 14924 KB Output is correct
60 Correct 72 ms 15032 KB Output is correct
61 Correct 75 ms 15020 KB Output is correct
62 Correct 78 ms 15052 KB Output is correct
63 Correct 73 ms 14924 KB Output is correct
64 Correct 71 ms 14996 KB Output is correct
65 Correct 75 ms 15064 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 328 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 328 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 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 340 KB Output is correct
13 Correct 0 ms 340 KB Output is correct
14 Correct 0 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 300 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 0 ms 340 KB Output is correct
23 Correct 1 ms 324 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 1 ms 332 KB Output is correct
26 Correct 56 ms 14900 KB Output is correct
27 Correct 62 ms 14896 KB Output is correct
28 Correct 51 ms 14860 KB Output is correct
29 Correct 51 ms 14820 KB Output is correct
30 Correct 55 ms 14924 KB Output is correct
31 Correct 53 ms 14896 KB Output is correct
32 Correct 53 ms 14896 KB Output is correct
33 Correct 52 ms 14776 KB Output is correct
34 Correct 53 ms 14780 KB Output is correct
35 Correct 53 ms 14856 KB Output is correct
36 Correct 53 ms 14784 KB Output is correct
37 Correct 59 ms 14880 KB Output is correct
38 Correct 52 ms 14804 KB Output is correct
39 Correct 53 ms 14900 KB Output is correct
40 Correct 53 ms 14796 KB Output is correct
41 Correct 56 ms 14860 KB Output is correct
42 Correct 52 ms 14836 KB Output is correct
43 Correct 55 ms 14856 KB Output is correct
44 Correct 52 ms 14792 KB Output is correct
45 Correct 57 ms 14900 KB Output is correct
46 Correct 1 ms 328 KB Output is correct
47 Correct 47 ms 14864 KB Output is correct
48 Correct 47 ms 14900 KB Output is correct
49 Correct 49 ms 14780 KB Output is correct
50 Correct 49 ms 14832 KB Output is correct
51 Correct 47 ms 14796 KB Output is correct
52 Correct 48 ms 14796 KB Output is correct
53 Correct 57 ms 14800 KB Output is correct
54 Correct 48 ms 14896 KB Output is correct
55 Correct 47 ms 14800 KB Output is correct
56 Correct 46 ms 14884 KB Output is correct
57 Correct 47 ms 14812 KB Output is correct
58 Correct 47 ms 14804 KB Output is correct
59 Correct 46 ms 14804 KB Output is correct
60 Correct 48 ms 14780 KB Output is correct
61 Correct 47 ms 14800 KB Output is correct
62 Correct 47 ms 14892 KB Output is correct
63 Correct 48 ms 14884 KB Output is correct
64 Correct 51 ms 14792 KB Output is correct
65 Correct 46 ms 14880 KB Output is correct
66 Correct 48 ms 14796 KB Output is correct
67 Correct 0 ms 324 KB Output is correct
68 Correct 1 ms 468 KB Output is correct
69 Correct 1 ms 468 KB Output is correct
70 Correct 1 ms 464 KB Output is correct
71 Correct 1 ms 468 KB Output is correct
72 Correct 1 ms 468 KB Output is correct
73 Correct 1 ms 468 KB Output is correct
74 Correct 1 ms 468 KB Output is correct
75 Correct 2 ms 468 KB Output is correct
76 Correct 1 ms 468 KB Output is correct
77 Correct 1 ms 468 KB Output is correct
78 Correct 1 ms 468 KB Output is correct
79 Correct 1 ms 468 KB Output is correct
80 Correct 1 ms 468 KB Output is correct
81 Correct 0 ms 340 KB Output is correct
82 Correct 1 ms 468 KB Output is correct
83 Correct 1 ms 468 KB Output is correct
84 Correct 1 ms 468 KB Output is correct
85 Correct 1 ms 468 KB Output is correct
86 Correct 1 ms 468 KB Output is correct
87 Correct 1 ms 468 KB Output is correct
88 Correct 1 ms 464 KB Output is correct
89 Correct 1 ms 340 KB Output is correct
90 Correct 1 ms 468 KB Output is correct
91 Correct 1 ms 468 KB Output is correct
92 Correct 1 ms 468 KB Output is correct
93 Correct 2 ms 468 KB Output is correct
94 Correct 1 ms 468 KB Output is correct
95 Correct 1 ms 468 KB Output is correct
96 Correct 1 ms 504 KB Output is correct
97 Correct 1 ms 468 KB Output is correct
98 Correct 1 ms 468 KB Output is correct
99 Correct 1 ms 464 KB Output is correct
100 Correct 1 ms 464 KB Output is correct
101 Correct 1 ms 388 KB Output is correct
102 Correct 1 ms 480 KB Output is correct
103 Correct 1 ms 352 KB Output is correct
104 Correct 1 ms 468 KB Output is correct
105 Correct 2 ms 468 KB Output is correct
106 Correct 1 ms 480 KB Output is correct
107 Correct 2 ms 424 KB Output is correct
108 Correct 1 ms 480 KB Output is correct
109 Correct 1 ms 516 KB Output is correct
110 Correct 1 ms 480 KB Output is correct
111 Correct 0 ms 352 KB Output is correct
112 Correct 74 ms 15028 KB Output is correct
113 Correct 76 ms 15064 KB Output is correct
114 Correct 74 ms 14976 KB Output is correct
115 Correct 73 ms 14912 KB Output is correct
116 Correct 77 ms 15060 KB Output is correct
117 Correct 71 ms 15124 KB Output is correct
118 Correct 71 ms 15004 KB Output is correct
119 Correct 72 ms 14948 KB Output is correct
120 Correct 71 ms 14996 KB Output is correct
121 Correct 74 ms 15004 KB Output is correct
122 Correct 87 ms 14904 KB Output is correct
123 Correct 81 ms 14924 KB Output is correct
124 Correct 76 ms 14964 KB Output is correct
125 Correct 1 ms 332 KB Output is correct
126 Correct 74 ms 14924 KB Output is correct
127 Correct 72 ms 15032 KB Output is correct
128 Correct 75 ms 15020 KB Output is correct
129 Correct 78 ms 15052 KB Output is correct
130 Correct 73 ms 14924 KB Output is correct
131 Correct 71 ms 14996 KB Output is correct
132 Correct 75 ms 15064 KB Output is correct
133 Correct 0 ms 340 KB Output is correct
134 Correct 76 ms 15020 KB Output is correct
135 Correct 87 ms 14932 KB Output is correct
136 Correct 85 ms 14984 KB Output is correct
137 Correct 79 ms 15032 KB Output is correct
138 Correct 77 ms 14996 KB Output is correct
139 Correct 79 ms 15052 KB Output is correct
140 Correct 77 ms 15028 KB Output is correct
141 Correct 76 ms 15044 KB Output is correct
142 Correct 85 ms 14924 KB Output is correct
143 Correct 82 ms 15104 KB Output is correct
144 Correct 81 ms 15028 KB Output is correct
145 Correct 79 ms 14996 KB Output is correct
146 Correct 84 ms 15024 KB Output is correct
147 Correct 0 ms 340 KB Output is correct
148 Correct 75 ms 15032 KB Output is correct
149 Correct 77 ms 14956 KB Output is correct
150 Correct 82 ms 15028 KB Output is correct
151 Correct 79 ms 14988 KB Output is correct
152 Correct 78 ms 15000 KB Output is correct
153 Correct 78 ms 15032 KB Output is correct
154 Correct 77 ms 15012 KB Output is correct