답안 #508665

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
508665 2022-01-13T14:00:10 Z Joo Cryptography (NOI20_crypto) C++17
100 / 100
393 ms 22152 KB
#include <bits/stdc++.h>
using namespace std;

const int N = 3e5+10, mod = 1000000007;

int n, arr[N], fen[N], fac[N];
map<int, int> idx;

void up(int idx, int val){
    if(idx <= 0) return;
    for(; idx < N; idx += idx&-idx) fen[idx] += val;
}

int sum(int idx){
    int res = 0;
    for(; idx; idx -= idx&-idx) res += fen[idx];
    return res;
}

int main(void){
    ios_base::sync_with_stdio(0); cin.tie(0);
    cin >> n;
    vector<int> vec;
    fac[0] = 1;
    for(int i = 1; i <= n ; i++){
        cin >> arr[i];
        vec.emplace_back(arr[i]); 
        up(i, 1);
        fac[i] = 1ll*fac[i-1]*i%mod;
    }

    sort(vec.begin(), vec.end());
    for(int i = 0; i < n; i++) idx[vec[i]] = i+1;

    int ans = 1;
    for(int i = 1; i <= n; i++){
        ans += 1ll*sum(idx[arr[i]]-1)*fac[n-i]%mod;
        ans %= mod;
        up(idx[arr[i]], -1);
    }
    cout << ans << "\n";


    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 316 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 316 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 316 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 320 KB Output is correct
7 Correct 0 ms 332 KB Output is correct
8 Correct 0 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 0 ms 332 KB Output is correct
11 Correct 0 ms 332 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 332 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 0 ms 312 KB Output is correct
17 Correct 1 ms 332 KB Output is correct
18 Correct 0 ms 332 KB Output is correct
19 Correct 0 ms 332 KB Output is correct
20 Correct 1 ms 332 KB Output is correct
21 Correct 1 ms 332 KB Output is correct
22 Correct 0 ms 332 KB Output is correct
23 Correct 0 ms 332 KB Output is correct
24 Correct 0 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 165 ms 21912 KB Output is correct
3 Correct 153 ms 21892 KB Output is correct
4 Correct 152 ms 21944 KB Output is correct
5 Correct 159 ms 21892 KB Output is correct
6 Correct 151 ms 22152 KB Output is correct
7 Correct 156 ms 21928 KB Output is correct
8 Correct 165 ms 21936 KB Output is correct
9 Correct 160 ms 21984 KB Output is correct
10 Correct 155 ms 21956 KB Output is correct
11 Correct 149 ms 21920 KB Output is correct
12 Correct 150 ms 22008 KB Output is correct
13 Correct 152 ms 21924 KB Output is correct
14 Correct 150 ms 21944 KB Output is correct
15 Correct 151 ms 22052 KB Output is correct
16 Correct 150 ms 21892 KB Output is correct
17 Correct 152 ms 21904 KB Output is correct
18 Correct 168 ms 21968 KB Output is correct
19 Correct 160 ms 22084 KB Output is correct
20 Correct 155 ms 21948 KB Output is correct
21 Correct 154 ms 21908 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 320 KB Output is correct
2 Correct 142 ms 21028 KB Output is correct
3 Correct 147 ms 21032 KB Output is correct
4 Correct 163 ms 20984 KB Output is correct
5 Correct 145 ms 20948 KB Output is correct
6 Correct 143 ms 20956 KB Output is correct
7 Correct 142 ms 20948 KB Output is correct
8 Correct 144 ms 21020 KB Output is correct
9 Correct 164 ms 20924 KB Output is correct
10 Correct 165 ms 21036 KB Output is correct
11 Correct 166 ms 21032 KB Output is correct
12 Correct 147 ms 20992 KB Output is correct
13 Correct 181 ms 21008 KB Output is correct
14 Correct 146 ms 20944 KB Output is correct
15 Correct 144 ms 21004 KB Output is correct
16 Correct 151 ms 21016 KB Output is correct
17 Correct 150 ms 20920 KB Output is correct
18 Correct 146 ms 20968 KB Output is correct
19 Correct 156 ms 21108 KB Output is correct
20 Correct 161 ms 21024 KB Output is correct
21 Correct 156 ms 20932 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 308 KB Output is correct
2 Correct 2 ms 460 KB Output is correct
3 Correct 2 ms 460 KB Output is correct
4 Correct 2 ms 460 KB Output is correct
5 Correct 2 ms 460 KB Output is correct
6 Correct 2 ms 460 KB Output is correct
7 Correct 3 ms 460 KB Output is correct
8 Correct 2 ms 452 KB Output is correct
9 Correct 2 ms 572 KB Output is correct
10 Correct 2 ms 464 KB Output is correct
11 Correct 2 ms 460 KB Output is correct
12 Correct 2 ms 460 KB Output is correct
13 Correct 2 ms 460 KB Output is correct
14 Correct 3 ms 460 KB Output is correct
15 Correct 0 ms 308 KB Output is correct
16 Correct 2 ms 460 KB Output is correct
17 Correct 2 ms 460 KB Output is correct
18 Correct 2 ms 460 KB Output is correct
19 Correct 2 ms 460 KB Output is correct
20 Correct 2 ms 452 KB Output is correct
21 Correct 2 ms 472 KB Output is correct
22 Correct 2 ms 556 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 316 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 316 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 320 KB Output is correct
7 Correct 0 ms 332 KB Output is correct
8 Correct 0 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 0 ms 332 KB Output is correct
11 Correct 0 ms 332 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 332 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 0 ms 312 KB Output is correct
17 Correct 1 ms 332 KB Output is correct
18 Correct 0 ms 332 KB Output is correct
19 Correct 0 ms 332 KB Output is correct
20 Correct 1 ms 332 KB Output is correct
21 Correct 1 ms 332 KB Output is correct
22 Correct 0 ms 332 KB Output is correct
23 Correct 0 ms 332 KB Output is correct
24 Correct 0 ms 332 KB Output is correct
25 Correct 1 ms 308 KB Output is correct
26 Correct 2 ms 460 KB Output is correct
27 Correct 2 ms 460 KB Output is correct
28 Correct 2 ms 460 KB Output is correct
29 Correct 2 ms 460 KB Output is correct
30 Correct 2 ms 460 KB Output is correct
31 Correct 3 ms 460 KB Output is correct
32 Correct 2 ms 452 KB Output is correct
33 Correct 2 ms 572 KB Output is correct
34 Correct 2 ms 464 KB Output is correct
35 Correct 2 ms 460 KB Output is correct
36 Correct 2 ms 460 KB Output is correct
37 Correct 2 ms 460 KB Output is correct
38 Correct 3 ms 460 KB Output is correct
39 Correct 0 ms 308 KB Output is correct
40 Correct 2 ms 460 KB Output is correct
41 Correct 2 ms 460 KB Output is correct
42 Correct 2 ms 460 KB Output is correct
43 Correct 2 ms 460 KB Output is correct
44 Correct 2 ms 452 KB Output is correct
45 Correct 2 ms 472 KB Output is correct
46 Correct 2 ms 556 KB Output is correct
47 Correct 0 ms 332 KB Output is correct
48 Correct 2 ms 588 KB Output is correct
49 Correct 2 ms 460 KB Output is correct
50 Correct 2 ms 460 KB Output is correct
51 Correct 2 ms 588 KB Output is correct
52 Correct 2 ms 588 KB Output is correct
53 Correct 2 ms 588 KB Output is correct
54 Correct 2 ms 588 KB Output is correct
55 Correct 2 ms 588 KB Output is correct
56 Correct 2 ms 588 KB Output is correct
57 Correct 2 ms 588 KB Output is correct
58 Correct 2 ms 584 KB Output is correct
59 Correct 2 ms 588 KB Output is correct
60 Correct 2 ms 588 KB Output is correct
61 Correct 0 ms 332 KB Output is correct
62 Correct 2 ms 584 KB Output is correct
63 Correct 2 ms 452 KB Output is correct
64 Correct 2 ms 452 KB Output is correct
65 Correct 2 ms 460 KB Output is correct
66 Correct 2 ms 588 KB Output is correct
67 Correct 2 ms 588 KB Output is correct
68 Correct 3 ms 540 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 320 KB Output is correct
2 Correct 142 ms 21028 KB Output is correct
3 Correct 147 ms 21032 KB Output is correct
4 Correct 163 ms 20984 KB Output is correct
5 Correct 145 ms 20948 KB Output is correct
6 Correct 143 ms 20956 KB Output is correct
7 Correct 142 ms 20948 KB Output is correct
8 Correct 144 ms 21020 KB Output is correct
9 Correct 164 ms 20924 KB Output is correct
10 Correct 165 ms 21036 KB Output is correct
11 Correct 166 ms 21032 KB Output is correct
12 Correct 147 ms 20992 KB Output is correct
13 Correct 181 ms 21008 KB Output is correct
14 Correct 146 ms 20944 KB Output is correct
15 Correct 144 ms 21004 KB Output is correct
16 Correct 151 ms 21016 KB Output is correct
17 Correct 150 ms 20920 KB Output is correct
18 Correct 146 ms 20968 KB Output is correct
19 Correct 156 ms 21108 KB Output is correct
20 Correct 161 ms 21024 KB Output is correct
21 Correct 156 ms 20932 KB Output is correct
22 Correct 1 ms 308 KB Output is correct
23 Correct 2 ms 460 KB Output is correct
24 Correct 2 ms 460 KB Output is correct
25 Correct 2 ms 460 KB Output is correct
26 Correct 2 ms 460 KB Output is correct
27 Correct 2 ms 460 KB Output is correct
28 Correct 3 ms 460 KB Output is correct
29 Correct 2 ms 452 KB Output is correct
30 Correct 2 ms 572 KB Output is correct
31 Correct 2 ms 464 KB Output is correct
32 Correct 2 ms 460 KB Output is correct
33 Correct 2 ms 460 KB Output is correct
34 Correct 2 ms 460 KB Output is correct
35 Correct 3 ms 460 KB Output is correct
36 Correct 0 ms 308 KB Output is correct
37 Correct 2 ms 460 KB Output is correct
38 Correct 2 ms 460 KB Output is correct
39 Correct 2 ms 460 KB Output is correct
40 Correct 2 ms 460 KB Output is correct
41 Correct 2 ms 452 KB Output is correct
42 Correct 2 ms 472 KB Output is correct
43 Correct 2 ms 556 KB Output is correct
44 Correct 0 ms 312 KB Output is correct
45 Correct 316 ms 21088 KB Output is correct
46 Correct 338 ms 21016 KB Output is correct
47 Correct 333 ms 21036 KB Output is correct
48 Correct 308 ms 21032 KB Output is correct
49 Correct 315 ms 20920 KB Output is correct
50 Correct 333 ms 21024 KB Output is correct
51 Correct 310 ms 20980 KB Output is correct
52 Correct 332 ms 21032 KB Output is correct
53 Correct 354 ms 21036 KB Output is correct
54 Correct 324 ms 20916 KB Output is correct
55 Correct 330 ms 21020 KB Output is correct
56 Correct 333 ms 21032 KB Output is correct
57 Correct 339 ms 21000 KB Output is correct
58 Correct 1 ms 312 KB Output is correct
59 Correct 333 ms 21148 KB Output is correct
60 Correct 347 ms 21068 KB Output is correct
61 Correct 324 ms 20972 KB Output is correct
62 Correct 332 ms 20960 KB Output is correct
63 Correct 325 ms 20944 KB Output is correct
64 Correct 327 ms 20976 KB Output is correct
65 Correct 312 ms 21032 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 316 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 316 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 320 KB Output is correct
7 Correct 0 ms 332 KB Output is correct
8 Correct 0 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 0 ms 332 KB Output is correct
11 Correct 0 ms 332 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 332 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 0 ms 312 KB Output is correct
17 Correct 1 ms 332 KB Output is correct
18 Correct 0 ms 332 KB Output is correct
19 Correct 0 ms 332 KB Output is correct
20 Correct 1 ms 332 KB Output is correct
21 Correct 1 ms 332 KB Output is correct
22 Correct 0 ms 332 KB Output is correct
23 Correct 0 ms 332 KB Output is correct
24 Correct 0 ms 332 KB Output is correct
25 Correct 0 ms 332 KB Output is correct
26 Correct 165 ms 21912 KB Output is correct
27 Correct 153 ms 21892 KB Output is correct
28 Correct 152 ms 21944 KB Output is correct
29 Correct 159 ms 21892 KB Output is correct
30 Correct 151 ms 22152 KB Output is correct
31 Correct 156 ms 21928 KB Output is correct
32 Correct 165 ms 21936 KB Output is correct
33 Correct 160 ms 21984 KB Output is correct
34 Correct 155 ms 21956 KB Output is correct
35 Correct 149 ms 21920 KB Output is correct
36 Correct 150 ms 22008 KB Output is correct
37 Correct 152 ms 21924 KB Output is correct
38 Correct 150 ms 21944 KB Output is correct
39 Correct 151 ms 22052 KB Output is correct
40 Correct 150 ms 21892 KB Output is correct
41 Correct 152 ms 21904 KB Output is correct
42 Correct 168 ms 21968 KB Output is correct
43 Correct 160 ms 22084 KB Output is correct
44 Correct 155 ms 21948 KB Output is correct
45 Correct 154 ms 21908 KB Output is correct
46 Correct 0 ms 320 KB Output is correct
47 Correct 142 ms 21028 KB Output is correct
48 Correct 147 ms 21032 KB Output is correct
49 Correct 163 ms 20984 KB Output is correct
50 Correct 145 ms 20948 KB Output is correct
51 Correct 143 ms 20956 KB Output is correct
52 Correct 142 ms 20948 KB Output is correct
53 Correct 144 ms 21020 KB Output is correct
54 Correct 164 ms 20924 KB Output is correct
55 Correct 165 ms 21036 KB Output is correct
56 Correct 166 ms 21032 KB Output is correct
57 Correct 147 ms 20992 KB Output is correct
58 Correct 181 ms 21008 KB Output is correct
59 Correct 146 ms 20944 KB Output is correct
60 Correct 144 ms 21004 KB Output is correct
61 Correct 151 ms 21016 KB Output is correct
62 Correct 150 ms 20920 KB Output is correct
63 Correct 146 ms 20968 KB Output is correct
64 Correct 156 ms 21108 KB Output is correct
65 Correct 161 ms 21024 KB Output is correct
66 Correct 156 ms 20932 KB Output is correct
67 Correct 1 ms 308 KB Output is correct
68 Correct 2 ms 460 KB Output is correct
69 Correct 2 ms 460 KB Output is correct
70 Correct 2 ms 460 KB Output is correct
71 Correct 2 ms 460 KB Output is correct
72 Correct 2 ms 460 KB Output is correct
73 Correct 3 ms 460 KB Output is correct
74 Correct 2 ms 452 KB Output is correct
75 Correct 2 ms 572 KB Output is correct
76 Correct 2 ms 464 KB Output is correct
77 Correct 2 ms 460 KB Output is correct
78 Correct 2 ms 460 KB Output is correct
79 Correct 2 ms 460 KB Output is correct
80 Correct 3 ms 460 KB Output is correct
81 Correct 0 ms 308 KB Output is correct
82 Correct 2 ms 460 KB Output is correct
83 Correct 2 ms 460 KB Output is correct
84 Correct 2 ms 460 KB Output is correct
85 Correct 2 ms 460 KB Output is correct
86 Correct 2 ms 452 KB Output is correct
87 Correct 2 ms 472 KB Output is correct
88 Correct 2 ms 556 KB Output is correct
89 Correct 0 ms 332 KB Output is correct
90 Correct 2 ms 588 KB Output is correct
91 Correct 2 ms 460 KB Output is correct
92 Correct 2 ms 460 KB Output is correct
93 Correct 2 ms 588 KB Output is correct
94 Correct 2 ms 588 KB Output is correct
95 Correct 2 ms 588 KB Output is correct
96 Correct 2 ms 588 KB Output is correct
97 Correct 2 ms 588 KB Output is correct
98 Correct 2 ms 588 KB Output is correct
99 Correct 2 ms 588 KB Output is correct
100 Correct 2 ms 584 KB Output is correct
101 Correct 2 ms 588 KB Output is correct
102 Correct 2 ms 588 KB Output is correct
103 Correct 0 ms 332 KB Output is correct
104 Correct 2 ms 584 KB Output is correct
105 Correct 2 ms 452 KB Output is correct
106 Correct 2 ms 452 KB Output is correct
107 Correct 2 ms 460 KB Output is correct
108 Correct 2 ms 588 KB Output is correct
109 Correct 2 ms 588 KB Output is correct
110 Correct 3 ms 540 KB Output is correct
111 Correct 0 ms 312 KB Output is correct
112 Correct 316 ms 21088 KB Output is correct
113 Correct 338 ms 21016 KB Output is correct
114 Correct 333 ms 21036 KB Output is correct
115 Correct 308 ms 21032 KB Output is correct
116 Correct 315 ms 20920 KB Output is correct
117 Correct 333 ms 21024 KB Output is correct
118 Correct 310 ms 20980 KB Output is correct
119 Correct 332 ms 21032 KB Output is correct
120 Correct 354 ms 21036 KB Output is correct
121 Correct 324 ms 20916 KB Output is correct
122 Correct 330 ms 21020 KB Output is correct
123 Correct 333 ms 21032 KB Output is correct
124 Correct 339 ms 21000 KB Output is correct
125 Correct 1 ms 312 KB Output is correct
126 Correct 333 ms 21148 KB Output is correct
127 Correct 347 ms 21068 KB Output is correct
128 Correct 324 ms 20972 KB Output is correct
129 Correct 332 ms 20960 KB Output is correct
130 Correct 325 ms 20944 KB Output is correct
131 Correct 327 ms 20976 KB Output is correct
132 Correct 312 ms 21032 KB Output is correct
133 Correct 0 ms 320 KB Output is correct
134 Correct 340 ms 21872 KB Output is correct
135 Correct 343 ms 21876 KB Output is correct
136 Correct 346 ms 21972 KB Output is correct
137 Correct 313 ms 21924 KB Output is correct
138 Correct 328 ms 21924 KB Output is correct
139 Correct 326 ms 21940 KB Output is correct
140 Correct 360 ms 21976 KB Output is correct
141 Correct 373 ms 21952 KB Output is correct
142 Correct 335 ms 21940 KB Output is correct
143 Correct 329 ms 21972 KB Output is correct
144 Correct 350 ms 21988 KB Output is correct
145 Correct 341 ms 21884 KB Output is correct
146 Correct 316 ms 21944 KB Output is correct
147 Correct 0 ms 332 KB Output is correct
148 Correct 329 ms 21912 KB Output is correct
149 Correct 339 ms 21928 KB Output is correct
150 Correct 359 ms 21908 KB Output is correct
151 Correct 357 ms 22004 KB Output is correct
152 Correct 393 ms 21992 KB Output is correct
153 Correct 336 ms 21956 KB Output is correct
154 Correct 387 ms 21944 KB Output is correct