Submission #651046

# Submission time Handle Problem Language Result Execution time Memory
651046 2022-10-16T15:50:32 Z dsyz Cryptography (NOI20_crypto) C++17
100 / 100
136 ms 15160 KB
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define MAXN (300006)

int n;
ll P[MAXN], f[MAXN], A[MAXN];
vector<ll> d;
struct fen {
	ll fw[MAXN];
	fen() {
		memset(fw, 0, sizeof fw);
	}
	void update(int x,ll nval) {
		for(;x<MAXN;x+=x&(-x)) fw[x]+=nval;
	}
	ll sum(int x) {
		ll res = 0;
		for(;x;x-=x&(-x)) res+=fw[x];
		return res;
	}
} ft;
ll mod=1e9+7;
int main(){
	f[0]=1; for(int i=1;i<MAXN;++i) f[i]=f[i-1]*i%mod; 
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin>>n;
	for(int i=0;i<n;++i) cin>>P[i], d.push_back(P[i]);
	sort(d.begin(), d.end()), d.resize(unique(d.begin(), d.end())-d.begin());
	for(int i=0;i<n;++i) P[i] = lower_bound(d.begin(), d.end(), P[i]) - d.begin() + 1;
	for(int i=n-1;i>=0;--i) {
		A[i] = ft.sum(P[i] - 1);
		ft.update(P[i], 1);
	}
	ll ans = 0;
	for(int i=0;i<n;++i) {
		ans += A[i] * f[n-i-1] % mod;
		ans %= mod;
	}
	cout<<(ans+1)%mod<<'\n';
}
# Verdict Execution time Memory Grader output
1 Correct 5 ms 4948 KB Output is correct
2 Correct 5 ms 4948 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 4948 KB Output is correct
2 Correct 5 ms 4948 KB Output is correct
3 Correct 5 ms 5032 KB Output is correct
4 Correct 5 ms 5036 KB Output is correct
5 Correct 5 ms 4948 KB Output is correct
6 Correct 5 ms 4948 KB Output is correct
7 Correct 5 ms 4948 KB Output is correct
8 Correct 5 ms 5076 KB Output is correct
9 Correct 5 ms 4948 KB Output is correct
10 Correct 5 ms 5036 KB Output is correct
11 Correct 5 ms 5032 KB Output is correct
12 Correct 5 ms 4948 KB Output is correct
13 Correct 5 ms 5004 KB Output is correct
14 Correct 5 ms 4976 KB Output is correct
15 Correct 5 ms 5040 KB Output is correct
16 Correct 5 ms 4948 KB Output is correct
17 Correct 5 ms 4948 KB Output is correct
18 Correct 5 ms 4948 KB Output is correct
19 Correct 5 ms 5036 KB Output is correct
20 Correct 5 ms 5036 KB Output is correct
21 Correct 5 ms 4948 KB Output is correct
22 Correct 5 ms 4948 KB Output is correct
23 Correct 5 ms 4948 KB Output is correct
24 Correct 5 ms 4948 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 4948 KB Output is correct
2 Correct 70 ms 15076 KB Output is correct
3 Correct 71 ms 15068 KB Output is correct
4 Correct 71 ms 15108 KB Output is correct
5 Correct 79 ms 15004 KB Output is correct
6 Correct 69 ms 15016 KB Output is correct
7 Correct 72 ms 15040 KB Output is correct
8 Correct 71 ms 15040 KB Output is correct
9 Correct 76 ms 14984 KB Output is correct
10 Correct 72 ms 15020 KB Output is correct
11 Correct 78 ms 15024 KB Output is correct
12 Correct 69 ms 15072 KB Output is correct
13 Correct 69 ms 15020 KB Output is correct
14 Correct 74 ms 15136 KB Output is correct
15 Correct 71 ms 14988 KB Output is correct
16 Correct 71 ms 15028 KB Output is correct
17 Correct 70 ms 15084 KB Output is correct
18 Correct 70 ms 15100 KB Output is correct
19 Correct 75 ms 15136 KB Output is correct
20 Correct 68 ms 15060 KB Output is correct
21 Correct 68 ms 15064 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 4964 KB Output is correct
2 Correct 65 ms 14020 KB Output is correct
3 Correct 66 ms 14040 KB Output is correct
4 Correct 68 ms 14112 KB Output is correct
5 Correct 63 ms 14224 KB Output is correct
6 Correct 64 ms 14064 KB Output is correct
7 Correct 63 ms 14080 KB Output is correct
8 Correct 65 ms 14112 KB Output is correct
9 Correct 66 ms 14024 KB Output is correct
10 Correct 64 ms 14068 KB Output is correct
11 Correct 64 ms 14068 KB Output is correct
12 Correct 63 ms 14108 KB Output is correct
13 Correct 69 ms 14144 KB Output is correct
14 Correct 65 ms 14172 KB Output is correct
15 Correct 66 ms 14108 KB Output is correct
16 Correct 63 ms 14036 KB Output is correct
17 Correct 68 ms 14108 KB Output is correct
18 Correct 63 ms 14108 KB Output is correct
19 Correct 62 ms 14108 KB Output is correct
20 Correct 65 ms 14092 KB Output is correct
21 Correct 65 ms 14116 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 4948 KB Output is correct
2 Correct 5 ms 5160 KB Output is correct
3 Correct 5 ms 5044 KB Output is correct
4 Correct 6 ms 5048 KB Output is correct
5 Correct 6 ms 5076 KB Output is correct
6 Correct 7 ms 5076 KB Output is correct
7 Correct 5 ms 5048 KB Output is correct
8 Correct 5 ms 5048 KB Output is correct
9 Correct 5 ms 5044 KB Output is correct
10 Correct 6 ms 5076 KB Output is correct
11 Correct 5 ms 5140 KB Output is correct
12 Correct 5 ms 5048 KB Output is correct
13 Correct 5 ms 5076 KB Output is correct
14 Correct 5 ms 5076 KB Output is correct
15 Correct 5 ms 5036 KB Output is correct
16 Correct 5 ms 5076 KB Output is correct
17 Correct 5 ms 5048 KB Output is correct
18 Correct 6 ms 5048 KB Output is correct
19 Correct 6 ms 5076 KB Output is correct
20 Correct 5 ms 5076 KB Output is correct
21 Correct 6 ms 5144 KB Output is correct
22 Correct 6 ms 5076 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 4948 KB Output is correct
2 Correct 5 ms 4948 KB Output is correct
3 Correct 5 ms 5032 KB Output is correct
4 Correct 5 ms 5036 KB Output is correct
5 Correct 5 ms 4948 KB Output is correct
6 Correct 5 ms 4948 KB Output is correct
7 Correct 5 ms 4948 KB Output is correct
8 Correct 5 ms 5076 KB Output is correct
9 Correct 5 ms 4948 KB Output is correct
10 Correct 5 ms 5036 KB Output is correct
11 Correct 5 ms 5032 KB Output is correct
12 Correct 5 ms 4948 KB Output is correct
13 Correct 5 ms 5004 KB Output is correct
14 Correct 5 ms 4976 KB Output is correct
15 Correct 5 ms 5040 KB Output is correct
16 Correct 5 ms 4948 KB Output is correct
17 Correct 5 ms 4948 KB Output is correct
18 Correct 5 ms 4948 KB Output is correct
19 Correct 5 ms 5036 KB Output is correct
20 Correct 5 ms 5036 KB Output is correct
21 Correct 5 ms 4948 KB Output is correct
22 Correct 5 ms 4948 KB Output is correct
23 Correct 5 ms 4948 KB Output is correct
24 Correct 5 ms 4948 KB Output is correct
25 Correct 5 ms 4948 KB Output is correct
26 Correct 5 ms 5160 KB Output is correct
27 Correct 5 ms 5044 KB Output is correct
28 Correct 6 ms 5048 KB Output is correct
29 Correct 6 ms 5076 KB Output is correct
30 Correct 7 ms 5076 KB Output is correct
31 Correct 5 ms 5048 KB Output is correct
32 Correct 5 ms 5048 KB Output is correct
33 Correct 5 ms 5044 KB Output is correct
34 Correct 6 ms 5076 KB Output is correct
35 Correct 5 ms 5140 KB Output is correct
36 Correct 5 ms 5048 KB Output is correct
37 Correct 5 ms 5076 KB Output is correct
38 Correct 5 ms 5076 KB Output is correct
39 Correct 5 ms 5036 KB Output is correct
40 Correct 5 ms 5076 KB Output is correct
41 Correct 5 ms 5048 KB Output is correct
42 Correct 6 ms 5048 KB Output is correct
43 Correct 6 ms 5076 KB Output is correct
44 Correct 5 ms 5076 KB Output is correct
45 Correct 6 ms 5144 KB Output is correct
46 Correct 6 ms 5076 KB Output is correct
47 Correct 5 ms 5032 KB Output is correct
48 Correct 5 ms 5144 KB Output is correct
49 Correct 5 ms 5076 KB Output is correct
50 Correct 5 ms 5092 KB Output is correct
51 Correct 6 ms 5176 KB Output is correct
52 Correct 6 ms 5160 KB Output is correct
53 Correct 5 ms 5076 KB Output is correct
54 Correct 5 ms 5076 KB Output is correct
55 Correct 6 ms 5060 KB Output is correct
56 Correct 5 ms 5076 KB Output is correct
57 Correct 6 ms 5172 KB Output is correct
58 Correct 6 ms 5076 KB Output is correct
59 Correct 5 ms 5076 KB Output is correct
60 Correct 5 ms 5076 KB Output is correct
61 Correct 5 ms 4948 KB Output is correct
62 Correct 6 ms 5076 KB Output is correct
63 Correct 5 ms 5076 KB Output is correct
64 Correct 6 ms 5076 KB Output is correct
65 Correct 5 ms 5144 KB Output is correct
66 Correct 6 ms 5176 KB Output is correct
67 Correct 6 ms 5172 KB Output is correct
68 Correct 5 ms 5076 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 4964 KB Output is correct
2 Correct 65 ms 14020 KB Output is correct
3 Correct 66 ms 14040 KB Output is correct
4 Correct 68 ms 14112 KB Output is correct
5 Correct 63 ms 14224 KB Output is correct
6 Correct 64 ms 14064 KB Output is correct
7 Correct 63 ms 14080 KB Output is correct
8 Correct 65 ms 14112 KB Output is correct
9 Correct 66 ms 14024 KB Output is correct
10 Correct 64 ms 14068 KB Output is correct
11 Correct 64 ms 14068 KB Output is correct
12 Correct 63 ms 14108 KB Output is correct
13 Correct 69 ms 14144 KB Output is correct
14 Correct 65 ms 14172 KB Output is correct
15 Correct 66 ms 14108 KB Output is correct
16 Correct 63 ms 14036 KB Output is correct
17 Correct 68 ms 14108 KB Output is correct
18 Correct 63 ms 14108 KB Output is correct
19 Correct 62 ms 14108 KB Output is correct
20 Correct 65 ms 14092 KB Output is correct
21 Correct 65 ms 14116 KB Output is correct
22 Correct 5 ms 4948 KB Output is correct
23 Correct 5 ms 5160 KB Output is correct
24 Correct 5 ms 5044 KB Output is correct
25 Correct 6 ms 5048 KB Output is correct
26 Correct 6 ms 5076 KB Output is correct
27 Correct 7 ms 5076 KB Output is correct
28 Correct 5 ms 5048 KB Output is correct
29 Correct 5 ms 5048 KB Output is correct
30 Correct 5 ms 5044 KB Output is correct
31 Correct 6 ms 5076 KB Output is correct
32 Correct 5 ms 5140 KB Output is correct
33 Correct 5 ms 5048 KB Output is correct
34 Correct 5 ms 5076 KB Output is correct
35 Correct 5 ms 5076 KB Output is correct
36 Correct 5 ms 5036 KB Output is correct
37 Correct 5 ms 5076 KB Output is correct
38 Correct 5 ms 5048 KB Output is correct
39 Correct 6 ms 5048 KB Output is correct
40 Correct 6 ms 5076 KB Output is correct
41 Correct 5 ms 5076 KB Output is correct
42 Correct 6 ms 5144 KB Output is correct
43 Correct 6 ms 5076 KB Output is correct
44 Correct 4 ms 5028 KB Output is correct
45 Correct 116 ms 14120 KB Output is correct
46 Correct 123 ms 14080 KB Output is correct
47 Correct 116 ms 14060 KB Output is correct
48 Correct 115 ms 14044 KB Output is correct
49 Correct 114 ms 14108 KB Output is correct
50 Correct 114 ms 14032 KB Output is correct
51 Correct 117 ms 14128 KB Output is correct
52 Correct 120 ms 14060 KB Output is correct
53 Correct 118 ms 14080 KB Output is correct
54 Correct 116 ms 14052 KB Output is correct
55 Correct 117 ms 14092 KB Output is correct
56 Correct 121 ms 14116 KB Output is correct
57 Correct 116 ms 14068 KB Output is correct
58 Correct 5 ms 4948 KB Output is correct
59 Correct 115 ms 14108 KB Output is correct
60 Correct 116 ms 14092 KB Output is correct
61 Correct 120 ms 14108 KB Output is correct
62 Correct 118 ms 14264 KB Output is correct
63 Correct 117 ms 14208 KB Output is correct
64 Correct 114 ms 14100 KB Output is correct
65 Correct 116 ms 14112 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 4948 KB Output is correct
2 Correct 5 ms 4948 KB Output is correct
3 Correct 5 ms 5032 KB Output is correct
4 Correct 5 ms 5036 KB Output is correct
5 Correct 5 ms 4948 KB Output is correct
6 Correct 5 ms 4948 KB Output is correct
7 Correct 5 ms 4948 KB Output is correct
8 Correct 5 ms 5076 KB Output is correct
9 Correct 5 ms 4948 KB Output is correct
10 Correct 5 ms 5036 KB Output is correct
11 Correct 5 ms 5032 KB Output is correct
12 Correct 5 ms 4948 KB Output is correct
13 Correct 5 ms 5004 KB Output is correct
14 Correct 5 ms 4976 KB Output is correct
15 Correct 5 ms 5040 KB Output is correct
16 Correct 5 ms 4948 KB Output is correct
17 Correct 5 ms 4948 KB Output is correct
18 Correct 5 ms 4948 KB Output is correct
19 Correct 5 ms 5036 KB Output is correct
20 Correct 5 ms 5036 KB Output is correct
21 Correct 5 ms 4948 KB Output is correct
22 Correct 5 ms 4948 KB Output is correct
23 Correct 5 ms 4948 KB Output is correct
24 Correct 5 ms 4948 KB Output is correct
25 Correct 4 ms 4948 KB Output is correct
26 Correct 70 ms 15076 KB Output is correct
27 Correct 71 ms 15068 KB Output is correct
28 Correct 71 ms 15108 KB Output is correct
29 Correct 79 ms 15004 KB Output is correct
30 Correct 69 ms 15016 KB Output is correct
31 Correct 72 ms 15040 KB Output is correct
32 Correct 71 ms 15040 KB Output is correct
33 Correct 76 ms 14984 KB Output is correct
34 Correct 72 ms 15020 KB Output is correct
35 Correct 78 ms 15024 KB Output is correct
36 Correct 69 ms 15072 KB Output is correct
37 Correct 69 ms 15020 KB Output is correct
38 Correct 74 ms 15136 KB Output is correct
39 Correct 71 ms 14988 KB Output is correct
40 Correct 71 ms 15028 KB Output is correct
41 Correct 70 ms 15084 KB Output is correct
42 Correct 70 ms 15100 KB Output is correct
43 Correct 75 ms 15136 KB Output is correct
44 Correct 68 ms 15060 KB Output is correct
45 Correct 68 ms 15064 KB Output is correct
46 Correct 5 ms 4964 KB Output is correct
47 Correct 65 ms 14020 KB Output is correct
48 Correct 66 ms 14040 KB Output is correct
49 Correct 68 ms 14112 KB Output is correct
50 Correct 63 ms 14224 KB Output is correct
51 Correct 64 ms 14064 KB Output is correct
52 Correct 63 ms 14080 KB Output is correct
53 Correct 65 ms 14112 KB Output is correct
54 Correct 66 ms 14024 KB Output is correct
55 Correct 64 ms 14068 KB Output is correct
56 Correct 64 ms 14068 KB Output is correct
57 Correct 63 ms 14108 KB Output is correct
58 Correct 69 ms 14144 KB Output is correct
59 Correct 65 ms 14172 KB Output is correct
60 Correct 66 ms 14108 KB Output is correct
61 Correct 63 ms 14036 KB Output is correct
62 Correct 68 ms 14108 KB Output is correct
63 Correct 63 ms 14108 KB Output is correct
64 Correct 62 ms 14108 KB Output is correct
65 Correct 65 ms 14092 KB Output is correct
66 Correct 65 ms 14116 KB Output is correct
67 Correct 5 ms 4948 KB Output is correct
68 Correct 5 ms 5160 KB Output is correct
69 Correct 5 ms 5044 KB Output is correct
70 Correct 6 ms 5048 KB Output is correct
71 Correct 6 ms 5076 KB Output is correct
72 Correct 7 ms 5076 KB Output is correct
73 Correct 5 ms 5048 KB Output is correct
74 Correct 5 ms 5048 KB Output is correct
75 Correct 5 ms 5044 KB Output is correct
76 Correct 6 ms 5076 KB Output is correct
77 Correct 5 ms 5140 KB Output is correct
78 Correct 5 ms 5048 KB Output is correct
79 Correct 5 ms 5076 KB Output is correct
80 Correct 5 ms 5076 KB Output is correct
81 Correct 5 ms 5036 KB Output is correct
82 Correct 5 ms 5076 KB Output is correct
83 Correct 5 ms 5048 KB Output is correct
84 Correct 6 ms 5048 KB Output is correct
85 Correct 6 ms 5076 KB Output is correct
86 Correct 5 ms 5076 KB Output is correct
87 Correct 6 ms 5144 KB Output is correct
88 Correct 6 ms 5076 KB Output is correct
89 Correct 5 ms 5032 KB Output is correct
90 Correct 5 ms 5144 KB Output is correct
91 Correct 5 ms 5076 KB Output is correct
92 Correct 5 ms 5092 KB Output is correct
93 Correct 6 ms 5176 KB Output is correct
94 Correct 6 ms 5160 KB Output is correct
95 Correct 5 ms 5076 KB Output is correct
96 Correct 5 ms 5076 KB Output is correct
97 Correct 6 ms 5060 KB Output is correct
98 Correct 5 ms 5076 KB Output is correct
99 Correct 6 ms 5172 KB Output is correct
100 Correct 6 ms 5076 KB Output is correct
101 Correct 5 ms 5076 KB Output is correct
102 Correct 5 ms 5076 KB Output is correct
103 Correct 5 ms 4948 KB Output is correct
104 Correct 6 ms 5076 KB Output is correct
105 Correct 5 ms 5076 KB Output is correct
106 Correct 6 ms 5076 KB Output is correct
107 Correct 5 ms 5144 KB Output is correct
108 Correct 6 ms 5176 KB Output is correct
109 Correct 6 ms 5172 KB Output is correct
110 Correct 5 ms 5076 KB Output is correct
111 Correct 4 ms 5028 KB Output is correct
112 Correct 116 ms 14120 KB Output is correct
113 Correct 123 ms 14080 KB Output is correct
114 Correct 116 ms 14060 KB Output is correct
115 Correct 115 ms 14044 KB Output is correct
116 Correct 114 ms 14108 KB Output is correct
117 Correct 114 ms 14032 KB Output is correct
118 Correct 117 ms 14128 KB Output is correct
119 Correct 120 ms 14060 KB Output is correct
120 Correct 118 ms 14080 KB Output is correct
121 Correct 116 ms 14052 KB Output is correct
122 Correct 117 ms 14092 KB Output is correct
123 Correct 121 ms 14116 KB Output is correct
124 Correct 116 ms 14068 KB Output is correct
125 Correct 5 ms 4948 KB Output is correct
126 Correct 115 ms 14108 KB Output is correct
127 Correct 116 ms 14092 KB Output is correct
128 Correct 120 ms 14108 KB Output is correct
129 Correct 118 ms 14264 KB Output is correct
130 Correct 117 ms 14208 KB Output is correct
131 Correct 114 ms 14100 KB Output is correct
132 Correct 116 ms 14112 KB Output is correct
133 Correct 4 ms 4948 KB Output is correct
134 Correct 131 ms 15108 KB Output is correct
135 Correct 127 ms 15080 KB Output is correct
136 Correct 118 ms 15064 KB Output is correct
137 Correct 124 ms 14980 KB Output is correct
138 Correct 123 ms 15112 KB Output is correct
139 Correct 127 ms 15160 KB Output is correct
140 Correct 120 ms 15008 KB Output is correct
141 Correct 123 ms 15028 KB Output is correct
142 Correct 128 ms 15132 KB Output is correct
143 Correct 126 ms 15060 KB Output is correct
144 Correct 124 ms 15084 KB Output is correct
145 Correct 124 ms 15000 KB Output is correct
146 Correct 132 ms 15064 KB Output is correct
147 Correct 5 ms 4948 KB Output is correct
148 Correct 124 ms 15128 KB Output is correct
149 Correct 122 ms 15060 KB Output is correct
150 Correct 126 ms 15076 KB Output is correct
151 Correct 136 ms 15068 KB Output is correct
152 Correct 119 ms 15104 KB Output is correct
153 Correct 124 ms 15000 KB Output is correct
154 Correct 121 ms 15032 KB Output is correct