답안 #258754

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
258754 2020-08-06T13:57:49 Z ryangohca Cryptography (NOI20_crypto) C++17
100 / 100
296 ms 15340 KB
#include <bits/stdc++.h>
#define int long long
using namespace std;
int fw[300001];
int fact[300001];
const int N = 300000;
const int LOGN = log2(N) + 1;
const int MOD = 1000000007;
void update(int x, int v) {
    for (; x<=N; x+=x&(-x)) fw[x] += v; 
}
int sum(int x) {
    int res = 0;
    for(; x; x-=x&(-x)) res += fw[x];
    return res;
}
vector<int> discretize(const vector<int>& V){
    vector<int> dis = V;
    vector<int> v(V.size());
    sort(dis.begin(), dis.end());
    dis.resize(unique(dis.begin(), dis.end()) - dis.begin());
    for (int i = 0; i < V.size(); i++){
        v[i] = lower_bound(dis.begin(), dis.end(), V[i]) - dis.begin() + 1;
    }
    return v;
}
main(){
  int n; cin >> n;
  vector<int> nums;
  fact[0] = 1;
  for (int i = 0; i < n; i++){
    int h; cin >> h;
    nums.push_back(h);
    update(i + 1, 1);
    fact[i+1] = fact[i] * (i + 1);
    fact[i+1] %= MOD;
  }
  nums = discretize(nums);
  int ans = 1;
  for (int i = 0; i < n; i++){
    int target = nums[i];
    ans += (sum(target) - 1) * fact[n - i - 1];
    ans %= MOD;
    update(target, -1);
  }
  cout << ans << endl;
}

Compilation message

