Submission #337348

# Submission time Handle Problem Language Result Execution time Memory
337348 2020-12-20T03:40:17 Z quocnguyen1012 Cryptography (NOI20_crypto) C++14
100 / 100
159 ms 8164 KB
#include <bits/stdc++.h>

using namespace std;
using ll = long long;

const int maxn = 3e5 + 5, mod = 1e9 + 7;

struct BIT {
  int bit[maxn];
  void upd(int i, int v) {
    for (; i < maxn; i += i & -i)
      bit[i] += v;
  }
  int query(int i) {
    int ret = 0;
    for (; i; i -= i & -i) {
      ret += bit[i];
    }
    return ret;
  }
}ft;

int N, a[maxn], fact[maxn];
vector<int> val;

signed main(void) {
  ios_base::sync_with_stdio(0);
	cin.tie(0);
#ifdef LOCAL
	freopen("A.INP", "r", stdin);
	freopen("A.OUT", "w", stdout);
#endif // LOCAL
  fact[0] = 1;
  for (int i = 1; i < maxn; ++i)
    fact[i] = 1ll * fact[i - 1] * i % mod;
  cin >> N;
  for (int i = 1; i <= N; ++i) {
    cin >> a[i];
    val.push_back(a[i]);
  }
  sort(val.begin(), val.end());
  val.erase(unique(val.begin(), val.end()), val.end());
  assert(val.size() == N);
  for (int i = 1; i <= N; ++i) {
    a[i] = lower_bound(val.begin(), val.end(), a[i]) - val.begin() + 1;
  }
  int ret = 0;
  for (int i = 1; i <= N; ++i) {
    int val = ft.query(a[i] - 1);
    (ret += 1ll * (a[i] - val - 1) * fact[N - i] % mod) %= mod;
    ft.upd(a[i], 1);
    //cerr << 1ll * (a[i] - val - 1) * fact[N - i] << ' ';
  }
  cout << (ret + 1) % mod;
}

Compilation message

In file included from /usr/include/c++/9/cassert:44,
                 from /usr/include/x86_64-linux-gnu/c++/9/bits/stdc++.h:33,
                 from Crypto.cpp:1:
Crypto.cpp: In function 'int main()':
Crypto.cpp:43:21: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   43 |   assert(val.size() == N);
      |          ~~~~~~~~~~~^~~~
