답안 #261291

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
261291 2020-08-11T15:54:24 Z Haunted_Cpp Cryptography (NOI20_crypto) C++17
100 / 100
170 ms 8084 KB
/**
 *  author: Haunted_Cpp
**/
 
#include <bits/stdc++.h>
using namespace std;
 
#pragma GCC optimize("Ofast")
#pragma GCC target("fma,sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")
#pragma GCC optimize("unroll-loops")
 
template<typename T> ostream &operator << (ostream &os, const vector<T> &v) { os << '{'; string sep; for (const auto &x : v) os << sep << x, sep = ", "; return os << '}'; }
template<typename T, size_t size> ostream &operator << (ostream &os, const array<T, size> &arr) { os << '{'; string sep; for (const auto &x : arr) os << sep << x, sep = ", "; return os << '}'; }
template<typename A, typename B> ostream &operator << (ostream &os, const pair<A, B> &p) { return os << '(' << p.first << ", " << p.second << ')'; }
 
void debug_out() { cerr << endl; }
template<typename Head, typename... Tail> void debug_out(Head H, Tail... T) { cerr << ' ' << H; debug_out(T...); }
 
#ifdef LOCAL
#define debug(...) cerr << "(" << #__VA_ARGS__ << "):", debug_out(__VA_ARGS__)
#else
#define debug(...) 47
#endif

const int MAX_N = 3e5 + 5;
const int MOD = 1e9 + 7;

int f[MAX_N], bit[MAX_N];

void update(int idx, int delta) {
  for (; idx < MAX_N; idx += idx & (- idx)) {
    bit[idx] += delta;
  }
}

int query(int idx) {
  int res = 0;
  for (; idx > 0; idx -= idx & (- idx)) {
    res += bit[idx];
  }
  return res;
}

int add(int a, int b) {
  int res = a + b;
  if (res >= MOD) res -= MOD;
  if (res < 0) res += MOD;
  return res;
}

int mult(int a, int b) {
  long long res = 1LL * a * b;
  if (res >= MOD) res %= MOD;
  return res;
}

