Submission #596572

# Submission time Handle Problem Language Result Execution time Memory
596572 2022-07-14T20:43:53 Z AdamGS Cryptography (NOI20_crypto) C++17
100 / 100
390 ms 25316 KB
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(a, b) for(int a = 0; a < (b); ++a)
#define all(a) a.begin(), a.end()
#define st first
#define nd second
#define pb push_back
#define all(a) a.begin(), a.end()
const ll MOD=1e9+7, LIM=3e5+7;
int T[LIM], S[LIM], tr[4*LIM], N=1;
ll sil[LIM];
map<int,int>mp;
void upd(int v) {
  for(v+=N; v; v/=2) --tr[v];
}
ll cnt(int l, int r) {
  l+=N; r+=N;
  ll ans=tr[l];
  if(l!=r) ans+=tr[r];
  while(l/2!=r/2) {
    if(l%2==0) ans+=tr[l+1];
    if(r%2==1) ans+=tr[r-1];
    l/=2; r/=2;
  }
  return ans;
}
int main() {
  ios_base::sync_with_stdio(0); cin.tie(0);
  sil[0]=1;
  for(ll i=1; i<LIM; ++i) sil[i]=(sil[i-1]*i)%MOD;
  int n;
  cin >> n;
  while(N<n) N*=2;
  rep(i, n) {
    cin >> T[i];
    S[i]=T[i];
    tr[N+i]=1;
  }
  for(int i=N-1; i; --i) tr[i]=tr[2*i]+tr[2*i+1];
  sort(S, S+n);
  rep(i, n) mp[S[i]]=i;
  ll ans=1;
  rep(i, n) {
    ll x=cnt(0, mp[T[i]]);
    upd(mp[T[i]]);
    ans=(ans+sil[n-i-1]*(x-1))%MOD;
  }
  cout << ans << '\n';
}
# Verdict Execution time Memory Grader output
1 Correct 3 ms 2644 KB Output is correct
2 Correct 3 ms 2644 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 2644 KB Output is correct
2 Correct 3 ms 2644 KB Output is correct
3 Correct 3 ms 2644 KB Output is correct
4 Correct 3 ms 2644 KB Output is correct
5 Correct 3 ms 2644 KB Output is correct
6 Correct 3 ms 2644 KB Output is correct
7 Correct 4 ms 2644 KB Output is correct
8 Correct 3 ms 2644 KB Output is correct
9 Correct 3 ms 2680 KB Output is correct
10 Correct 3 ms 2644 KB Output is correct
11 Correct 3 ms 2644 KB Output is correct
12 Correct 4 ms 2644 KB Output is correct
13 Correct 3 ms 2644 KB Output is correct
14 Correct 4 ms 2620 KB Output is correct
15 Correct 3 ms 2684 KB Output is correct
16 Correct 4 ms 2644 KB Output is correct
17 Correct 3 ms 2644 KB Output is correct
18 Correct 4 ms 2644 KB Output is correct
19 Correct 3 ms 2644 KB Output is correct
20 Correct 3 ms 2688 KB Output is correct
21 Correct 3 ms 2644 KB Output is correct
22 Correct 3 ms 2684 KB Output is correct
23 Correct 3 ms 2644 KB Output is correct
24 Correct 3 ms 2644 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 2644 KB Output is correct
2 Correct 170 ms 22216 KB Output is correct
3 Correct 167 ms 22320 KB Output is correct
4 Correct 165 ms 22204 KB Output is correct
5 Correct 170 ms 22220 KB Output is correct
6 Correct 168 ms 22324 KB Output is correct
7 Correct 168 ms 22324 KB Output is correct
8 Correct 163 ms 22212 KB Output is correct
9 Correct 167 ms 22320 KB Output is correct
10 Correct 168 ms 22328 KB Output is correct
11 Correct 171 ms 22368 KB Output is correct
12 Correct 170 ms 22320 KB Output is correct
13 Correct 167 ms 22248 KB Output is correct
14 Correct 170 ms 22348 KB Output is correct
15 Correct 164 ms 22220 KB Output is correct
16 Correct 165 ms 22424 KB Output is correct
17 Correct 164 ms 22308 KB Output is correct
18 Correct 169 ms 22320 KB Output is correct
19 Correct 167 ms 22204 KB Output is correct
20 Correct 164 ms 22220 KB Output is correct
21 Correct 166 ms 22320 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 2644 KB Output is correct
2 Correct 164 ms 22308 KB Output is correct
3 Correct 165 ms 24224 KB Output is correct
4 Correct 161 ms 24160 KB Output is correct
5 Correct 166 ms 24308 KB Output is correct
6 Correct 163 ms 24192 KB Output is correct
7 Correct 160 ms 24204 KB Output is correct
8 Correct 162 ms 24268 KB Output is correct
9 Correct 165 ms 24320 KB Output is correct
10 Correct 162 ms 24220 KB Output is correct
11 Correct 164 ms 24276 KB Output is correct
12 Correct 161 ms 24340 KB Output is correct
13 Correct 162 ms 24272 KB Output is correct
14 Correct 159 ms 24276 KB Output is correct
15 Correct 162 ms 24232 KB Output is correct
16 Correct 164 ms 24396 KB Output is correct
17 Correct 160 ms 24272 KB Output is correct
18 Correct 159 ms 24172 KB Output is correct
19 Correct 160 ms 24176 KB Output is correct
20 Correct 162 ms 24284 KB Output is correct
21 Correct 161 ms 24268 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 2644 KB Output is correct
2 Correct 5 ms 2772 KB Output is correct
3 Correct 5 ms 2900 KB Output is correct
4 Correct 5 ms 2900 KB Output is correct
5 Correct 5 ms 2824 KB Output is correct
6 Correct 5 ms 2900 KB Output is correct
7 Correct 6 ms 2900 KB Output is correct
8 Correct 5 ms 2844 KB Output is correct
9 Correct 5 ms 2784 KB Output is correct
10 Correct 5 ms 2900 KB Output is correct
11 Correct 4 ms 2828 KB Output is correct
12 Correct 5 ms 2816 KB Output is correct
13 Correct 5 ms 2844 KB Output is correct
14 Correct 5 ms 2820 KB Output is correct
15 Correct 3 ms 2680 KB Output is correct
16 Correct 4 ms 2900 KB Output is correct
17 Correct 5 ms 2900 KB Output is correct
18 Correct 5 ms 2900 KB Output is correct
19 Correct 5 ms 2900 KB Output is correct
20 Correct 5 ms 2820 KB Output is correct
21 Correct 5 ms 2900 KB Output is correct
22 Correct 5 ms 2824 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 2644 KB Output is correct
2 Correct 3 ms 2644 KB Output is correct
3 Correct 3 ms 2644 KB Output is correct
4 Correct 3 ms 2644 KB Output is correct
5 Correct 3 ms 2644 KB Output is correct
6 Correct 3 ms 2644 KB Output is correct
7 Correct 4 ms 2644 KB Output is correct
8 Correct 3 ms 2644 KB Output is correct
9 Correct 3 ms 2680 KB Output is correct
10 Correct 3 ms 2644 KB Output is correct
11 Correct 3 ms 2644 KB Output is correct
12 Correct 4 ms 2644 KB Output is correct
13 Correct 3 ms 2644 KB Output is correct
14 Correct 4 ms 2620 KB Output is correct
15 Correct 3 ms 2684 KB Output is correct
16 Correct 4 ms 2644 KB Output is correct
17 Correct 3 ms 2644 KB Output is correct
18 Correct 4 ms 2644 KB Output is correct
19 Correct 3 ms 2644 KB Output is correct
20 Correct 3 ms 2688 KB Output is correct
21 Correct 3 ms 2644 KB Output is correct
22 Correct 3 ms 2684 KB Output is correct
23 Correct 3 ms 2644 KB Output is correct
24 Correct 3 ms 2644 KB Output is correct
25 Correct 3 ms 2644 KB Output is correct
26 Correct 5 ms 2772 KB Output is correct
27 Correct 5 ms 2900 KB Output is correct
28 Correct 5 ms 2900 KB Output is correct
29 Correct 5 ms 2824 KB Output is correct
30 Correct 5 ms 2900 KB Output is correct
31 Correct 6 ms 2900 KB Output is correct
32 Correct 5 ms 2844 KB Output is correct
33 Correct 5 ms 2784 KB Output is correct
34 Correct 5 ms 2900 KB Output is correct
35 Correct 4 ms 2828 KB Output is correct
36 Correct 5 ms 2816 KB Output is correct
37 Correct 5 ms 2844 KB Output is correct
38 Correct 5 ms 2820 KB Output is correct
39 Correct 3 ms 2680 KB Output is correct
40 Correct 4 ms 2900 KB Output is correct
41 Correct 5 ms 2900 KB Output is correct
42 Correct 5 ms 2900 KB Output is correct
43 Correct 5 ms 2900 KB Output is correct
44 Correct 5 ms 2820 KB Output is correct
45 Correct 5 ms 2900 KB Output is correct
46 Correct 5 ms 2824 KB Output is correct
47 Correct 4 ms 2644 KB Output is correct
48 Correct 5 ms 2900 KB Output is correct
49 Correct 5 ms 2900 KB Output is correct
50 Correct 5 ms 2900 KB Output is correct
51 Correct 5 ms 2900 KB Output is correct
52 Correct 5 ms 2900 KB Output is correct
53 Correct 5 ms 2900 KB Output is correct
54 Correct 5 ms 2900 KB Output is correct
55 Correct 5 ms 2900 KB Output is correct
56 Correct 5 ms 2828 KB Output is correct
57 Correct 5 ms 2900 KB Output is correct
58 Correct 5 ms 2824 KB Output is correct
59 Correct 5 ms 2828 KB Output is correct
60 Correct 5 ms 2900 KB Output is correct
61 Correct 3 ms 2644 KB Output is correct
62 Correct 5 ms 2900 KB Output is correct
63 Correct 5 ms 2900 KB Output is correct
64 Correct 5 ms 2900 KB Output is correct
65 Correct 4 ms 2900 KB Output is correct
66 Correct 4 ms 2900 KB Output is correct
67 Correct 5 ms 2900 KB Output is correct
68 Correct 5 ms 2900 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 2644 KB Output is correct
2 Correct 164 ms 22308 KB Output is correct
3 Correct 165 ms 24224 KB Output is correct
4 Correct 161 ms 24160 KB Output is correct
5 Correct 166 ms 24308 KB Output is correct
6 Correct 163 ms 24192 KB Output is correct
7 Correct 160 ms 24204 KB Output is correct
8 Correct 162 ms 24268 KB Output is correct
9 Correct 165 ms 24320 KB Output is correct
10 Correct 162 ms 24220 KB Output is correct
11 Correct 164 ms 24276 KB Output is correct
12 Correct 161 ms 24340 KB Output is correct
13 Correct 162 ms 24272 KB Output is correct
14 Correct 159 ms 24276 KB Output is correct
15 Correct 162 ms 24232 KB Output is correct
16 Correct 164 ms 24396 KB Output is correct
17 Correct 160 ms 24272 KB Output is correct
18 Correct 159 ms 24172 KB Output is correct
19 Correct 160 ms 24176 KB Output is correct
20 Correct 162 ms 24284 KB Output is correct
21 Correct 161 ms 24268 KB Output is correct
22 Correct 3 ms 2644 KB Output is correct
23 Correct 5 ms 2772 KB Output is correct
24 Correct 5 ms 2900 KB Output is correct
25 Correct 5 ms 2900 KB Output is correct
26 Correct 5 ms 2824 KB Output is correct
27 Correct 5 ms 2900 KB Output is correct
28 Correct 6 ms 2900 KB Output is correct
29 Correct 5 ms 2844 KB Output is correct
30 Correct 5 ms 2784 KB Output is correct
31 Correct 5 ms 2900 KB Output is correct
32 Correct 4 ms 2828 KB Output is correct
33 Correct 5 ms 2816 KB Output is correct
34 Correct 5 ms 2844 KB Output is correct
35 Correct 5 ms 2820 KB Output is correct
36 Correct 3 ms 2680 KB Output is correct
37 Correct 4 ms 2900 KB Output is correct
38 Correct 5 ms 2900 KB Output is correct
39 Correct 5 ms 2900 KB Output is correct
40 Correct 5 ms 2900 KB Output is correct
41 Correct 5 ms 2820 KB Output is correct
42 Correct 5 ms 2900 KB Output is correct
43 Correct 5 ms 2824 KB Output is correct
44 Correct 3 ms 2644 KB Output is correct
45 Correct 349 ms 24256 KB Output is correct
46 Correct 360 ms 24276 KB Output is correct
47 Correct 359 ms 24184 KB Output is correct
48 Correct 354 ms 24260 KB Output is correct
49 Correct 353 ms 24280 KB Output is correct
50 Correct 357 ms 24280 KB Output is correct
51 Correct 374 ms 24280 KB Output is correct
52 Correct 357 ms 24280 KB Output is correct
53 Correct 380 ms 24276 KB Output is correct
54 Correct 355 ms 24272 KB Output is correct
55 Correct 363 ms 24356 KB Output is correct
56 Correct 343 ms 24276 KB Output is correct
57 Correct 359 ms 24276 KB Output is correct
58 Correct 3 ms 2644 KB Output is correct
59 Correct 347 ms 24240 KB Output is correct
60 Correct 383 ms 24280 KB Output is correct
61 Correct 353 ms 24272 KB Output is correct
62 Correct 338 ms 24396 KB Output is correct
63 Correct 351 ms 24276 KB Output is correct
64 Correct 352 ms 24216 KB Output is correct
65 Correct 343 ms 24264 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 2644 KB Output is correct
2 Correct 3 ms 2644 KB Output is correct
3 Correct 3 ms 2644 KB Output is correct
4 Correct 3 ms 2644 KB Output is correct
5 Correct 3 ms 2644 KB Output is correct
6 Correct 3 ms 2644 KB Output is correct
7 Correct 4 ms 2644 KB Output is correct
8 Correct 3 ms 2644 KB Output is correct
9 Correct 3 ms 2680 KB Output is correct
10 Correct 3 ms 2644 KB Output is correct
11 Correct 3 ms 2644 KB Output is correct
12 Correct 4 ms 2644 KB Output is correct
13 Correct 3 ms 2644 KB Output is correct
14 Correct 4 ms 2620 KB Output is correct
15 Correct 3 ms 2684 KB Output is correct
16 Correct 4 ms 2644 KB Output is correct
17 Correct 3 ms 2644 KB Output is correct
18 Correct 4 ms 2644 KB Output is correct
19 Correct 3 ms 2644 KB Output is correct
20 Correct 3 ms 2688 KB Output is correct
21 Correct 3 ms 2644 KB Output is correct
22 Correct 3 ms 2684 KB Output is correct
23 Correct 3 ms 2644 KB Output is correct
24 Correct 3 ms 2644 KB Output is correct
25 Correct 4 ms 2644 KB Output is correct
26 Correct 170 ms 22216 KB Output is correct
27 Correct 167 ms 22320 KB Output is correct
28 Correct 165 ms 22204 KB Output is correct
29 Correct 170 ms 22220 KB Output is correct
30 Correct 168 ms 22324 KB Output is correct
31 Correct 168 ms 22324 KB Output is correct
32 Correct 163 ms 22212 KB Output is correct
33 Correct 167 ms 22320 KB Output is correct
34 Correct 168 ms 22328 KB Output is correct
35 Correct 171 ms 22368 KB Output is correct
36 Correct 170 ms 22320 KB Output is correct
37 Correct 167 ms 22248 KB Output is correct
38 Correct 170 ms 22348 KB Output is correct
39 Correct 164 ms 22220 KB Output is correct
40 Correct 165 ms 22424 KB Output is correct
41 Correct 164 ms 22308 KB Output is correct
42 Correct 169 ms 22320 KB Output is correct
43 Correct 167 ms 22204 KB Output is correct
44 Correct 164 ms 22220 KB Output is correct
45 Correct 166 ms 22320 KB Output is correct
46 Correct 3 ms 2644 KB Output is correct
47 Correct 164 ms 22308 KB Output is correct
48 Correct 165 ms 24224 KB Output is correct
49 Correct 161 ms 24160 KB Output is correct
50 Correct 166 ms 24308 KB Output is correct
51 Correct 163 ms 24192 KB Output is correct
52 Correct 160 ms 24204 KB Output is correct
53 Correct 162 ms 24268 KB Output is correct
54 Correct 165 ms 24320 KB Output is correct
55 Correct 162 ms 24220 KB Output is correct
56 Correct 164 ms 24276 KB Output is correct
57 Correct 161 ms 24340 KB Output is correct
58 Correct 162 ms 24272 KB Output is correct
59 Correct 159 ms 24276 KB Output is correct
60 Correct 162 ms 24232 KB Output is correct
61 Correct 164 ms 24396 KB Output is correct
62 Correct 160 ms 24272 KB Output is correct
63 Correct 159 ms 24172 KB Output is correct
64 Correct 160 ms 24176 KB Output is correct
65 Correct 162 ms 24284 KB Output is correct
66 Correct 161 ms 24268 KB Output is correct
67 Correct 3 ms 2644 KB Output is correct
68 Correct 5 ms 2772 KB Output is correct
69 Correct 5 ms 2900 KB Output is correct
70 Correct 5 ms 2900 KB Output is correct
71 Correct 5 ms 2824 KB Output is correct
72 Correct 5 ms 2900 KB Output is correct
73 Correct 6 ms 2900 KB Output is correct
74 Correct 5 ms 2844 KB Output is correct
75 Correct 5 ms 2784 KB Output is correct
76 Correct 5 ms 2900 KB Output is correct
77 Correct 4 ms 2828 KB Output is correct
78 Correct 5 ms 2816 KB Output is correct
79 Correct 5 ms 2844 KB Output is correct
80 Correct 5 ms 2820 KB Output is correct
81 Correct 3 ms 2680 KB Output is correct
82 Correct 4 ms 2900 KB Output is correct
83 Correct 5 ms 2900 KB Output is correct
84 Correct 5 ms 2900 KB Output is correct
85 Correct 5 ms 2900 KB Output is correct
86 Correct 5 ms 2820 KB Output is correct
87 Correct 5 ms 2900 KB Output is correct
88 Correct 5 ms 2824 KB Output is correct
89 Correct 4 ms 2644 KB Output is correct
90 Correct 5 ms 2900 KB Output is correct
91 Correct 5 ms 2900 KB Output is correct
92 Correct 5 ms 2900 KB Output is correct
93 Correct 5 ms 2900 KB Output is correct
94 Correct 5 ms 2900 KB Output is correct
95 Correct 5 ms 2900 KB Output is correct
96 Correct 5 ms 2900 KB Output is correct
97 Correct 5 ms 2900 KB Output is correct
98 Correct 5 ms 2828 KB Output is correct
99 Correct 5 ms 2900 KB Output is correct
100 Correct 5 ms 2824 KB Output is correct
101 Correct 5 ms 2828 KB Output is correct
102 Correct 5 ms 2900 KB Output is correct
103 Correct 3 ms 2644 KB Output is correct
104 Correct 5 ms 2900 KB Output is correct
105 Correct 5 ms 2900 KB Output is correct
106 Correct 5 ms 2900 KB Output is correct
107 Correct 4 ms 2900 KB Output is correct
108 Correct 4 ms 2900 KB Output is correct
109 Correct 5 ms 2900 KB Output is correct
110 Correct 5 ms 2900 KB Output is correct
111 Correct 3 ms 2644 KB Output is correct
112 Correct 349 ms 24256 KB Output is correct
113 Correct 360 ms 24276 KB Output is correct
114 Correct 359 ms 24184 KB Output is correct
115 Correct 354 ms 24260 KB Output is correct
116 Correct 353 ms 24280 KB Output is correct
117 Correct 357 ms 24280 KB Output is correct
118 Correct 374 ms 24280 KB Output is correct
119 Correct 357 ms 24280 KB Output is correct
120 Correct 380 ms 24276 KB Output is correct
121 Correct 355 ms 24272 KB Output is correct
122 Correct 363 ms 24356 KB Output is correct
123 Correct 343 ms 24276 KB Output is correct
124 Correct 359 ms 24276 KB Output is correct
125 Correct 3 ms 2644 KB Output is correct
126 Correct 347 ms 24240 KB Output is correct
127 Correct 383 ms 24280 KB Output is correct
128 Correct 353 ms 24272 KB Output is correct
129 Correct 338 ms 24396 KB Output is correct
130 Correct 351 ms 24276 KB Output is correct
131 Correct 352 ms 24216 KB Output is correct
132 Correct 343 ms 24264 KB Output is correct
133 Correct 3 ms 2684 KB Output is correct
134 Correct 368 ms 25232 KB Output is correct
135 Correct 355 ms 25232 KB Output is correct
136 Correct 363 ms 25216 KB Output is correct
137 Correct 355 ms 25236 KB Output is correct
138 Correct 377 ms 25292 KB Output is correct
139 Correct 342 ms 25220 KB Output is correct
140 Correct 369 ms 25228 KB Output is correct
141 Correct 353 ms 25220 KB Output is correct
142 Correct 361 ms 25232 KB Output is correct
143 Correct 366 ms 25168 KB Output is correct
144 Correct 357 ms 25220 KB Output is correct
145 Correct 380 ms 25260 KB Output is correct
146 Correct 369 ms 25168 KB Output is correct
147 Correct 3 ms 2644 KB Output is correct
148 Correct 390 ms 25316 KB Output is correct
149 Correct 375 ms 25148 KB Output is correct
150 Correct 362 ms 25292 KB Output is correct
151 Correct 353 ms 25232 KB Output is correct
152 Correct 361 ms 25164 KB Output is correct
153 Correct 350 ms 25232 KB Output is correct
154 Correct 373 ms 25252 KB Output is correct