# Verdict Execution time Memory Grader output
1 Correct 3 ms 1516 KB Output is correct
2 Correct 3 ms 1516 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 1516 KB Output is correct
2 Correct 3 ms 1516 KB Output is correct
3 Correct 3 ms 1516 KB Output is correct
4 Correct 3 ms 1516 KB Output is correct
5 Correct 3 ms 1516 KB Output is correct
6 Correct 3 ms 1516 KB Output is correct
7 Correct 3 ms 1516 KB Output is correct
8 Correct 3 ms 1516 KB Output is correct
9 Correct 3 ms 1516 KB Output is correct
10 Correct 3 ms 1516 KB Output is correct
11 Correct 3 ms 1516 KB Output is correct
12 Correct 3 ms 1520 KB Output is correct
13 Correct 3 ms 1516 KB Output is correct
14 Correct 3 ms 1516 KB Output is correct
15 Correct 3 ms 1516 KB Output is correct
16 Correct 3 ms 1536 KB Output is correct
17 Correct 3 ms 1516 KB Output is correct
18 Correct 5 ms 1516 KB Output is correct
19 Correct 4 ms 1516 KB Output is correct
20 Correct 3 ms 1592 KB Output is correct
21 Correct 4 ms 1516 KB Output is correct
22 Correct 3 ms 1516 KB Output is correct
23 Correct 3 ms 1516 KB Output is correct
24 Correct 4 ms 1516 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 1516 KB Output is correct
2 Correct 77 ms 8164 KB Output is correct
3 Correct 87 ms 8036 KB Output is correct
4 Correct 89 ms 8036 KB Output is correct
5 Correct 72 ms 8036 KB Output is correct
6 Correct 114 ms 8036 KB Output is correct
7 Correct 75 ms 8056 KB Output is correct
8 Correct 75 ms 8036 KB Output is correct
9 Correct 122 ms 8036 KB Output is correct
10 Correct 98 ms 8164 KB Output is correct
11 Correct 77 ms 8036 KB Output is correct
12 Correct 87 ms 8036 KB Output is correct
13 Correct 88 ms 8036 KB Output is correct
14 Correct 79 ms 8036 KB Output is correct
15 Correct 80 ms 8088 KB Output is correct
16 Correct 78 ms 8112 KB Output is correct
17 Correct 78 ms 8036 KB Output is correct
18 Correct 79 ms 8036 KB Output is correct
19 Correct 76 ms 8036 KB Output is correct
20 Correct 75 ms 8144 KB Output is correct
21 Correct 82 ms 8036 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 1516 KB Output is correct
2 Correct 72 ms 7140 KB Output is correct
3 Correct 81 ms 7140 KB Output is correct
4 Correct 71 ms 7156 KB Output is correct
5 Correct 69 ms 7140 KB Output is correct
6 Correct 79 ms 7176 KB Output is correct
7 Correct 67 ms 7140 KB Output is correct
8 Correct 71 ms 7140 KB Output is correct
9 Correct 68 ms 7140 KB Output is correct
10 Correct 68 ms 7140 KB Output is correct
11 Correct 71 ms 7140 KB Output is correct
12 Correct 72 ms 7172 KB Output is correct
13 Correct 67 ms 7140 KB Output is correct
14 Correct 68 ms 7140 KB Output is correct
15 Correct 73 ms 7140 KB Output is correct
16 Correct 70 ms 7140 KB Output is correct
17 Correct 75 ms 7268 KB Output is correct
18 Correct 72 ms 7140 KB Output is correct
19 Correct 72 ms 7140 KB Output is correct
20 Correct 77 ms 7140 KB Output is correct
21 Correct 71 ms 7140 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 1516 KB Output is correct
2 Correct 5 ms 1644 KB Output is correct
3 Correct 5 ms 1644 KB Output is correct
4 Correct 5 ms 1644 KB Output is correct
5 Correct 5 ms 1644 KB Output is correct
6 Correct 4 ms 1644 KB Output is correct
7 Correct 4 ms 1644 KB Output is correct
8 Correct 4 ms 1644 KB Output is correct
9 Correct 4 ms 1644 KB Output is correct
10 Correct 4 ms 1644 KB Output is correct
11 Correct 4 ms 1644 KB Output is correct
12 Correct 4 ms 1644 KB Output is correct
13 Correct 4 ms 1644 KB Output is correct
14 Correct 4 ms 1644 KB Output is correct
15 Correct 3 ms 1516 KB Output is correct
16 Correct 4 ms 1644 KB Output is correct
17 Correct 4 ms 1644 KB Output is correct
18 Correct 4 ms 1644 KB Output is correct
19 Correct 4 ms 1644 KB Output is correct
20 Correct 4 ms 1644 KB Output is correct
21 Correct 4 ms 1644 KB Output is correct
22 Correct 4 ms 1644 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 1516 KB Output is correct
2 Correct 3 ms 1516 KB Output is correct
3 Correct 3 ms 1516 KB Output is correct
4 Correct 3 ms 1516 KB Output is correct
5 Correct 3 ms 1516 KB Output is correct
6 Correct 3 ms 1516 KB Output is correct
7 Correct 3 ms 1516 KB Output is correct
8 Correct 3 ms 1516 KB Output is correct
9 Correct 3 ms 1516 KB Output is correct
10 Correct 3 ms 1516 KB Output is correct
11 Correct 3 ms 1516 KB Output is correct
12 Correct 3 ms 1520 KB Output is correct
13 Correct 3 ms 1516 KB Output is correct
14 Correct 3 ms 1516 KB Output is correct
15 Correct 3 ms 1516 KB Output is correct
16 Correct 3 ms 1536 KB Output is correct
17 Correct 3 ms 1516 KB Output is correct
18 Correct 5 ms 1516 KB Output is correct
19 Correct 4 ms 1516 KB Output is correct
20 Correct 3 ms 1592 KB Output is correct
21 Correct 4 ms 1516 KB Output is correct
22 Correct 3 ms 1516 KB Output is correct
23 Correct 3 ms 1516 KB Output is correct
24 Correct 4 ms 1516 KB Output is correct
25 Correct 4 ms 1516 KB Output is correct
26 Correct 5 ms 1644 KB Output is correct
27 Correct 5 ms 1644 KB Output is correct
28 Correct 5 ms 1644 KB Output is correct
29 Correct 5 ms 1644 KB Output is correct
30 Correct 4 ms 1644 KB Output is correct
31 Correct 4 ms 1644 KB Output is correct
32 Correct 4 ms 1644 KB Output is correct
33 Correct 4 ms 1644 KB Output is correct
34 Correct 4 ms 1644 KB Output is correct
35 Correct 4 ms 1644 KB Output is correct
36 Correct 4 ms 1644 KB Output is correct
37 Correct 4 ms 1644 KB Output is correct
38 Correct 4 ms 1644 KB Output is correct
39 Correct 3 ms 1516 KB Output is correct
40 Correct 4 ms 1644 KB Output is correct
41 Correct 4 ms 1644 KB Output is correct
42 Correct 4 ms 1644 KB Output is correct
43 Correct 4 ms 1644 KB Output is correct
44 Correct 4 ms 1644 KB Output is correct
45 Correct 4 ms 1644 KB Output is correct
46 Correct 4 ms 1644 KB Output is correct
47 Correct 3 ms 1516 KB Output is correct
48 Correct 5 ms 1644 KB Output is correct
49 Correct 4 ms 1644 KB Output is correct
50 Correct 4 ms 1644 KB Output is correct
51 Correct 4 ms 1644 KB Output is correct
52 Correct 5 ms 1644 KB Output is correct
53 Correct 4 ms 1644 KB Output is correct
54 Correct 5 ms 1644 KB Output is correct
55 Correct 5 ms 1644 KB Output is correct
56 Correct 4 ms 1644 KB Output is correct
57 Correct 5 ms 1644 KB Output is correct
58 Correct 4 ms 1644 KB Output is correct
59 Correct 4 ms 1644 KB Output is correct
60 Correct 4 ms 1644 KB Output is correct
61 Correct 3 ms 1516 KB Output is correct
62 Correct 4 ms 1644 KB Output is correct
63 Correct 5 ms 1676 KB Output is correct
64 Correct 5 ms 1644 KB Output is correct
65 Correct 4 ms 1644 KB Output is correct
66 Correct 4 ms 1644 KB Output is correct
67 Correct 4 ms 1644 KB Output is correct
68 Correct 4 ms 1644 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 1516 KB Output is correct
2 Correct 72 ms 7140 KB Output is correct
3 Correct 81 ms 7140 KB Output is correct
4 Correct 71 ms 7156 KB Output is correct
5 Correct 69 ms 7140 KB Output is correct
6 Correct 79 ms 7176 KB Output is correct
7 Correct 67 ms 7140 KB Output is correct
8 Correct 71 ms 7140 KB Output is correct
9 Correct 68 ms 7140 KB Output is correct
10 Correct 68 ms 7140 KB Output is correct
11 Correct 71 ms 7140 KB Output is correct
12 Correct 72 ms 7172 KB Output is correct
13 Correct 67 ms 7140 KB Output is correct
14 Correct 68 ms 7140 KB Output is correct
15 Correct 73 ms 7140 KB Output is correct
16 Correct 70 ms 7140 KB Output is correct
17 Correct 75 ms 7268 KB Output is correct
18 Correct 72 ms 7140 KB Output is correct
19 Correct 72 ms 7140 KB Output is correct
20 Correct 77 ms 7140 KB Output is correct
21 Correct 71 ms 7140 KB Output is correct
22 Correct 4 ms 1516 KB Output is correct
23 Correct 5 ms 1644 KB Output is correct
24 Correct 5 ms 1644 KB Output is correct
25 Correct 5 ms 1644 KB Output is correct
26 Correct 5 ms 1644 KB Output is correct
27 Correct 4 ms 1644 KB Output is correct
28 Correct 4 ms 1644 KB Output is correct
29 Correct 4 ms 1644 KB Output is correct
30 Correct 4 ms 1644 KB Output is correct
31 Correct 4 ms 1644 KB Output is correct
32 Correct 4 ms 1644 KB Output is correct
33 Correct 4 ms 1644 KB Output is correct
34 Correct 4 ms 1644 KB Output is correct
35 Correct 4 ms 1644 KB Output is correct
36 Correct 3 ms 1516 KB Output is correct
37 Correct 4 ms 1644 KB Output is correct
38 Correct 4 ms 1644 KB Output is correct
39 Correct 4 ms 1644 KB Output is correct
40 Correct 4 ms 1644 KB Output is correct
41 Correct 4 ms 1644 KB Output is correct
42 Correct 4 ms 1644 KB Output is correct
43 Correct 4 ms 1644 KB Output is correct
44 Correct 4 ms 1516 KB Output is correct
45 Correct 137 ms 7140 KB Output is correct
46 Correct 136 ms 7140 KB Output is correct
47 Correct 137 ms 7268 KB Output is correct
48 Correct 134 ms 7140 KB Output is correct
49 Correct 137 ms 7140 KB Output is correct
50 Correct 125 ms 7140 KB Output is correct
51 Correct 128 ms 7156 KB Output is correct
52 Correct 127 ms 7140 KB Output is correct
53 Correct 158 ms 7140 KB Output is correct
54 Correct 127 ms 7140 KB Output is correct
55 Correct 146 ms 7140 KB Output is correct
56 Correct 139 ms 7172 KB Output is correct
57 Correct 158 ms 7140 KB Output is correct
58 Correct 3 ms 1516 KB Output is correct
59 Correct 131 ms 7140 KB Output is correct
60 Correct 127 ms 7140 KB Output is correct
61 Correct 129 ms 7140 KB Output is correct
62 Correct 136 ms 7140 KB Output is correct
63 Correct 137 ms 7276 KB Output is correct
64 Correct 141 ms 7140 KB Output is correct
65 Correct 127 ms 7160 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 1516 KB Output is correct
2 Correct 3 ms 1516 KB Output is correct
3 Correct 3 ms 1516 KB Output is correct
4 Correct 3 ms 1516 KB Output is correct
5 Correct 3 ms 1516 KB Output is correct
6 Correct 3 ms 1516 KB Output is correct
7 Correct 3 ms 1516 KB Output is correct
8 Correct 3 ms 1516 KB Output is correct
9 Correct 3 ms 1516 KB Output is correct
10 Correct 3 ms 1516 KB Output is correct
11 Correct 3 ms 1516 KB Output is correct
12 Correct 3 ms 1520 KB Output is correct
13 Correct 3 ms 1516 KB Output is correct
14 Correct 3 ms 1516 KB Output is correct
15 Correct 3 ms 1516 KB Output is correct
16 Correct 3 ms 1536 KB Output is correct
17 Correct 3 ms 1516 KB Output is correct
18 Correct 5 ms 1516 KB Output is correct
19 Correct 4 ms 1516 KB Output is correct
20 Correct 3 ms 1592 KB Output is correct
21 Correct 4 ms 1516 KB Output is correct
22 Correct 3 ms 1516 KB Output is correct
23 Correct 3 ms 1516 KB Output is correct
24 Correct 4 ms 1516 KB Output is correct
25 Correct 4 ms 1516 KB Output is correct
26 Correct 77 ms 8164 KB Output is correct
27 Correct 87 ms 8036 KB Output is correct
28 Correct 89 ms 8036 KB Output is correct
29 Correct 72 ms 8036 KB Output is correct
30 Correct 114 ms 8036 KB Output is correct
31 Correct 75 ms 8056 KB Output is correct
32 Correct 75 ms 8036 KB Output is correct
33 Correct 122 ms 8036 KB Output is correct
34 Correct 98 ms 8164 KB Output is correct
35 Correct 77 ms 8036 KB Output is correct
36 Correct 87 ms 8036 KB Output is correct
37 Correct 88 ms 8036 KB Output is correct
38 Correct 79 ms 8036 KB Output is correct
39 Correct 80 ms 8088 KB Output is correct
40 Correct 78 ms 8112 KB Output is correct
41 Correct 78 ms 8036 KB Output is correct
42 Correct 79 ms 8036 KB Output is correct
43 Correct 76 ms 8036 KB Output is correct
44 Correct 75 ms 8144 KB Output is correct
45 Correct 82 ms 8036 KB Output is correct
46 Correct 3 ms 1516 KB Output is correct
47 Correct 72 ms 7140 KB Output is correct
48 Correct 81 ms 7140 KB Output is correct
49 Correct 71 ms 7156 KB Output is correct
50 Correct 69 ms 7140 KB Output is correct
51 Correct 79 ms 7176 KB Output is correct
52 Correct 67 ms 7140 KB Output is correct
53 Correct 71 ms 7140 KB Output is correct
54 Correct 68 ms 7140 KB Output is correct
55 Correct 68 ms 7140 KB Output is correct
56 Correct 71 ms 7140 KB Output is correct
57 Correct 72 ms 7172 KB Output is correct
58 Correct 67 ms 7140 KB Output is correct
59 Correct 68 ms 7140 KB Output is correct
60 Correct 73 ms 7140 KB Output is correct
61 Correct 70 ms 7140 KB Output is correct
62 Correct 75 ms 7268 KB Output is correct
63 Correct 72 ms 7140 KB Output is correct
64 Correct 72 ms 7140 KB Output is correct
65 Correct 77 ms 7140 KB Output is correct
66 Correct 71 ms 7140 KB Output is correct
67 Correct 4 ms 1516 KB Output is correct
68 Correct 5 ms 1644 KB Output is correct
69 Correct 5 ms 1644 KB Output is correct
70 Correct 5 ms 1644 KB Output is correct
71 Correct 5 ms 1644 KB Output is correct
72 Correct 4 ms 1644 KB Output is correct
73 Correct 4 ms 1644 KB Output is correct
74 Correct 4 ms 1644 KB Output is correct
75 Correct 4 ms 1644 KB Output is correct
76 Correct 4 ms 1644 KB Output is correct
77 Correct 4 ms 1644 KB Output is correct
78 Correct 4 ms 1644 KB Output is correct
79 Correct 4 ms 1644 KB Output is correct
80 Correct 4 ms 1644 KB Output is correct
81 Correct 3 ms 1516 KB Output is correct
82 Correct 4 ms 1644 KB Output is correct
83 Correct 4 ms 1644 KB Output is correct
84 Correct 4 ms 1644 KB Output is correct
85 Correct 4 ms 1644 KB Output is correct
86 Correct 4 ms 1644 KB Output is correct
87 Correct 4 ms 1644 KB Output is correct
88 Correct 4 ms 1644 KB Output is correct
89 Correct 3 ms 1516 KB Output is correct
90 Correct 5 ms 1644 KB Output is correct
91 Correct 4 ms 1644 KB Output is correct
92 Correct 4 ms 1644 KB Output is correct
93 Correct 4 ms 1644 KB Output is correct
94 Correct 5 ms 1644 KB Output is correct
95 Correct 4 ms 1644 KB Output is correct
96 Correct 5 ms 1644 KB Output is correct
97 Correct 5 ms 1644 KB Output is correct
98 Correct 4 ms 1644 KB Output is correct
99 Correct 5 ms 1644 KB Output is correct
100 Correct 4 ms 1644 KB Output is correct
101 Correct 4 ms 1644 KB Output is correct
102 Correct 4 ms 1644 KB Output is correct
103 Correct 3 ms 1516 KB Output is correct
104 Correct 4 ms 1644 KB Output is correct
105 Correct 5 ms 1676 KB Output is correct
106 Correct 5 ms 1644 KB Output is correct
107 Correct 4 ms 1644 KB Output is correct
108 Correct 4 ms 1644 KB Output is correct
109 Correct 4 ms 1644 KB Output is correct
110 Correct 4 ms 1644 KB Output is correct
111 Correct 4 ms 1516 KB Output is correct
112 Correct 137 ms 7140 KB Output is correct
113 Correct 136 ms 7140 KB Output is correct
114 Correct 137 ms 7268 KB Output is correct
115 Correct 134 ms 7140 KB Output is correct
116 Correct 137 ms 7140 KB Output is correct
117 Correct 125 ms 7140 KB Output is correct
118 Correct 128 ms 7156 KB Output is correct
119 Correct 127 ms 7140 KB Output is correct
120 Correct 158 ms 7140 KB Output is correct
121 Correct 127 ms 7140 KB Output is correct
122 Correct 146 ms 7140 KB Output is correct
123 Correct 139 ms 7172 KB Output is correct
124 Correct 158 ms 7140 KB Output is correct
125 Correct 3 ms 1516 KB Output is correct
126 Correct 131 ms 7140 KB Output is correct
127 Correct 127 ms 7140 KB Output is correct
128 Correct 129 ms 7140 KB Output is correct
129 Correct 136 ms 7140 KB Output is correct
130 Correct 137 ms 7276 KB Output is correct
131 Correct 141 ms 7140 KB Output is correct
132 Correct 127 ms 7160 KB Output is correct
133 Correct 4 ms 1516 KB Output is correct
134 Correct 144 ms 8036 KB Output is correct
135 Correct 134 ms 8036 KB Output is correct
136 Correct 131 ms 8036 KB Output is correct
137 Correct 150 ms 8164 KB Output is correct
138 Correct 159 ms 8036 KB Output is correct
139 Correct 152 ms 8036 KB Output is correct
140 Correct 145 ms 8036 KB Output is correct
141 Correct 144 ms 8128 KB Output is correct
142 Correct 131 ms 8128 KB Output is correct
143 Correct 150 ms 8036 KB Output is correct
144 Correct 142 ms 8164 KB Output is correct
145 Correct 136 ms 8128 KB Output is correct
146 Correct 131 ms 8036 KB Output is correct
147 Correct 3 ms 1516 KB Output is correct
148 Correct 141 ms 8120 KB Output is correct
149 Correct 133 ms 8036 KB Output is correct
150 Correct 135 ms 8128 KB Output is correct
151 Correct 131 ms 8036 KB Output is correct
152 Correct 129 ms 8036 KB Output is correct
153 Correct 144 ms 8036 KB Output is correct
154 Correct 156 ms 8100 KB Output is correct