답안 #332993

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
332993 2020-12-04T08:10:12 Z Cantfindme Cryptography (NOI20_crypto) C++17
100 / 100
143 ms 12780 KB
#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int,int> pi;
#define f first
#define s second
#define FAST ios_base::sync_with_stdio(0); cin.tie(0);
#define all(x) x.begin(),x.end()
const int maxn = 300010;
const int mod = 1e9+7;

int n;

int ft[maxn];
int fac[maxn];

vector <int> disc(vector <int> V) {
	vector <int> dis = V;
	sort(dis.begin(),dis.end());
	dis.resize(unique(dis.begin(),dis.end()) - dis.begin());
	for (int i =0;i<(int)V.size();i++) {
		V[i] = lower_bound(dis.begin(),dis.end(),V[i]) - dis.begin() + 1;
	}
	return V;
}

int ls(int x) {
	return x & (-x);
}

void up(int x, int v) {
	for (;x <= n; x += ls(x)) ft[x] += v;
}

int query(int x) {
	int res = 0;
	for (; x; x -= ls(x)) res += ft[x];
	return res;
}

void add(int &a, int b) {
	a += b;
	a %= mod;
}

int32_t main() {
	FAST
	cin >> n;
	vector <int> v(n);
	fac[0] = 1;
	for (int i =1;i<=n;i++) {
		fac[i] = (fac[i-1] * i) % mod;
	}
	
	for (int i =0;i<n;i++) {
		cin >> v[i];
	}
	v = disc(v);
	
	//cout << "HELLO\n";
	//for (int i =1;i<=n;i++) {
		//cout << v[i-1] << "\n";
	//}
	
	int ans = 0;
	for (int i =1;i<=n;i++) {
		int x = v[i-1];
		int taken = query(x-1);
		if (x-taken-1 > 0) {
			//cout << x << " " << taken << " " << fac[n-i] << "\n"; 
			int res = ((x - taken - 1) * fac[n-i] % mod)%mod;
			add(ans,res%mod);
		}
		up(x,1);
	}
	cout << (ans+1)%mod;
	
}

# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
17 Correct 1 ms 364 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
19 Correct 1 ms 364 KB Output is correct
20 Correct 1 ms 364 KB Output is correct
21 Correct 1 ms 364 KB Output is correct
22 Correct 1 ms 364 KB Output is correct
23 Correct 1 ms 364 KB Output is correct
24 Correct 1 ms 364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 79 ms 12676 KB Output is correct
3 Correct 77 ms 12652 KB Output is correct
4 Correct 77 ms 12652 KB Output is correct
5 Correct 79 ms 12780 KB Output is correct
6 Correct 79 ms 12652 KB Output is correct
7 Correct 79 ms 12652 KB Output is correct
8 Correct 80 ms 12652 KB Output is correct
9 Correct 81 ms 12652 KB Output is correct
10 Correct 80 ms 12652 KB Output is correct
11 Correct 82 ms 12652 KB Output is correct
12 Correct 79 ms 12652 KB Output is correct
13 Correct 78 ms 12652 KB Output is correct
14 Correct 78 ms 12652 KB Output is correct
15 Correct 79 ms 12652 KB Output is correct
16 Correct 80 ms 12652 KB Output is correct
17 Correct 79 ms 12652 KB Output is correct
18 Correct 81 ms 12652 KB Output is correct
19 Correct 82 ms 12780 KB Output is correct
20 Correct 78 ms 12652 KB Output is correct
21 Correct 90 ms 12652 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 75 ms 11628 KB Output is correct
3 Correct 73 ms 11628 KB Output is correct
4 Correct 74 ms 11628 KB Output is correct
5 Correct 72 ms 11628 KB Output is correct
6 Correct 82 ms 11628 KB Output is correct
7 Correct 71 ms 11628 KB Output is correct
8 Correct 73 ms 11628 KB Output is correct
9 Correct 78 ms 11756 KB Output is correct
10 Correct 73 ms 11756 KB Output is correct
11 Correct 72 ms 11756 KB Output is correct
12 Correct 72 ms 11628 KB Output is correct
13 Correct 72 ms 11628 KB Output is correct
14 Correct 71 ms 11628 KB Output is correct
15 Correct 73 ms 11628 KB Output is correct
16 Correct 72 ms 11628 KB Output is correct
17 Correct 72 ms 11628 KB Output is correct
18 Correct 72 ms 11756 KB Output is correct
19 Correct 71 ms 11756 KB Output is correct
20 Correct 71 ms 11756 KB Output is correct
21 Correct 72 ms 11628 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 492 KB Output is correct
3 Correct 2 ms 492 KB Output is correct
4 Correct 2 ms 492 KB Output is correct
5 Correct 1 ms 492 KB Output is correct
6 Correct 2 ms 492 KB Output is correct
7 Correct 1 ms 492 KB Output is correct
8 Correct 1 ms 492 KB Output is correct
9 Correct 2 ms 492 KB Output is correct
10 Correct 1 ms 492 KB Output is correct
11 Correct 2 ms 508 KB Output is correct
12 Correct 1 ms 492 KB Output is correct
13 Correct 2 ms 492 KB Output is correct
14 Correct 1 ms 492 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 2 ms 492 KB Output is correct
17 Correct 2 ms 492 KB Output is correct
18 Correct 2 ms 492 KB Output is correct
19 Correct 1 ms 492 KB Output is correct
20 Correct 1 ms 492 KB Output is correct
21 Correct 1 ms 492 KB Output is correct
22 Correct 2 ms 492 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
17 Correct 1 ms 364 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
19 Correct 1 ms 364 KB Output is correct
20 Correct 1 ms 364 KB Output is correct
21 Correct 1 ms 364 KB Output is correct
22 Correct 1 ms 364 KB Output is correct
23 Correct 1 ms 364 KB Output is correct
24 Correct 1 ms 364 KB Output is correct
25 Correct 1 ms 364 KB Output is correct
26 Correct 1 ms 492 KB Output is correct
27 Correct 2 ms 492 KB Output is correct
28 Correct 2 ms 492 KB Output is correct
29 Correct 1 ms 492 KB Output is correct
30 Correct 2 ms 492 KB Output is correct
31 Correct 1 ms 492 KB Output is correct
32 Correct 1 ms 492 KB Output is correct
33 Correct 2 ms 492 KB Output is correct
34 Correct 1 ms 492 KB Output is correct
35 Correct 2 ms 508 KB Output is correct
36 Correct 1 ms 492 KB Output is correct
37 Correct 2 ms 492 KB Output is correct
38 Correct 1 ms 492 KB Output is correct
39 Correct 1 ms 364 KB Output is correct
40 Correct 2 ms 492 KB Output is correct
41 Correct 2 ms 492 KB Output is correct
42 Correct 2 ms 492 KB Output is correct
43 Correct 1 ms 492 KB Output is correct
44 Correct 1 ms 492 KB Output is correct
45 Correct 1 ms 492 KB Output is correct
46 Correct 2 ms 492 KB Output is correct
47 Correct 1 ms 364 KB Output is correct
48 Correct 2 ms 492 KB Output is correct
49 Correct 2 ms 492 KB Output is correct
50 Correct 2 ms 492 KB Output is correct
51 Correct 2 ms 492 KB Output is correct
52 Correct 2 ms 492 KB Output is correct
53 Correct 2 ms 492 KB Output is correct
54 Correct 2 ms 492 KB Output is correct
55 Correct 2 ms 492 KB Output is correct
56 Correct 2 ms 492 KB Output is correct
57 Correct 2 ms 492 KB Output is correct
58 Correct 2 ms 492 KB Output is correct
59 Correct 2 ms 492 KB Output is correct
60 Correct 2 ms 492 KB Output is correct
61 Correct 1 ms 364 KB Output is correct
62 Correct 2 ms 492 KB Output is correct
63 Correct 2 ms 492 KB Output is correct
64 Correct 2 ms 492 KB Output is correct
65 Correct 48 ms 492 KB Output is correct
66 Correct 2 ms 492 KB Output is correct
67 Correct 2 ms 492 KB Output is correct
68 Correct 2 ms 492 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 75 ms 11628 KB Output is correct
3 Correct 73 ms 11628 KB Output is correct
4 Correct 74 ms 11628 KB Output is correct
5 Correct 72 ms 11628 KB Output is correct
6 Correct 82 ms 11628 KB Output is correct
7 Correct 71 ms 11628 KB Output is correct
8 Correct 73 ms 11628 KB Output is correct
9 Correct 78 ms 11756 KB Output is correct
10 Correct 73 ms 11756 KB Output is correct
11 Correct 72 ms 11756 KB Output is correct
12 Correct 72 ms 11628 KB Output is correct
13 Correct 72 ms 11628 KB Output is correct
14 Correct 71 ms 11628 KB Output is correct
15 Correct 73 ms 11628 KB Output is correct
16 Correct 72 ms 11628 KB Output is correct
17 Correct 72 ms 11628 KB Output is correct
18 Correct 72 ms 11756 KB Output is correct
19 Correct 71 ms 11756 KB Output is correct
20 Correct 71 ms 11756 KB Output is correct
21 Correct 72 ms 11628 KB Output is correct
22 Correct 1 ms 364 KB Output is correct
23 Correct 1 ms 492 KB Output is correct
24 Correct 2 ms 492 KB Output is correct
25 Correct 2 ms 492 KB Output is correct
26 Correct 1 ms 492 KB Output is correct
27 Correct 2 ms 492 KB Output is correct
28 Correct 1 ms 492 KB Output is correct
29 Correct 1 ms 492 KB Output is correct
30 Correct 2 ms 492 KB Output is correct
31 Correct 1 ms 492 KB Output is correct
32 Correct 2 ms 508 KB Output is correct
33 Correct 1 ms 492 KB Output is correct
34 Correct 2 ms 492 KB Output is correct
35 Correct 1 ms 492 KB Output is correct
36 Correct 1 ms 364 KB Output is correct
37 Correct 2 ms 492 KB Output is correct
38 Correct 2 ms 492 KB Output is correct
39 Correct 2 ms 492 KB Output is correct
40 Correct 1 ms 492 KB Output is correct
41 Correct 1 ms 492 KB Output is correct
42 Correct 1 ms 492 KB Output is correct
43 Correct 2 ms 492 KB Output is correct
44 Correct 1 ms 364 KB Output is correct
45 Correct 131 ms 11884 KB Output is correct
46 Correct 136 ms 11628 KB Output is correct
47 Correct 129 ms 11628 KB Output is correct
48 Correct 132 ms 11856 KB Output is correct
49 Correct 131 ms 11776 KB Output is correct
50 Correct 131 ms 11756 KB Output is correct
51 Correct 130 ms 11628 KB Output is correct
52 Correct 130 ms 11868 KB Output is correct
53 Correct 132 ms 11628 KB Output is correct
54 Correct 132 ms 11628 KB Output is correct
55 Correct 130 ms 11756 KB Output is correct
56 Correct 133 ms 11756 KB Output is correct
57 Correct 129 ms 11628 KB Output is correct
58 Correct 1 ms 364 KB Output is correct
59 Correct 130 ms 11628 KB Output is correct
60 Correct 129 ms 11628 KB Output is correct
61 Correct 132 ms 11628 KB Output is correct
62 Correct 129 ms 11628 KB Output is correct
63 Correct 134 ms 11628 KB Output is correct
64 Correct 135 ms 11628 KB Output is correct
65 Correct 129 ms 11628 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
17 Correct 1 ms 364 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
19 Correct 1 ms 364 KB Output is correct
20 Correct 1 ms 364 KB Output is correct
21 Correct 1 ms 364 KB Output is correct
22 Correct 1 ms 364 KB Output is correct
23 Correct 1 ms 364 KB Output is correct
24 Correct 1 ms 364 KB Output is correct
25 Correct 1 ms 364 KB Output is correct
26 Correct 79 ms 12676 KB Output is correct
27 Correct 77 ms 12652 KB Output is correct
28 Correct 77 ms 12652 KB Output is correct
29 Correct 79 ms 12780 KB Output is correct
30 Correct 79 ms 12652 KB Output is correct
31 Correct 79 ms 12652 KB Output is correct
32 Correct 80 ms 12652 KB Output is correct
33 Correct 81 ms 12652 KB Output is correct
34 Correct 80 ms 12652 KB Output is correct
35 Correct 82 ms 12652 KB Output is correct
36 Correct 79 ms 12652 KB Output is correct
37 Correct 78 ms 12652 KB Output is correct
38 Correct 78 ms 12652 KB Output is correct
39 Correct 79 ms 12652 KB Output is correct
40 Correct 80 ms 12652 KB Output is correct
41 Correct 79 ms 12652 KB Output is correct
42 Correct 81 ms 12652 KB Output is correct
43 Correct 82 ms 12780 KB Output is correct
44 Correct 78 ms 12652 KB Output is correct
45 Correct 90 ms 12652 KB Output is correct
46 Correct 1 ms 364 KB Output is correct
47 Correct 75 ms 11628 KB Output is correct
48 Correct 73 ms 11628 KB Output is correct
49 Correct 74 ms 11628 KB Output is correct
50 Correct 72 ms 11628 KB Output is correct
51 Correct 82 ms 11628 KB Output is correct
52 Correct 71 ms 11628 KB Output is correct
53 Correct 73 ms 11628 KB Output is correct
54 Correct 78 ms 11756 KB Output is correct
55 Correct 73 ms 11756 KB Output is correct
56 Correct 72 ms 11756 KB Output is correct
57 Correct 72 ms 11628 KB Output is correct
58 Correct 72 ms 11628 KB Output is correct
59 Correct 71 ms 11628 KB Output is correct
60 Correct 73 ms 11628 KB Output is correct
61 Correct 72 ms 11628 KB Output is correct
62 Correct 72 ms 11628 KB Output is correct
63 Correct 72 ms 11756 KB Output is correct
64 Correct 71 ms 11756 KB Output is correct
65 Correct 71 ms 11756 KB Output is correct
66 Correct 72 ms 11628 KB Output is correct
67 Correct 1 ms 364 KB Output is correct
68 Correct 1 ms 492 KB Output is correct
69 Correct 2 ms 492 KB Output is correct
70 Correct 2 ms 492 KB Output is correct
71 Correct 1 ms 492 KB Output is correct
72 Correct 2 ms 492 KB Output is correct
73 Correct 1 ms 492 KB Output is correct
74 Correct 1 ms 492 KB Output is correct
75 Correct 2 ms 492 KB Output is correct
76 Correct 1 ms 492 KB Output is correct
77 Correct 2 ms 508 KB Output is correct
78 Correct 1 ms 492 KB Output is correct
79 Correct 2 ms 492 KB Output is correct
80 Correct 1 ms 492 KB Output is correct
81 Correct 1 ms 364 KB Output is correct
82 Correct 2 ms 492 KB Output is correct
83 Correct 2 ms 492 KB Output is correct
84 Correct 2 ms 492 KB Output is correct
85 Correct 1 ms 492 KB Output is correct
86 Correct 1 ms 492 KB Output is correct
87 Correct 1 ms 492 KB Output is correct
88 Correct 2 ms 492 KB Output is correct
89 Correct 1 ms 364 KB Output is correct
90 Correct 2 ms 492 KB Output is correct
91 Correct 2 ms 492 KB Output is correct
92 Correct 2 ms 492 KB Output is correct
93 Correct 2 ms 492 KB Output is correct
94 Correct 2 ms 492 KB Output is correct
95 Correct 2 ms 492 KB Output is correct
96 Correct 2 ms 492 KB Output is correct
97 Correct 2 ms 492 KB Output is correct
98 Correct 2 ms 492 KB Output is correct
99 Correct 2 ms 492 KB Output is correct
100 Correct 2 ms 492 KB Output is correct
101 Correct 2 ms 492 KB Output is correct
102 Correct 2 ms 492 KB Output is correct
103 Correct 1 ms 364 KB Output is correct
104 Correct 2 ms 492 KB Output is correct
105 Correct 2 ms 492 KB Output is correct
106 Correct 2 ms 492 KB Output is correct
107 Correct 48 ms 492 KB Output is correct
108 Correct 2 ms 492 KB Output is correct
109 Correct 2 ms 492 KB Output is correct
110 Correct 2 ms 492 KB Output is correct
111 Correct 1 ms 364 KB Output is correct
112 Correct 131 ms 11884 KB Output is correct
113 Correct 136 ms 11628 KB Output is correct
114 Correct 129 ms 11628 KB Output is correct
115 Correct 132 ms 11856 KB Output is correct
116 Correct 131 ms 11776 KB Output is correct
117 Correct 131 ms 11756 KB Output is correct
118 Correct 130 ms 11628 KB Output is correct
119 Correct 130 ms 11868 KB Output is correct
120 Correct 132 ms 11628 KB Output is correct
121 Correct 132 ms 11628 KB Output is correct
122 Correct 130 ms 11756 KB Output is correct
123 Correct 133 ms 11756 KB Output is correct
124 Correct 129 ms 11628 KB Output is correct
125 Correct 1 ms 364 KB Output is correct
126 Correct 130 ms 11628 KB Output is correct
127 Correct 129 ms 11628 KB Output is correct
128 Correct 132 ms 11628 KB Output is correct
129 Correct 129 ms 11628 KB Output is correct
130 Correct 134 ms 11628 KB Output is correct
131 Correct 135 ms 11628 KB Output is correct
132 Correct 129 ms 11628 KB Output is correct
133 Correct 1 ms 364 KB Output is correct
134 Correct 139 ms 12652 KB Output is correct
135 Correct 138 ms 12780 KB Output is correct
136 Correct 136 ms 12652 KB Output is correct
137 Correct 137 ms 12652 KB Output is correct
138 Correct 143 ms 12652 KB Output is correct
139 Correct 137 ms 12652 KB Output is correct
140 Correct 135 ms 12652 KB Output is correct
141 Correct 136 ms 12652 KB Output is correct
142 Correct 134 ms 12652 KB Output is correct
143 Correct 135 ms 12652 KB Output is correct
144 Correct 137 ms 12780 KB Output is correct
145 Correct 136 ms 12652 KB Output is correct
146 Correct 136 ms 12652 KB Output is correct
147 Correct 1 ms 364 KB Output is correct
148 Correct 137 ms 12652 KB Output is correct
149 Correct 135 ms 12652 KB Output is correct
150 Correct 136 ms 12780 KB Output is correct
151 Correct 140 ms 12652 KB Output is correct
152 Correct 137 ms 12652 KB Output is correct
153 Correct 136 ms 12652 KB Output is correct
154 Correct 137 ms 12728 KB Output is correct