답안 #948359

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
948359 2024-03-18T04:47:19 Z Lilypad Cryptography (NOI20_crypto) C++14
100 / 100
346 ms 31572 KB
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pii pair<ll,ll>
#define pb push_back
#define fi first
#define se second

const ll N = 3e5+3;
const ll MOD = 1e9+7;

ll a[N],b[N],fac[N],bit[N];
ll n,tmp,ans;
map<ll,ll> mp;

void update(ll idx) {
	for(int i=idx; i<=n; i+=i&-i) {
		bit[i]++;
	}
}

ll query(ll idx) {
	ll ret = 0;
	for(int i=idx; i>=1; i-=i&-i) {
		ret += bit[i];
	}
	return ret;
}

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cin >> n;
	fac[0] = 1;
	for(int i=1; i<=n; i++) {
		cin >> a[i];
		b[i] = a[i];
		fac[i] = fac[i-1] * i;
		fac[i] %= MOD;
	}
	sort(b+1,b+n+1);
	for(int i=1; i<=n; i++) {
		mp[b[i]] = i;
	}
	for(int i=1; i<=n; i++) a[i] = mp[a[i]];
	for(int i=n; i>=1; i--) {
		ans += (fac[n-i] * query(a[i]-1)) % MOD;
		ans %= MOD;
		update(a[i]);
	}
	cout << (ans + 1) % MOD << endl;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 6644 KB Output is correct