int main () {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int n;
  cin >> n;
  vector<int> arr(n);
  vector<int> c(n);
  for (int i = 0; i < n; i++) {
    cin >> arr[i];
    c[i] = arr[i];
  }
  sort(c.begin(), c.end());
  c.erase(unique(c.begin(), c.end()), c.end());
  for (auto &to : arr) {
    to = lower_bound(c.begin(), c.end(), to) - c.begin() + 1;
    update(to, +1);
  }
  f[0] = 1;
  for (int i = 1; i < MAX_N; i++) {
    f[i] = mult(f[i - 1], i);
  }
  int res = 0;
  int left = n - 1;
  for (int i = 0; i < n; left--, i++) {
    int l = query(arr[i] - 1);
    res = add(res, mult(l, f[left]));
    update(arr[i], -1);
  }
  cout << add(res, +1) << '\n';
  return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 1664 KB Output is correct
2 Correct 3 ms 1536 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 1664 KB Output is correct
2 Correct 3 ms 1536 KB Output is correct
3 Correct 3 ms 1536 KB Output is correct
4 Correct 3 ms 1536 KB Output is correct
5 Correct 3 ms 1536 KB Output is correct
6 Correct 3 ms 1536 KB Output is correct
7 Correct 3 ms 1536 KB Output is correct
8 Correct 4 ms 1536 KB Output is correct
9 Correct 3 ms 1536 KB Output is correct
10 Correct 3 ms 1536 KB Output is correct
11 Correct 3 ms 1536 KB Output is correct
12 Correct 3 ms 1536 KB Output is correct
13 Correct 3 ms 1536 KB Output is correct
14 Correct 3 ms 1536 KB Output is correct
15 Correct 3 ms 1536 KB Output is correct
16 Correct 3 ms 1536 KB Output is correct
17 Correct 3 ms 1536 KB Output is correct
18 Correct 3 ms 1536 KB Output is correct
19 Correct 3 ms 1536 KB Output is correct
20 Correct 3 ms 1536 KB Output is correct
21 Correct 3 ms 1536 KB Output is correct
22 Correct 3 ms 1536 KB Output is correct
23 Correct 3 ms 1536 KB Output is correct
24 Correct 3 ms 1536 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 1536 KB Output is correct
2 Correct 97 ms 5112 KB Output is correct
3 Correct 94 ms 7992 KB Output is correct
4 Correct 93 ms 7972 KB Output is correct
5 Correct 98 ms 7992 KB Output is correct
6 Correct 114 ms 7928 KB Output is correct
7 Correct 92 ms 7928 KB Output is correct
8 Correct 95 ms 7928 KB Output is correct
9 Correct 92 ms 7928 KB Output is correct
10 Correct 92 ms 7928 KB Output is correct
11 Correct 93 ms 7928 KB Output is correct
12 Correct 110 ms 7928 KB Output is correct
13 Correct 99 ms 7928 KB Output is correct
14 Correct 95 ms 7928 KB Output is correct
15 Correct 96 ms 7928 KB Output is correct
16 Correct 91 ms 7872 KB Output is correct
17 Correct 93 ms 7928 KB Output is correct
18 Correct 92 ms 7924 KB Output is correct
19 Correct 95 ms 7928 KB Output is correct
20 Correct 96 ms 7984 KB Output is correct
21 Correct 94 ms 8056 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 1664 KB Output is correct
2 Correct 82 ms 4984 KB Output is correct
3 Correct 85 ms 4988 KB Output is correct
4 Correct 82 ms 4984 KB Output is correct
5 Correct 86 ms 4984 KB Output is correct
6 Correct 84 ms 4984 KB Output is correct
7 Correct 83 ms 5068 KB Output is correct
8 Correct 83 ms 4984 KB Output is correct
9 Correct 85 ms 5060 KB Output is correct
10 Correct 85 ms 5052 KB Output is correct
11 Correct 94 ms 4984 KB Output is correct
12 Correct 85 ms 5000 KB Output is correct
13 Correct 82 ms 4984 KB Output is correct
14 Correct 92 ms 4984 KB Output is correct
15 Correct 81 ms 4984 KB Output is correct
16 Correct 85 ms 4984 KB Output is correct
17 Correct 85 ms 5056 KB Output is correct
18 Correct 81 ms 4984 KB Output is correct
19 Correct 84 ms 4984 KB Output is correct
20 Correct 82 ms 4984 KB Output is correct
21 Correct 82 ms 4984 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 1536 KB Output is correct
2 Correct 4 ms 1536 KB Output is correct
3 Correct 4 ms 1536 KB Output is correct
4 Correct 4 ms 1536 KB Output is correct
5 Correct 4 ms 1536 KB Output is correct
6 Correct 4 ms 1536 KB Output is correct
7 Correct 4 ms 1536 KB Output is correct
8 Correct 4 ms 1536 KB Output is correct
9 Correct 4 ms 1536 KB Output is correct
10 Correct 4 ms 1588 KB Output is correct
11 Correct 4 ms 1536 KB Output is correct
12 Correct 5 ms 1536 KB Output is correct
13 Correct 4 ms 1536 KB Output is correct
14 Correct 4 ms 1536 KB Output is correct
15 Correct 4 ms 1536 KB Output is correct
16 Correct 4 ms 1536 KB Output is correct
17 Correct 4 ms 1536 KB Output is correct
18 Correct 5 ms 1664 KB Output is correct
19 Correct 4 ms 1536 KB Output is correct
20 Correct 5 ms 1536 KB Output is correct
21 Correct 5 ms 1536 KB Output is correct
22 Correct 4 ms 1536 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 1664 KB Output is correct
2 Correct 3 ms 1536 KB Output is correct
3 Correct 3 ms 1536 KB Output is correct
4 Correct 3 ms 1536 KB Output is correct
5 Correct 3 ms 1536 KB Output is correct
6 Correct 3 ms 1536 KB Output is correct
7 Correct 3 ms 1536 KB Output is correct
8 Correct 4 ms 1536 KB Output is correct
9 Correct 3 ms 1536 KB Output is correct
10 Correct 3 ms 1536 KB Output is correct
11 Correct 3 ms 1536 KB Output is correct
12 Correct 3 ms 1536 KB Output is correct
13 Correct 3 ms 1536 KB Output is correct
14 Correct 3 ms 1536 KB Output is correct
15 Correct 3 ms 1536 KB Output is correct
16 Correct 3 ms 1536 KB Output is correct
17 Correct 3 ms 1536 KB Output is correct
18 Correct 3 ms 1536 KB Output is correct
19 Correct 3 ms 1536 KB Output is correct
20 Correct 3 ms 1536 KB Output is correct
21 Correct 3 ms 1536 KB Output is correct
22 Correct 3 ms 1536 KB Output is correct
23 Correct 3 ms 1536 KB Output is correct
24 Correct 3 ms 1536 KB Output is correct
25 Correct 5 ms 1536 KB Output is correct
26 Correct 4 ms 1536 KB Output is correct
27 Correct 4 ms 1536 KB Output is correct
28 Correct 4 ms 1536 KB Output is correct
29 Correct 4 ms 1536 KB Output is correct
30 Correct 4 ms 1536 KB Output is correct
31 Correct 4 ms 1536 KB Output is correct
32 Correct 4 ms 1536 KB Output is correct
33 Correct 4 ms 1536 KB Output is correct
34 Correct 4 ms 1588 KB Output is correct
35 Correct 4 ms 1536 KB Output is correct
36 Correct 5 ms 1536 KB Output is correct
37 Correct 4 ms 1536 KB Output is correct
38 Correct 4 ms 1536 KB Output is correct
39 Correct 4 ms 1536 KB Output is correct
40 Correct 4 ms 1536 KB Output is correct
41 Correct 4 ms 1536 KB Output is correct
42 Correct 5 ms 1664 KB Output is correct
43 Correct 4 ms 1536 KB Output is correct
44 Correct 5 ms 1536 KB Output is correct
45 Correct 5 ms 1536 KB Output is correct
46 Correct 4 ms 1536 KB Output is correct
47 Correct 4 ms 1536 KB Output is correct
48 Correct 5 ms 1664 KB Output is correct
49 Correct 5 ms 1664 KB Output is correct
50 Correct 4 ms 1664 KB Output is correct
51 Correct 5 ms 1664 KB Output is correct
52 Correct 4 ms 1664 KB Output is correct
53 Correct 4 ms 1664 KB Output is correct
54 Correct 4 ms 1664 KB Output is correct
55 Correct 4 ms 1664 KB Output is correct
56 Correct 4 ms 1664 KB Output is correct
57 Correct 4 ms 1664 KB Output is correct
58 Correct 5 ms 1664 KB Output is correct
59 Correct 5 ms 1664 KB Output is correct
60 Correct 5 ms 1664 KB Output is correct
61 Correct 3 ms 1536 KB Output is correct
62 Correct 4 ms 1664 KB Output is correct
63 Correct 4 ms 1664 KB Output is correct
64 Correct 4 ms 1664 KB Output is correct
65 Correct 4 ms 1664 KB Output is correct
66 Correct 4 ms 1664 KB Output is correct
67 Correct 5 ms 1664 KB Output is correct
68 Correct 4 ms 1664 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 1664 KB Output is correct
2 Correct 82 ms 4984 KB Output is correct
3 Correct 85 ms 4988 KB Output is correct
4 Correct 82 ms 4984 KB Output is correct
5 Correct 86 ms 4984 KB Output is correct
6 Correct 84 ms 4984 KB Output is correct
7 Correct 83 ms 5068 KB Output is correct
8 Correct 83 ms 4984 KB Output is correct
9 Correct 85 ms 5060 KB Output is correct
10 Correct 85 ms 5052 KB Output is correct
11 Correct 94 ms 4984 KB Output is correct
12 Correct 85 ms 5000 KB Output is correct
13 Correct 82 ms 4984 KB Output is correct
14 Correct 92 ms 4984 KB Output is correct
15 Correct 81 ms 4984 KB Output is correct
16 Correct 85 ms 4984 KB Output is correct
17 Correct 85 ms 5056 KB Output is correct
18 Correct 81 ms 4984 KB Output is correct
19 Correct 84 ms 4984 KB Output is correct
20 Correct 82 ms 4984 KB Output is correct
21 Correct 82 ms 4984 KB Output is correct
22 Correct 5 ms 1536 KB Output is correct
23 Correct 4 ms 1536 KB Output is correct
24 Correct 4 ms 1536 KB Output is correct
25 Correct 4 ms 1536 KB Output is correct
26 Correct 4 ms 1536 KB Output is correct
27 Correct 4 ms 1536 KB Output is correct
28 Correct 4 ms 1536 KB Output is correct
29 Correct 4 ms 1536 KB Output is correct
30 Correct 4 ms 1536 KB Output is correct
31 Correct 4 ms 1588 KB Output is correct
32 Correct 4 ms 1536 KB Output is correct
33 Correct 5 ms 1536 KB Output is correct
34 Correct 4 ms 1536 KB Output is correct
35 Correct 4 ms 1536 KB Output is correct
36 Correct 4 ms 1536 KB Output is correct
37 Correct 4 ms 1536 KB Output is correct
38 Correct 4 ms 1536 KB Output is correct
39 Correct 5 ms 1664 KB Output is correct
40 Correct 4 ms 1536 KB Output is correct
41 Correct 5 ms 1536 KB Output is correct
42 Correct 5 ms 1536 KB Output is correct
43 Correct 4 ms 1536 KB Output is correct
44 Correct 3 ms 1536 KB Output is correct
45 Correct 147 ms 6904 KB Output is correct
46 Correct 143 ms 7000 KB Output is correct
47 Correct 149 ms 7032 KB Output is correct
48 Correct 146 ms 7160 KB Output is correct
49 Correct 144 ms 7036 KB Output is correct
50 Correct 144 ms 7160 KB Output is correct
51 Correct 145 ms 7024 KB Output is correct
52 Correct 143 ms 7032 KB Output is correct
53 Correct 142 ms 7032 KB Output is correct
54 Correct 144 ms 7032 KB Output is correct
55 Correct 146 ms 6908 KB Output is correct
56 Correct 145 ms 6904 KB Output is correct
57 Correct 146 ms 7032 KB Output is correct
58 Correct 4 ms 1536 KB Output is correct
59 Correct 144 ms 6956 KB Output is correct
60 Correct 145 ms 6904 KB Output is correct
61 Correct 143 ms 7092 KB Output is correct
62 Correct 144 ms 7032 KB Output is correct
63 Correct 144 ms 6936 KB Output is correct
64 Correct 154 ms 7036 KB Output is correct
65 Correct 145 ms 6904 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 1664 KB Output is correct
2 Correct 3 ms 1536 KB Output is correct
3 Correct 3 ms 1536 KB Output is correct
4 Correct 3 ms 1536 KB Output is correct
5 Correct 3 ms 1536 KB Output is correct
6 Correct 3 ms 1536 KB Output is correct
7 Correct 3 ms 1536 KB Output is correct
8 Correct 4 ms 1536 KB Output is correct
9 Correct 3 ms 1536 KB Output is correct
10 Correct 3 ms 1536 KB Output is correct
11 Correct 3 ms 1536 KB Output is correct
12 Correct 3 ms 1536 KB Output is correct
13 Correct 3 ms 1536 KB Output is correct
14 Correct 3 ms 1536 KB Output is correct
15 Correct 3 ms 1536 KB Output is correct
16 Correct 3 ms 1536 KB Output is correct
17 Correct 3 ms 1536 KB Output is correct
18 Correct 3 ms 1536 KB Output is correct
19 Correct 3 ms 1536 KB Output is correct
20 Correct 3 ms 1536 KB Output is correct
21 Correct 3 ms 1536 KB Output is correct
22 Correct 3 ms 1536 KB Output is correct
23 Correct 3 ms 1536 KB Output is correct
24 Correct 3 ms 1536 KB Output is correct
25 Correct 3 ms 1536 KB Output is correct
26 Correct 97 ms 5112 KB Output is correct
27 Correct 94 ms 7992 KB Output is correct
28 Correct 93 ms 7972 KB Output is correct
29 Correct 98 ms 7992 KB Output is correct
30 Correct 114 ms 7928 KB Output is correct
31 Correct 92 ms 7928 KB Output is correct
32 Correct 95 ms 7928 KB Output is correct
33 Correct 92 ms 7928 KB Output is correct
34 Correct 92 ms 7928 KB Output is correct
35 Correct 93 ms 7928 KB Output is correct
36 Correct 110 ms 7928 KB Output is correct
37 Correct 99 ms 7928 KB Output is correct
38 Correct 95 ms 7928 KB Output is correct
39 Correct 96 ms 7928 KB Output is correct
40 Correct 91 ms 7872 KB Output is correct
41 Correct 93 ms 7928 KB Output is correct
42 Correct 92 ms 7924 KB Output is correct
43 Correct 95 ms 7928 KB Output is correct
44 Correct 96 ms 7984 KB Output is correct
45 Correct 94 ms 8056 KB Output is correct
46 Correct 3 ms 1664 KB Output is correct
47 Correct 82 ms 4984 KB Output is correct
48 Correct 85 ms 4988 KB Output is correct
49 Correct 82 ms 4984 KB Output is correct
50 Correct 86 ms 4984 KB Output is correct
51 Correct 84 ms 4984 KB Output is correct
52 Correct 83 ms 5068 KB Output is correct
53 Correct 83 ms 4984 KB Output is correct
54 Correct 85 ms 5060 KB Output is correct
55 Correct 85 ms 5052 KB Output is correct
56 Correct 94 ms 4984 KB Output is correct
57 Correct 85 ms 5000 KB Output is correct
58 Correct 82 ms 4984 KB Output is correct
59 Correct 92 ms 4984 KB Output is correct
60 Correct 81 ms 4984 KB Output is correct
61 Correct 85 ms 4984 KB Output is correct
62 Correct 85 ms 5056 KB Output is correct
63 Correct 81 ms 4984 KB Output is correct
64 Correct 84 ms 4984 KB Output is correct
65 Correct 82 ms 4984 KB Output is correct
66 Correct 82 ms 4984 KB Output is correct
67 Correct 5 ms 1536 KB Output is correct
68 Correct 4 ms 1536 KB Output is correct
69 Correct 4 ms 1536 KB Output is correct
70 Correct 4 ms 1536 KB Output is correct
71 Correct 4 ms 1536 KB Output is correct
72 Correct 4 ms 1536 KB Output is correct
73 Correct 4 ms 1536 KB Output is correct
74 Correct 4 ms 1536 KB Output is correct
75 Correct 4 ms 1536 KB Output is correct
76 Correct 4 ms 1588 KB Output is correct
77 Correct 4 ms 1536 KB Output is correct
78 Correct 5 ms 1536 KB Output is correct
79 Correct 4 ms 1536 KB Output is correct
80 Correct 4 ms 1536 KB Output is correct
81 Correct 4 ms 1536 KB Output is correct
82 Correct 4 ms 1536 KB Output is correct
83 Correct 4 ms 1536 KB Output is correct
84 Correct 5 ms 1664 KB Output is correct
85 Correct 4 ms 1536 KB Output is correct
86 Correct 5 ms 1536 KB Output is correct
87 Correct 5 ms 1536 KB Output is correct
88 Correct 4 ms 1536 KB Output is correct
89 Correct 4 ms 1536 KB Output is correct
90 Correct 5 ms 1664 KB Output is correct
91 Correct 5 ms 1664 KB Output is correct
92 Correct 4 ms 1664 KB Output is correct
93 Correct 5 ms 1664 KB Output is correct
94 Correct 4 ms 1664 KB Output is correct
95 Correct 4 ms 1664 KB Output is correct
96 Correct 4 ms 1664 KB Output is correct
97 Correct 4 ms 1664 KB Output is correct
98 Correct 4 ms 1664 KB Output is correct
99 Correct 4 ms 1664 KB Output is correct
100 Correct 5 ms 1664 KB Output is correct
101 Correct 5 ms 1664 KB Output is correct
102 Correct 5 ms 1664 KB Output is correct
103 Correct 3 ms 1536 KB Output is correct
104 Correct 4 ms 1664 KB Output is correct
105 Correct 4 ms 1664 KB Output is correct
106 Correct 4 ms 1664 KB Output is correct
107 Correct 4 ms 1664 KB Output is correct
108 Correct 4 ms 1664 KB Output is correct
109 Correct 5 ms 1664 KB Output is correct
110 Correct 4 ms 1664 KB Output is correct
111 Correct 3 ms 1536 KB Output is correct
112 Correct 147 ms 6904 KB Output is correct
113 Correct 143 ms 7000 KB Output is correct
114 Correct 149 ms 7032 KB Output is correct
115 Correct 146 ms 7160 KB Output is correct
116 Correct 144 ms 7036 KB Output is correct
117 Correct 144 ms 7160 KB Output is correct
118 Correct 145 ms 7024 KB Output is correct
119 Correct 143 ms 7032 KB Output is correct
120 Correct 142 ms 7032 KB Output is correct
121 Correct 144 ms 7032 KB Output is correct
122 Correct 146 ms 6908 KB Output is correct
123 Correct 145 ms 6904 KB Output is correct
124 Correct 146 ms 7032 KB Output is correct
125 Correct 4 ms 1536 KB Output is correct
126 Correct 144 ms 6956 KB Output is correct
127 Correct 145 ms 6904 KB Output is correct
128 Correct 143 ms 7092 KB Output is correct
129 Correct 144 ms 7032 KB Output is correct
130 Correct 144 ms 6936 KB Output is correct
131 Correct 154 ms 7036 KB Output is correct
132 Correct 145 ms 6904 KB Output is correct
133 Correct 5 ms 1536 KB Output is correct
134 Correct 164 ms 8056 KB Output is correct
135 Correct 155 ms 7984 KB Output is correct
136 Correct 164 ms 8060 KB Output is correct
137 Correct 157 ms 7928 KB Output is correct
138 Correct 153 ms 7928 KB Output is correct
139 Correct 157 ms 8084 KB Output is correct
140 Correct 152 ms 7928 KB Output is correct
141 Correct 155 ms 7928 KB Output is correct
142 Correct 152 ms 8064 KB Output is correct
143 Correct 153 ms 7928 KB Output is correct
144 Correct 163 ms 7928 KB Output is correct
145 Correct 155 ms 7928 KB Output is correct
146 Correct 159 ms 7928 KB Output is correct
147 Correct 3 ms 1536 KB Output is correct
148 Correct 170 ms 7988 KB Output is correct
149 Correct 155 ms 7928 KB Output is correct
150 Correct 162 ms 7932 KB Output is correct
151 Correct 153 ms 8056 KB Output is correct
152 Correct 152 ms 7928 KB Output is correct
153 Correct 155 ms 7984 KB Output is correct
154 Correct 154 ms 7928 KB Output is correct