Crypto.cpp: In function 'std::vector<long long int> discretize(const std::vector<long long int>&)':
Crypto.cpp:22:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (int i = 0; i < V.size(); i++){
                     ~~^~~~~~~~~~
Crypto.cpp: At global scope:
Crypto.cpp:27:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
 main(){
      ^
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 0 ms 384 KB Output is correct
7 Correct 0 ms 384 KB Output is correct
8 Correct 0 ms 384 KB Output is correct
9 Correct 0 ms 384 KB Output is correct
10 Correct 0 ms 384 KB Output is correct
11 Correct 0 ms 384 KB Output is correct
12 Correct 0 ms 384 KB Output is correct
13 Correct 0 ms 384 KB Output is correct
14 Correct 0 ms 384 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 0 ms 384 KB Output is correct
17 Correct 0 ms 384 KB Output is correct
18 Correct 0 ms 384 KB Output is correct
19 Correct 0 ms 384 KB Output is correct
20 Correct 0 ms 384 KB Output is correct
21 Correct 0 ms 384 KB Output is correct
22 Correct 0 ms 384 KB Output is correct
23 Correct 0 ms 384 KB Output is correct
24 Correct 0 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 232 ms 15136 KB Output is correct
3 Correct 225 ms 15068 KB Output is correct
4 Correct 228 ms 15076 KB Output is correct
5 Correct 225 ms 15232 KB Output is correct
6 Correct 223 ms 15340 KB Output is correct
7 Correct 227 ms 15084 KB Output is correct
8 Correct 227 ms 15180 KB Output is correct
9 Correct 243 ms 15164 KB Output is correct
10 Correct 224 ms 15068 KB Output is correct
11 Correct 239 ms 15072 KB Output is correct
12 Correct 229 ms 15208 KB Output is correct
13 Correct 243 ms 15076 KB Output is correct
14 Correct 228 ms 15068 KB Output is correct
15 Correct 223 ms 15220 KB Output is correct
16 Correct 227 ms 15140 KB Output is correct
17 Correct 237 ms 15208 KB Output is correct
18 Correct 228 ms 15068 KB Output is correct
19 Correct 222 ms 15068 KB Output is correct
20 Correct 226 ms 15116 KB Output is correct
21 Correct 224 ms 15200 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 178 ms 14244 KB Output is correct
3 Correct 180 ms 14188 KB Output is correct
4 Correct 181 ms 14172 KB Output is correct
5 Correct 183 ms 14176 KB Output is correct
6 Correct 179 ms 14172 KB Output is correct
7 Correct 182 ms 14176 KB Output is correct
8 Correct 196 ms 14176 KB Output is correct
9 Correct 181 ms 14172 KB Output is correct
10 Correct 182 ms 14176 KB Output is correct
11 Correct 182 ms 14172 KB Output is correct
12 Correct 180 ms 14172 KB Output is correct
13 Correct 178 ms 14172 KB Output is correct
14 Correct 228 ms 14312 KB Output is correct
15 Correct 184 ms 14176 KB Output is correct
16 Correct 176 ms 14176 KB Output is correct
17 Correct 177 ms 14176 KB Output is correct
18 Correct 179 ms 14188 KB Output is correct
19 Correct 180 ms 14176 KB Output is correct
20 Correct 182 ms 14252 KB Output is correct
21 Correct 180 ms 14316 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 2 ms 512 KB Output is correct
3 Correct 2 ms 512 KB Output is correct
4 Correct 2 ms 512 KB Output is correct
5 Correct 2 ms 512 KB Output is correct
6 Correct 2 ms 640 KB Output is correct
7 Correct 2 ms 512 KB Output is correct
8 Correct 2 ms 512 KB Output is correct
9 Correct 2 ms 512 KB Output is correct
10 Correct 2 ms 512 KB Output is correct
11 Correct 2 ms 512 KB Output is correct
12 Correct 2 ms 512 KB Output is correct
13 Correct 3 ms 512 KB Output is correct
14 Correct 2 ms 512 KB Output is correct
15 Correct 0 ms 384 KB Output is correct
16 Correct 2 ms 512 KB Output is correct
17 Correct 2 ms 512 KB Output is correct
18 Correct 2 ms 512 KB Output is correct
19 Correct 2 ms 512 KB Output is correct
20 Correct 2 ms 512 KB Output is correct
21 Correct 2 ms 512 KB Output is correct
22 Correct 2 ms 512 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 0 ms 384 KB Output is correct
7 Correct 0 ms 384 KB Output is correct
8 Correct 0 ms 384 KB Output is correct
9 Correct 0 ms 384 KB Output is correct
10 Correct 0 ms 384 KB Output is correct
11 Correct 0 ms 384 KB Output is correct
12 Correct 0 ms 384 KB Output is correct
13 Correct 0 ms 384 KB Output is correct
14 Correct 0 ms 384 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 0 ms 384 KB Output is correct
17 Correct 0 ms 384 KB Output is correct
18 Correct 0 ms 384 KB Output is correct
19 Correct 0 ms 384 KB Output is correct
20 Correct 0 ms 384 KB Output is correct
21 Correct 0 ms 384 KB Output is correct
22 Correct 0 ms 384 KB Output is correct
23 Correct 0 ms 384 KB Output is correct
24 Correct 0 ms 384 KB Output is correct
25 Correct 0 ms 384 KB Output is correct
26 Correct 2 ms 512 KB Output is correct
27 Correct 2 ms 512 KB Output is correct
28 Correct 2 ms 512 KB Output is correct
29 Correct 2 ms 512 KB Output is correct
30 Correct 2 ms 640 KB Output is correct
31 Correct 2 ms 512 KB Output is correct
32 Correct 2 ms 512 KB Output is correct
33 Correct 2 ms 512 KB Output is correct
34 Correct 2 ms 512 KB Output is correct
35 Correct 2 ms 512 KB Output is correct
36 Correct 2 ms 512 KB Output is correct
37 Correct 3 ms 512 KB Output is correct
38 Correct 2 ms 512 KB Output is correct
39 Correct 0 ms 384 KB Output is correct
40 Correct 2 ms 512 KB Output is correct
41 Correct 2 ms 512 KB Output is correct
42 Correct 2 ms 512 KB Output is correct
43 Correct 2 ms 512 KB Output is correct
44 Correct 2 ms 512 KB Output is correct
45 Correct 2 ms 512 KB Output is correct
46 Correct 2 ms 512 KB Output is correct
47 Correct 1 ms 384 KB Output is correct
48 Correct 3 ms 512 KB Output is correct
49 Correct 4 ms 512 KB Output is correct
50 Correct 3 ms 512 KB Output is correct
51 Correct 3 ms 512 KB Output is correct
52 Correct 3 ms 512 KB Output is correct
53 Correct 3 ms 512 KB Output is correct
54 Correct 3 ms 512 KB Output is correct
55 Correct 3 ms 512 KB Output is correct
56 Correct 3 ms 512 KB Output is correct
57 Correct 3 ms 512 KB Output is correct
58 Correct 3 ms 512 KB Output is correct
59 Correct 3 ms 512 KB Output is correct
60 Correct 3 ms 512 KB Output is correct
61 Correct 0 ms 384 KB Output is correct
62 Correct 3 ms 512 KB Output is correct
63 Correct 3 ms 512 KB Output is correct
64 Correct 3 ms 512 KB Output is correct
65 Correct 3 ms 512 KB Output is correct
66 Correct 3 ms 512 KB Output is correct
67 Correct 3 ms 512 KB Output is correct
68 Correct 3 ms 512 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 178 ms 14244 KB Output is correct
3 Correct 180 ms 14188 KB Output is correct
4 Correct 181 ms 14172 KB Output is correct
5 Correct 183 ms 14176 KB Output is correct
6 Correct 179 ms 14172 KB Output is correct
7 Correct 182 ms 14176 KB Output is correct
8 Correct 196 ms 14176 KB Output is correct
9 Correct 181 ms 14172 KB Output is correct
10 Correct 182 ms 14176 KB Output is correct
11 Correct 182 ms 14172 KB Output is correct
12 Correct 180 ms 14172 KB Output is correct
13 Correct 178 ms 14172 KB Output is correct
14 Correct 228 ms 14312 KB Output is correct
15 Correct 184 ms 14176 KB Output is correct
16 Correct 176 ms 14176 KB Output is correct
17 Correct 177 ms 14176 KB Output is correct
18 Correct 179 ms 14188 KB Output is correct
19 Correct 180 ms 14176 KB Output is correct
20 Correct 182 ms 14252 KB Output is correct
21 Correct 180 ms 14316 KB Output is correct
22 Correct 0 ms 384 KB Output is correct
23 Correct 2 ms 512 KB Output is correct
24 Correct 2 ms 512 KB Output is correct
25 Correct 2 ms 512 KB Output is correct
26 Correct 2 ms 512 KB Output is correct
27 Correct 2 ms 640 KB Output is correct
28 Correct 2 ms 512 KB Output is correct
29 Correct 2 ms 512 KB Output is correct
30 Correct 2 ms 512 KB Output is correct
31 Correct 2 ms 512 KB Output is correct
32 Correct 2 ms 512 KB Output is correct
33 Correct 2 ms 512 KB Output is correct
34 Correct 3 ms 512 KB Output is correct
35 Correct 2 ms 512 KB Output is correct
36 Correct 0 ms 384 KB Output is correct
37 Correct 2 ms 512 KB Output is correct
38 Correct 2 ms 512 KB Output is correct
39 Correct 2 ms 512 KB Output is correct
40 Correct 2 ms 512 KB Output is correct
41 Correct 2 ms 512 KB Output is correct
42 Correct 2 ms 512 KB Output is correct
43 Correct 2 ms 512 KB Output is correct
44 Correct 0 ms 384 KB Output is correct
45 Correct 250 ms 14320 KB Output is correct
46 Correct 251 ms 14172 KB Output is correct
47 Correct 239 ms 14176 KB Output is correct
48 Correct 243 ms 14172 KB Output is correct
49 Correct 243 ms 14192 KB Output is correct
50 Correct 238 ms 14176 KB Output is correct
51 Correct 243 ms 14148 KB Output is correct
52 Correct 243 ms 14192 KB Output is correct
53 Correct 265 ms 14176 KB Output is correct
54 Correct 243 ms 14176 KB Output is correct
55 Correct 242 ms 14172 KB Output is correct
56 Correct 243 ms 14176 KB Output is correct
57 Correct 239 ms 14172 KB Output is correct
58 Correct 1 ms 384 KB Output is correct
59 Correct 242 ms 14172 KB Output is correct
60 Correct 240 ms 14148 KB Output is correct
61 Correct 241 ms 14176 KB Output is correct
62 Correct 238 ms 14172 KB Output is correct
63 Correct 238 ms 14176 KB Output is correct
64 Correct 241 ms 14172 KB Output is correct
65 Correct 236 ms 14176 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 0 ms 384 KB Output is correct
7 Correct 0 ms 384 KB Output is correct
8 Correct 0 ms 384 KB Output is correct
9 Correct 0 ms 384 KB Output is correct
10 Correct 0 ms 384 KB Output is correct
11 Correct 0 ms 384 KB Output is correct
12 Correct 0 ms 384 KB Output is correct
13 Correct 0 ms 384 KB Output is correct
14 Correct 0 ms 384 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 0 ms 384 KB Output is correct
17 Correct 0 ms 384 KB Output is correct
18 Correct 0 ms 384 KB Output is correct
19 Correct 0 ms 384 KB Output is correct
20 Correct 0 ms 384 KB Output is correct
21 Correct 0 ms 384 KB Output is correct
22 Correct 0 ms 384 KB Output is correct
23 Correct 0 ms 384 KB Output is correct
24 Correct 0 ms 384 KB Output is correct
25 Correct 0 ms 384 KB Output is correct
26 Correct 232 ms 15136 KB Output is correct
27 Correct 225 ms 15068 KB Output is correct
28 Correct 228 ms 15076 KB Output is correct
29 Correct 225 ms 15232 KB Output is correct
30 Correct 223 ms 15340 KB Output is correct
31 Correct 227 ms 15084 KB Output is correct
32 Correct 227 ms 15180 KB Output is correct
33 Correct 243 ms 15164 KB Output is correct
34 Correct 224 ms 15068 KB Output is correct
35 Correct 239 ms 15072 KB Output is correct
36 Correct 229 ms 15208 KB Output is correct
37 Correct 243 ms 15076 KB Output is correct
38 Correct 228 ms 15068 KB Output is correct
39 Correct 223 ms 15220 KB Output is correct
40 Correct 227 ms 15140 KB Output is correct
41 Correct 237 ms 15208 KB Output is correct
42 Correct 228 ms 15068 KB Output is correct
43 Correct 222 ms 15068 KB Output is correct
44 Correct 226 ms 15116 KB Output is correct
45 Correct 224 ms 15200 KB Output is correct
46 Correct 1 ms 384 KB Output is correct
47 Correct 178 ms 14244 KB Output is correct
48 Correct 180 ms 14188 KB Output is correct
49 Correct 181 ms 14172 KB Output is correct
50 Correct 183 ms 14176 KB Output is correct
51 Correct 179 ms 14172 KB Output is correct
52 Correct 182 ms 14176 KB Output is correct
53 Correct 196 ms 14176 KB Output is correct
54 Correct 181 ms 14172 KB Output is correct
55 Correct 182 ms 14176 KB Output is correct
56 Correct 182 ms 14172 KB Output is correct
57 Correct 180 ms 14172 KB Output is correct
58 Correct 178 ms 14172 KB Output is correct
59 Correct 228 ms 14312 KB Output is correct
60 Correct 184 ms 14176 KB Output is correct
61 Correct 176 ms 14176 KB Output is correct
62 Correct 177 ms 14176 KB Output is correct
63 Correct 179 ms 14188 KB Output is correct
64 Correct 180 ms 14176 KB Output is correct
65 Correct 182 ms 14252 KB Output is correct
66 Correct 180 ms 14316 KB Output is correct
67 Correct 0 ms 384 KB Output is correct
68 Correct 2 ms 512 KB Output is correct
69 Correct 2 ms 512 KB Output is correct
70 Correct 2 ms 512 KB Output is correct
71 Correct 2 ms 512 KB Output is correct
72 Correct 2 ms 640 KB Output is correct
73 Correct 2 ms 512 KB Output is correct
74 Correct 2 ms 512 KB Output is correct
75 Correct 2 ms 512 KB Output is correct
76 Correct 2 ms 512 KB Output is correct
77 Correct 2 ms 512 KB Output is correct
78 Correct 2 ms 512 KB Output is correct
79 Correct 3 ms 512 KB Output is correct
80 Correct 2 ms 512 KB Output is correct
81 Correct 0 ms 384 KB Output is correct
82 Correct 2 ms 512 KB Output is correct
83 Correct 2 ms 512 KB Output is correct
84 Correct 2 ms 512 KB Output is correct
85 Correct 2 ms 512 KB Output is correct
86 Correct 2 ms 512 KB Output is correct
87 Correct 2 ms 512 KB Output is correct
88 Correct 2 ms 512 KB Output is correct
89 Correct 1 ms 384 KB Output is correct
90 Correct 3 ms 512 KB Output is correct
91 Correct 4 ms 512 KB Output is correct
92 Correct 3 ms 512 KB Output is correct
93 Correct 3 ms 512 KB Output is correct
94 Correct 3 ms 512 KB Output is correct
95 Correct 3 ms 512 KB Output is correct
96 Correct 3 ms 512 KB Output is correct
97 Correct 3 ms 512 KB Output is correct
98 Correct 3 ms 512 KB Output is correct
99 Correct 3 ms 512 KB Output is correct
100 Correct 3 ms 512 KB Output is correct
101 Correct 3 ms 512 KB Output is correct
102 Correct 3 ms 512 KB Output is correct
103 Correct 0 ms 384 KB Output is correct
104 Correct 3 ms 512 KB Output is correct
105 Correct 3 ms 512 KB Output is correct
106 Correct 3 ms 512 KB Output is correct
107 Correct 3 ms 512 KB Output is correct
108 Correct 3 ms 512 KB Output is correct
109 Correct 3 ms 512 KB Output is correct
110 Correct 3 ms 512 KB Output is correct
111 Correct 0 ms 384 KB Output is correct
112 Correct 250 ms 14320 KB Output is correct
113 Correct 251 ms 14172 KB Output is correct
114 Correct 239 ms 14176 KB Output is correct
115 Correct 243 ms 14172 KB Output is correct
116 Correct 243 ms 14192 KB Output is correct
117 Correct 238 ms 14176 KB Output is correct
118 Correct 243 ms 14148 KB Output is correct
119 Correct 243 ms 14192 KB Output is correct
120 Correct 265 ms 14176 KB Output is correct
121 Correct 243 ms 14176 KB Output is correct
122 Correct 242 ms 14172 KB Output is correct
123 Correct 243 ms 14176 KB Output is correct
124 Correct 239 ms 14172 KB Output is correct
125 Correct 1 ms 384 KB Output is correct
126 Correct 242 ms 14172 KB Output is correct
127 Correct 240 ms 14148 KB Output is correct
128 Correct 241 ms 14176 KB Output is correct
129 Correct 238 ms 14172 KB Output is correct
130 Correct 238 ms 14176 KB Output is correct
131 Correct 241 ms 14172 KB Output is correct
132 Correct 236 ms 14176 KB Output is correct
133 Correct 0 ms 384 KB Output is correct
134 Correct 293 ms 15236 KB Output is correct
135 Correct 281 ms 15068 KB Output is correct
136 Correct 286 ms 15288 KB Output is correct
137 Correct 283 ms 15068 KB Output is correct
138 Correct 282 ms 15068 KB Output is correct
139 Correct 283 ms 15300 KB Output is correct
140 Correct 282 ms 15068 KB Output is correct
141 Correct 295 ms 15176 KB Output is correct
142 Correct 286 ms 15068 KB Output is correct
143 Correct 286 ms 15068 KB Output is correct
144 Correct 296 ms 15068 KB Output is correct
145 Correct 284 ms 15072 KB Output is correct
146 Correct 289 ms 15212 KB Output is correct
147 Correct 0 ms 384 KB Output is correct
148 Correct 285 ms 15128 KB Output is correct
149 Correct 286 ms 15068 KB Output is correct
150 Correct 286 ms 15072 KB Output is correct
151 Correct 284 ms 15068 KB Output is correct
152 Correct 288 ms 15068 KB Output is correct
153 Correct 285 ms 15068 KB Output is correct
154 Correct 284 ms 15216 KB Output is correct