2 Correct 1 ms 6492 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 6644 KB Output is correct
2 Correct 1 ms 6492 KB Output is correct
3 Correct 1 ms 6492 KB Output is correct
4 Correct 1 ms 6492 KB Output is correct
5 Correct 1 ms 6488 KB Output is correct
6 Correct 1 ms 6492 KB Output is correct
7 Correct 1 ms 6488 KB Output is correct
8 Correct 1 ms 6492 KB Output is correct
9 Correct 1 ms 6488 KB Output is correct
10 Correct 1 ms 6492 KB Output is correct
11 Correct 1 ms 6492 KB Output is correct
12 Correct 1 ms 6492 KB Output is correct
13 Correct 1 ms 6492 KB Output is correct
14 Correct 1 ms 6492 KB Output is correct
15 Correct 1 ms 6492 KB Output is correct
16 Correct 1 ms 6492 KB Output is correct
17 Correct 1 ms 6492 KB Output is correct
18 Correct 1 ms 6492 KB Output is correct
19 Correct 1 ms 6492 KB Output is correct
20 Correct 1 ms 6492 KB Output is correct
21 Correct 1 ms 6492 KB Output is correct
22 Correct 1 ms 6492 KB Output is correct
23 Correct 1 ms 6492 KB Output is correct
24 Correct 1 ms 6492 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 6492 KB Output is correct
2 Correct 116 ms 28556 KB Output is correct
3 Correct 115 ms 31476 KB Output is correct
4 Correct 119 ms 31400 KB Output is correct
5 Correct 114 ms 31316 KB Output is correct
6 Correct 118 ms 31316 KB Output is correct
7 Correct 126 ms 31504 KB Output is correct
8 Correct 112 ms 31316 KB Output is correct
9 Correct 117 ms 31572 KB Output is correct
10 Correct 112 ms 31316 KB Output is correct
11 Correct 112 ms 31316 KB Output is correct
12 Correct 119 ms 31316 KB Output is correct
13 Correct 115 ms 31572 KB Output is correct
14 Correct 115 ms 31316 KB Output is correct
15 Correct 112 ms 31316 KB Output is correct
16 Correct 112 ms 31360 KB Output is correct
17 Correct 112 ms 31460 KB Output is correct
18 Correct 116 ms 31476 KB Output is correct
19 Correct 131 ms 31284 KB Output is correct
20 Correct 117 ms 31344 KB Output is correct
21 Correct 117 ms 31420 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 6488 KB Output is correct
2 Correct 108 ms 28492 KB Output is correct
3 Correct 107 ms 30336 KB Output is correct
4 Correct 114 ms 30488 KB Output is correct
5 Correct 112 ms 30528 KB Output is correct
6 Correct 134 ms 30552 KB Output is correct
7 Correct 106 ms 30544 KB Output is correct
8 Correct 119 ms 30548 KB Output is correct
9 Correct 117 ms 30516 KB Output is correct
10 Correct 114 ms 30312 KB Output is correct
11 Correct 108 ms 30552 KB Output is correct
12 Correct 116 ms 30392 KB Output is correct
13 Correct 110 ms 30376 KB Output is correct
14 Correct 117 ms 30520 KB Output is correct
15 Correct 111 ms 30384 KB Output is correct
16 Correct 115 ms 30476 KB Output is correct
17 Correct 110 ms 30508 KB Output is correct
18 Correct 111 ms 30368 KB Output is correct
19 Correct 106 ms 30352 KB Output is correct
20 Correct 113 ms 30388 KB Output is correct
21 Correct 108 ms 30392 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 6488 KB Output is correct
2 Correct 2 ms 6748 KB Output is correct
3 Correct 2 ms 6744 KB Output is correct
4 Correct 3 ms 6744 KB Output is correct
5 Correct 3 ms 6748 KB Output is correct
6 Correct 2 ms 6748 KB Output is correct
7 Correct 2 ms 6912 KB Output is correct
8 Correct 2 ms 6744 KB Output is correct
9 Correct 3 ms 6812 KB Output is correct
10 Correct 2 ms 6748 KB Output is correct
11 Correct 2 ms 6748 KB Output is correct
12 Correct 3 ms 6620 KB Output is correct
13 Correct 2 ms 6744 KB Output is correct
14 Correct 2 ms 6748 KB Output is correct
15 Correct 1 ms 6492 KB Output is correct
16 Correct 3 ms 6748 KB Output is correct
17 Correct 2 ms 6744 KB Output is correct
18 Correct 2 ms 6748 KB Output is correct
19 Correct 3 ms 6748 KB Output is correct
20 Correct 2 ms 6748 KB Output is correct
21 Correct 2 ms 6748 KB Output is correct
22 Correct 2 ms 6748 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 6644 KB Output is correct
2 Correct 1 ms 6492 KB Output is correct
3 Correct 1 ms 6492 KB Output is correct
4 Correct 1 ms 6492 KB Output is correct
5 Correct 1 ms 6488 KB Output is correct
6 Correct 1 ms 6492 KB Output is correct
7 Correct 1 ms 6488 KB Output is correct
8 Correct 1 ms 6492 KB Output is correct
9 Correct 1 ms 6488 KB Output is correct
10 Correct 1 ms 6492 KB Output is correct
11 Correct 1 ms 6492 KB Output is correct
12 Correct 1 ms 6492 KB Output is correct
13 Correct 1 ms 6492 KB Output is correct
14 Correct 1 ms 6492 KB Output is correct
15 Correct 1 ms 6492 KB Output is correct
16 Correct 1 ms 6492 KB Output is correct
17 Correct 1 ms 6492 KB Output is correct
18 Correct 1 ms 6492 KB Output is correct
19 Correct 1 ms 6492 KB Output is correct
20 Correct 1 ms 6492 KB Output is correct
21 Correct 1 ms 6492 KB Output is correct
22 Correct 1 ms 6492 KB Output is correct
23 Correct 1 ms 6492 KB Output is correct
24 Correct 1 ms 6492 KB Output is correct
25 Correct 1 ms 6488 KB Output is correct
26 Correct 2 ms 6748 KB Output is correct
27 Correct 2 ms 6744 KB Output is correct
28 Correct 3 ms 6744 KB Output is correct
29 Correct 3 ms 6748 KB Output is correct
30 Correct 2 ms 6748 KB Output is correct
31 Correct 2 ms 6912 KB Output is correct
32 Correct 2 ms 6744 KB Output is correct
33 Correct 3 ms 6812 KB Output is correct
34 Correct 2 ms 6748 KB Output is correct
35 Correct 2 ms 6748 KB Output is correct
36 Correct 3 ms 6620 KB Output is correct
37 Correct 2 ms 6744 KB Output is correct
38 Correct 2 ms 6748 KB Output is correct
39 Correct 1 ms 6492 KB Output is correct
40 Correct 3 ms 6748 KB Output is correct
41 Correct 2 ms 6744 KB Output is correct
42 Correct 2 ms 6748 KB Output is correct
43 Correct 3 ms 6748 KB Output is correct
44 Correct 2 ms 6748 KB Output is correct
45 Correct 2 ms 6748 KB Output is correct
46 Correct 2 ms 6748 KB Output is correct
47 Correct 1 ms 6492 KB Output is correct
48 Correct 2 ms 6748 KB Output is correct
49 Correct 2 ms 6748 KB Output is correct
50 Correct 2 ms 6748 KB Output is correct
51 Correct 3 ms 6748 KB Output is correct
52 Correct 2 ms 6748 KB Output is correct
53 Correct 3 ms 6748 KB Output is correct
54 Correct 2 ms 6748 KB Output is correct
55 Correct 3 ms 6748 KB Output is correct
56 Correct 3 ms 6748 KB Output is correct
57 Correct 3 ms 6748 KB Output is correct
58 Correct 2 ms 6748 KB Output is correct
59 Correct 2 ms 6760 KB Output is correct
60 Correct 2 ms 6748 KB Output is correct
61 Correct 1 ms 6492 KB Output is correct
62 Correct 2 ms 6744 KB Output is correct
63 Correct 2 ms 6748 KB Output is correct
64 Correct 2 ms 6748 KB Output is correct
65 Correct 2 ms 6748 KB Output is correct
66 Correct 3 ms 6748 KB Output is correct
67 Correct 2 ms 6748 KB Output is correct
68 Correct 2 ms 6748 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 6488 KB Output is correct
2 Correct 108 ms 28492 KB Output is correct
3 Correct 107 ms 30336 KB Output is correct
4 Correct 114 ms 30488 KB Output is correct
5 Correct 112 ms 30528 KB Output is correct
6 Correct 134 ms 30552 KB Output is correct
7 Correct 106 ms 30544 KB Output is correct
8 Correct 119 ms 30548 KB Output is correct
9 Correct 117 ms 30516 KB Output is correct
10 Correct 114 ms 30312 KB Output is correct
11 Correct 108 ms 30552 KB Output is correct
12 Correct 116 ms 30392 KB Output is correct
13 Correct 110 ms 30376 KB Output is correct
14 Correct 117 ms 30520 KB Output is correct
15 Correct 111 ms 30384 KB Output is correct
16 Correct 115 ms 30476 KB Output is correct
17 Correct 110 ms 30508 KB Output is correct
18 Correct 111 ms 30368 KB Output is correct
19 Correct 106 ms 30352 KB Output is correct
20 Correct 113 ms 30388 KB Output is correct
21 Correct 108 ms 30392 KB Output is correct
22 Correct 1 ms 6488 KB Output is correct
23 Correct 2 ms 6748 KB Output is correct
24 Correct 2 ms 6744 KB Output is correct
25 Correct 3 ms 6744 KB Output is correct
26 Correct 3 ms 6748 KB Output is correct
27 Correct 2 ms 6748 KB Output is correct
28 Correct 2 ms 6912 KB Output is correct
29 Correct 2 ms 6744 KB Output is correct
30 Correct 3 ms 6812 KB Output is correct
31 Correct 2 ms 6748 KB Output is correct
32 Correct 2 ms 6748 KB Output is correct
33 Correct 3 ms 6620 KB Output is correct
34 Correct 2 ms 6744 KB Output is correct
35 Correct 2 ms 6748 KB Output is correct
36 Correct 1 ms 6492 KB Output is correct
37 Correct 3 ms 6748 KB Output is correct
38 Correct 2 ms 6744 KB Output is correct
39 Correct 2 ms 6748 KB Output is correct
40 Correct 3 ms 6748 KB Output is correct
41 Correct 2 ms 6748 KB Output is correct
42 Correct 2 ms 6748 KB Output is correct
43 Correct 2 ms 6748 KB Output is correct
44 Correct 1 ms 6492 KB Output is correct
45 Correct 346 ms 30388 KB Output is correct
46 Correct 285 ms 30384 KB Output is correct
47 Correct 328 ms 30628 KB Output is correct
48 Correct 282 ms 30388 KB Output is correct
49 Correct 286 ms 30548 KB Output is correct
50 Correct 259 ms 30564 KB Output is correct
51 Correct 262 ms 30548 KB Output is correct
52 Correct 261 ms 30716 KB Output is correct
53 Correct 267 ms 30388 KB Output is correct
54 Correct 287 ms 30544 KB Output is correct
55 Correct 291 ms 30544 KB Output is correct
56 Correct 255 ms 30544 KB Output is correct
57 Correct 270 ms 30392 KB Output is correct
58 Correct 1 ms 6492 KB Output is correct
59 Correct 258 ms 30564 KB Output is correct
60 Correct 292 ms 30388 KB Output is correct
61 Correct 258 ms 30392 KB Output is correct
62 Correct 267 ms 30388 KB Output is correct
63 Correct 279 ms 30428 KB Output is correct
64 Correct 246 ms 30396 KB Output is correct
65 Correct 279 ms 30540 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 6644 KB Output is correct
2 Correct 1 ms 6492 KB Output is correct
3 Correct 1 ms 6492 KB Output is correct
4 Correct 1 ms 6492 KB Output is correct
5 Correct 1 ms 6488 KB Output is correct
6 Correct 1 ms 6492 KB Output is correct
7 Correct 1 ms 6488 KB Output is correct
8 Correct 1 ms 6492 KB Output is correct
9 Correct 1 ms 6488 KB Output is correct
10 Correct 1 ms 6492 KB Output is correct
11 Correct 1 ms 6492 KB Output is correct
12 Correct 1 ms 6492 KB Output is correct
13 Correct 1 ms 6492 KB Output is correct
14 Correct 1 ms 6492 KB Output is correct
15 Correct 1 ms 6492 KB Output is correct
16 Correct 1 ms 6492 KB Output is correct
17 Correct 1 ms 6492 KB Output is correct
18 Correct 1 ms 6492 KB Output is correct
19 Correct 1 ms 6492 KB Output is correct
20 Correct 1 ms 6492 KB Output is correct
21 Correct 1 ms 6492 KB Output is correct
22 Correct 1 ms 6492 KB Output is correct
23 Correct 1 ms 6492 KB Output is correct
24 Correct 1 ms 6492 KB Output is correct
25 Correct 1 ms 6492 KB Output is correct
26 Correct 116 ms 28556 KB Output is correct
27 Correct 115 ms 31476 KB Output is correct
28 Correct 119 ms 31400 KB Output is correct
29 Correct 114 ms 31316 KB Output is correct
30 Correct 118 ms 31316 KB Output is correct
31 Correct 126 ms 31504 KB Output is correct
32 Correct 112 ms 31316 KB Output is correct
33 Correct 117 ms 31572 KB Output is correct
34 Correct 112 ms 31316 KB Output is correct
35 Correct 112 ms 31316 KB Output is correct
36 Correct 119 ms 31316 KB Output is correct
37 Correct 115 ms 31572 KB Output is correct
38 Correct 115 ms 31316 KB Output is correct
39 Correct 112 ms 31316 KB Output is correct
40 Correct 112 ms 31360 KB Output is correct
41 Correct 112 ms 31460 KB Output is correct
42 Correct 116 ms 31476 KB Output is correct
43 Correct 131 ms 31284 KB Output is correct
44 Correct 117 ms 31344 KB Output is correct
45 Correct 117 ms 31420 KB Output is correct
46 Correct 1 ms 6488 KB Output is correct
47 Correct 108 ms 28492 KB Output is correct
48 Correct 107 ms 30336 KB Output is correct
49 Correct 114 ms 30488 KB Output is correct
50 Correct 112 ms 30528 KB Output is correct
51 Correct 134 ms 30552 KB Output is correct
52 Correct 106 ms 30544 KB Output is correct
53 Correct 119 ms 30548 KB Output is correct
54 Correct 117 ms 30516 KB Output is correct
55 Correct 114 ms 30312 KB Output is correct
56 Correct 108 ms 30552 KB Output is correct
57 Correct 116 ms 30392 KB Output is correct
58 Correct 110 ms 30376 KB Output is correct
59 Correct 117 ms 30520 KB Output is correct
60 Correct 111 ms 30384 KB Output is correct
61 Correct 115 ms 30476 KB Output is correct
62 Correct 110 ms 30508 KB Output is correct
63 Correct 111 ms 30368 KB Output is correct
64 Correct 106 ms 30352 KB Output is correct
65 Correct 113 ms 30388 KB Output is correct
66 Correct 108 ms 30392 KB Output is correct
67 Correct 1 ms 6488 KB Output is correct
68 Correct 2 ms 6748 KB Output is correct
69 Correct 2 ms 6744 KB Output is correct
70 Correct 3 ms 6744 KB Output is correct
71 Correct 3 ms 6748 KB Output is correct
72 Correct 2 ms 6748 KB Output is correct
73 Correct 2 ms 6912 KB Output is correct
74 Correct 2 ms 6744 KB Output is correct
75 Correct 3 ms 6812 KB Output is correct
76 Correct 2 ms 6748 KB Output is correct
77 Correct 2 ms 6748 KB Output is correct
78 Correct 3 ms 6620 KB Output is correct
79 Correct 2 ms 6744 KB Output is correct
80 Correct 2 ms 6748 KB Output is correct
81 Correct 1 ms 6492 KB Output is correct
82 Correct 3 ms 6748 KB Output is correct
83 Correct 2 ms 6744 KB Output is correct
84 Correct 2 ms 6748 KB Output is correct
85 Correct 3 ms 6748 KB Output is correct
86 Correct 2 ms 6748 KB Output is correct
87 Correct 2 ms 6748 KB Output is correct
88 Correct 2 ms 6748 KB Output is correct
89 Correct 1 ms 6492 KB Output is correct
90 Correct 2 ms 6748 KB Output is correct
91 Correct 2 ms 6748 KB Output is correct
92 Correct 2 ms 6748 KB Output is correct
93 Correct 3 ms 6748 KB Output is correct
94 Correct 2 ms 6748 KB Output is correct
95 Correct 3 ms 6748 KB Output is correct
96 Correct 2 ms 6748 KB Output is correct
97 Correct 3 ms 6748 KB Output is correct
98 Correct 3 ms 6748 KB Output is correct
99 Correct 3 ms 6748 KB Output is correct
100 Correct 2 ms 6748 KB Output is correct
101 Correct 2 ms 6760 KB Output is correct
102 Correct 2 ms 6748 KB Output is correct
103 Correct 1 ms 6492 KB Output is correct
104 Correct 2 ms 6744 KB Output is correct
105 Correct 2 ms 6748 KB Output is correct
106 Correct 2 ms 6748 KB Output is correct
107 Correct 2 ms 6748 KB Output is correct
108 Correct 3 ms 6748 KB Output is correct
109 Correct 2 ms 6748 KB Output is correct
110 Correct 2 ms 6748 KB Output is correct
111 Correct 1 ms 6492 KB Output is correct
112 Correct 346 ms 30388 KB Output is correct
113 Correct 285 ms 30384 KB Output is correct
114 Correct 328 ms 30628 KB Output is correct
115 Correct 282 ms 30388 KB Output is correct
116 Correct 286 ms 30548 KB Output is correct
117 Correct 259 ms 30564 KB Output is correct
118 Correct 262 ms 30548 KB Output is correct
119 Correct 261 ms 30716 KB Output is correct
120 Correct 267 ms 30388 KB Output is correct
121 Correct 287 ms 30544 KB Output is correct
122 Correct 291 ms 30544 KB Output is correct
123 Correct 255 ms 30544 KB Output is correct
124 Correct 270 ms 30392 KB Output is correct
125 Correct 1 ms 6492 KB Output is correct
126 Correct 258 ms 30564 KB Output is correct
127 Correct 292 ms 30388 KB Output is correct
128 Correct 258 ms 30392 KB Output is correct
129 Correct 267 ms 30388 KB Output is correct
130 Correct 279 ms 30428 KB Output is correct
131 Correct 246 ms 30396 KB Output is correct
132 Correct 279 ms 30540 KB Output is correct
133 Correct 1 ms 6492 KB Output is correct
134 Correct 270 ms 31508 KB Output is correct
135 Correct 282 ms 31572 KB Output is correct
136 Correct 277 ms 31500 KB Output is correct
137 Correct 259 ms 31504 KB Output is correct
138 Correct 249 ms 31344 KB Output is correct
139 Correct 261 ms 31344 KB Output is correct
140 Correct 278 ms 31344 KB Output is correct
141 Correct 258 ms 31348 KB Output is correct
142 Correct 257 ms 31356 KB Output is correct
143 Correct 263 ms 31316 KB Output is correct
144 Correct 271 ms 31344 KB Output is correct
145 Correct 270 ms 31288 KB Output is correct
146 Correct 258 ms 31316 KB Output is correct
147 Correct 1 ms 6492 KB Output is correct
148 Correct 264 ms 31524 KB Output is correct
149 Correct 280 ms 31348 KB Output is correct
150 Correct 263 ms 31316 KB Output is correct
151 Correct 251 ms 31316 KB Output is correct
152 Correct 268 ms 31316 KB Output is correct
153 Correct 296 ms 31356 KB Output is correct
154 Correct 263 ms 31496 KB Output is correct