답안 #294551

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
294551 2020-09-09T04:27:41 Z nandonathaniel Cryptography (NOI20_crypto) C++14
100 / 100
161 ms 15976 KB
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<LL,LL> pii;
const LL MAXN=300005,MOD=1000000007;

LL a[MAXN],bit[MAXN],n,fac[MAXN];

void update(LL now){
	for(LL i=now;i<=n;i+=(i&(-i)))bit[i]++;
}

LL query(LL now){
	LL ret=0;
	if(now==0)return ret;
	for(LL i=now;i>0;i-=(i&(-i)))ret+=bit[i];
	return ret;
}

int main(){
	ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
	fac[0]=1;
	for(LL i=1;i<=MAXN-5;i++)fac[i]=(fac[i-1]*i)%MOD;
	cin >> n;
	vector<pii> v;
	for(LL i=1;i<=n;i++){
		cin >> a[i];
		v.push_back({a[i],i});
	}
	sort(v.begin(),v.end());
	for(int i=0;i<v.size();i++)a[v[i].second]=i+1;
	LL ans=0;
	for(int i=1;i<=n;i++){
		ans=(ans+(((a[i]-1-query(a[i]-1))*fac[n-i])%MOD))%MOD;
		update(a[i]);
	}
	cout << (ans+1)%MOD << '\n';
	return 0;
}

Compilation message

Crypto.cpp: In function 'int main()':
Crypto.cpp:31:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   31 |  for(int i=0;i<v.size();i++)a[v[i].second]=i+1;
      |              ~^~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 2688 KB Output is correct
2 Correct 4 ms 2688 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 2688 KB Output is correct
2 Correct 4 ms 2688 KB Output is correct
3 Correct 5 ms 2688 KB Output is correct
4 Correct 4 ms 2720 KB Output is correct
5 Correct 6 ms 2688 KB Output is correct
6 Correct 4 ms 2688 KB Output is correct
7 Correct 5 ms 2688 KB Output is correct
8 Correct 4 ms 2688 KB Output is correct
9 Correct 4 ms 2688 KB Output is correct
10 Correct 5 ms 2688 KB Output is correct
11 Correct 5 ms 2688 KB Output is correct
12 Correct 5 ms 2688 KB Output is correct
13 Correct 4 ms 2688 KB Output is correct
14 Correct 4 ms 2688 KB Output is correct
15 Correct 5 ms 2664 KB Output is correct
16 Correct 5 ms 2688 KB Output is correct
17 Correct 4 ms 2688 KB Output is correct
18 Correct 4 ms 2688 KB Output is correct
19 Correct 5 ms 2688 KB Output is correct
20 Correct 6 ms 2688 KB Output is correct
21 Correct 6 ms 2688 KB Output is correct
22 Correct 4 ms 2688 KB Output is correct
23 Correct 5 ms 2688 KB Output is correct
24 Correct 5 ms 2688 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 2688 KB Output is correct
2 Correct 68 ms 15976 KB Output is correct
3 Correct 81 ms 15848 KB Output is correct
4 Correct 65 ms 15972 KB Output is correct
5 Correct 81 ms 15848 KB Output is correct
6 Correct 82 ms 15844 KB Output is correct
7 Correct 69 ms 15844 KB Output is correct
8 Correct 75 ms 15716 KB Output is correct
9 Correct 67 ms 15848 KB Output is correct
10 Correct 71 ms 15844 KB Output is correct
11 Correct 68 ms 15840 KB Output is correct
12 Correct 64 ms 15972 KB Output is correct
13 Correct 63 ms 15908 KB Output is correct
14 Correct 63 ms 15968 KB Output is correct
15 Correct 64 ms 15840 KB Output is correct
16 Correct 71 ms 15840 KB Output is correct
17 Correct 66 ms 15848 KB Output is correct
18 Correct 67 ms 15848 KB Output is correct
19 Correct 63 ms 15976 KB Output is correct
20 Correct 63 ms 15968 KB Output is correct
21 Correct 103 ms 15968 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 2688 KB Output is correct
2 Correct 63 ms 14960 KB Output is correct
3 Correct 60 ms 15080 KB Output is correct
4 Correct 59 ms 14944 KB Output is correct
5 Correct 60 ms 15076 KB Output is correct
6 Correct 61 ms 15020 KB Output is correct
7 Correct 60 ms 14952 KB Output is correct
8 Correct 63 ms 15072 KB Output is correct
9 Correct 59 ms 15080 KB Output is correct
10 Correct 58 ms 15080 KB Output is correct
11 Correct 64 ms 15000 KB Output is correct
12 Correct 59 ms 15080 KB Output is correct
13 Correct 59 ms 15064 KB Output is correct
14 Correct 61 ms 15076 KB Output is correct
15 Correct 58 ms 14952 KB Output is correct
16 Correct 60 ms 15076 KB Output is correct
17 Correct 86 ms 15072 KB Output is correct
18 Correct 84 ms 15072 KB Output is correct
19 Correct 61 ms 15036 KB Output is correct
20 Correct 62 ms 15048 KB Output is correct
21 Correct 62 ms 15000 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 2688 KB Output is correct
2 Correct 5 ms 2816 KB Output is correct
3 Correct 5 ms 2816 KB Output is correct
4 Correct 5 ms 2816 KB Output is correct
5 Correct 5 ms 2816 KB Output is correct
6 Correct 5 ms 2816 KB Output is correct
7 Correct 5 ms 2816 KB Output is correct
8 Correct 5 ms 2816 KB Output is correct
9 Correct 5 ms 2816 KB Output is correct
10 Correct 5 ms 2880 KB Output is correct
11 Correct 5 ms 2816 KB Output is correct
12 Correct 6 ms 2944 KB Output is correct
13 Correct 5 ms 2816 KB Output is correct
14 Correct 5 ms 2816 KB Output is correct
15 Correct 4 ms 2688 KB Output is correct
16 Correct 5 ms 2816 KB Output is correct
17 Correct 5 ms 2944 KB Output is correct
18 Correct 5 ms 2816 KB Output is correct
19 Correct 5 ms 2816 KB Output is correct
20 Correct 5 ms 2816 KB Output is correct
21 Correct 6 ms 2816 KB Output is correct
22 Correct 5 ms 2816 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 2688 KB Output is correct
2 Correct 4 ms 2688 KB Output is correct
3 Correct 5 ms 2688 KB Output is correct
4 Correct 4 ms 2720 KB Output is correct
5 Correct 6 ms 2688 KB Output is correct
6 Correct 4 ms 2688 KB Output is correct
7 Correct 5 ms 2688 KB Output is correct
8 Correct 4 ms 2688 KB Output is correct
9 Correct 4 ms 2688 KB Output is correct
10 Correct 5 ms 2688 KB Output is correct
11 Correct 5 ms 2688 KB Output is correct
12 Correct 5 ms 2688 KB Output is correct
13 Correct 4 ms 2688 KB Output is correct
14 Correct 4 ms 2688 KB Output is correct
15 Correct 5 ms 2664 KB Output is correct
16 Correct 5 ms 2688 KB Output is correct
17 Correct 4 ms 2688 KB Output is correct
18 Correct 4 ms 2688 KB Output is correct
19 Correct 5 ms 2688 KB Output is correct
20 Correct 6 ms 2688 KB Output is correct
21 Correct 6 ms 2688 KB Output is correct
22 Correct 4 ms 2688 KB Output is correct
23 Correct 5 ms 2688 KB Output is correct
24 Correct 5 ms 2688 KB Output is correct
25 Correct 5 ms 2688 KB Output is correct
26 Correct 5 ms 2816 KB Output is correct
27 Correct 5 ms 2816 KB Output is correct
28 Correct 5 ms 2816 KB Output is correct
29 Correct 5 ms 2816 KB Output is correct
30 Correct 5 ms 2816 KB Output is correct
31 Correct 5 ms 2816 KB Output is correct
32 Correct 5 ms 2816 KB Output is correct
33 Correct 5 ms 2816 KB Output is correct
34 Correct 5 ms 2880 KB Output is correct
35 Correct 5 ms 2816 KB Output is correct
36 Correct 6 ms 2944 KB Output is correct
37 Correct 5 ms 2816 KB Output is correct
38 Correct 5 ms 2816 KB Output is correct
39 Correct 4 ms 2688 KB Output is correct
40 Correct 5 ms 2816 KB Output is correct
41 Correct 5 ms 2944 KB Output is correct
42 Correct 5 ms 2816 KB Output is correct
43 Correct 5 ms 2816 KB Output is correct
44 Correct 5 ms 2816 KB Output is correct
45 Correct 6 ms 2816 KB Output is correct
46 Correct 5 ms 2816 KB Output is correct
47 Correct 4 ms 2688 KB Output is correct
48 Correct 5 ms 2944 KB Output is correct
49 Correct 5 ms 2944 KB Output is correct
50 Correct 5 ms 2944 KB Output is correct
51 Correct 5 ms 2944 KB Output is correct
52 Correct 5 ms 2944 KB Output is correct
53 Correct 5 ms 2944 KB Output is correct
54 Correct 5 ms 2944 KB Output is correct
55 Correct 5 ms 2944 KB Output is correct
56 Correct 5 ms 2944 KB Output is correct
57 Correct 5 ms 2944 KB Output is correct
58 Correct 6 ms 2944 KB Output is correct
59 Correct 5 ms 2944 KB Output is correct
60 Correct 6 ms 2944 KB Output is correct
61 Correct 6 ms 2688 KB Output is correct
62 Correct 6 ms 2944 KB Output is correct
63 Correct 6 ms 2944 KB Output is correct
64 Correct 6 ms 2944 KB Output is correct
65 Correct 5 ms 2944 KB Output is correct
66 Correct 5 ms 2944 KB Output is correct
67 Correct 5 ms 2944 KB Output is correct
68 Correct 5 ms 2944 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 2688 KB Output is correct
2 Correct 63 ms 14960 KB Output is correct
3 Correct 60 ms 15080 KB Output is correct
4 Correct 59 ms 14944 KB Output is correct
5 Correct 60 ms 15076 KB Output is correct
6 Correct 61 ms 15020 KB Output is correct
7 Correct 60 ms 14952 KB Output is correct
8 Correct 63 ms 15072 KB Output is correct
9 Correct 59 ms 15080 KB Output is correct
10 Correct 58 ms 15080 KB Output is correct
11 Correct 64 ms 15000 KB Output is correct
12 Correct 59 ms 15080 KB Output is correct
13 Correct 59 ms 15064 KB Output is correct
14 Correct 61 ms 15076 KB Output is correct
15 Correct 58 ms 14952 KB Output is correct
16 Correct 60 ms 15076 KB Output is correct
17 Correct 86 ms 15072 KB Output is correct
18 Correct 84 ms 15072 KB Output is correct
19 Correct 61 ms 15036 KB Output is correct
20 Correct 62 ms 15048 KB Output is correct
21 Correct 62 ms 15000 KB Output is correct
22 Correct 5 ms 2688 KB Output is correct
23 Correct 5 ms 2816 KB Output is correct
24 Correct 5 ms 2816 KB Output is correct
25 Correct 5 ms 2816 KB Output is correct
26 Correct 5 ms 2816 KB Output is correct
27 Correct 5 ms 2816 KB Output is correct
28 Correct 5 ms 2816 KB Output is correct
29 Correct 5 ms 2816 KB Output is correct
30 Correct 5 ms 2816 KB Output is correct
31 Correct 5 ms 2880 KB Output is correct
32 Correct 5 ms 2816 KB Output is correct
33 Correct 6 ms 2944 KB Output is correct
34 Correct 5 ms 2816 KB Output is correct
35 Correct 5 ms 2816 KB Output is correct
36 Correct 4 ms 2688 KB Output is correct
37 Correct 5 ms 2816 KB Output is correct
38 Correct 5 ms 2944 KB Output is correct
39 Correct 5 ms 2816 KB Output is correct
40 Correct 5 ms 2816 KB Output is correct
41 Correct 5 ms 2816 KB Output is correct
42 Correct 6 ms 2816 KB Output is correct
43 Correct 5 ms 2816 KB Output is correct
44 Correct 5 ms 2688 KB Output is correct
45 Correct 102 ms 15076 KB Output is correct
46 Correct 112 ms 15072 KB Output is correct
47 Correct 104 ms 15076 KB Output is correct
48 Correct 91 ms 15080 KB Output is correct
49 Correct 87 ms 15080 KB Output is correct
50 Correct 87 ms 15036 KB Output is correct
51 Correct 89 ms 14952 KB Output is correct
52 Correct 99 ms 15008 KB Output is correct
53 Correct 92 ms 15080 KB Output is correct
54 Correct 88 ms 15076 KB Output is correct
55 Correct 102 ms 15080 KB Output is correct
56 Correct 92 ms 15076 KB Output is correct
57 Correct 103 ms 15080 KB Output is correct
58 Correct 4 ms 2688 KB Output is correct
59 Correct 100 ms 14944 KB Output is correct
60 Correct 99 ms 15076 KB Output is correct
61 Correct 90 ms 15080 KB Output is correct
62 Correct 161 ms 14944 KB Output is correct
63 Correct 128 ms 15076 KB Output is correct
64 Correct 89 ms 14952 KB Output is correct
65 Correct 125 ms 14948 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 2688 KB Output is correct
2 Correct 4 ms 2688 KB Output is correct
3 Correct 5 ms 2688 KB Output is correct
4 Correct 4 ms 2720 KB Output is correct
5 Correct 6 ms 2688 KB Output is correct
6 Correct 4 ms 2688 KB Output is correct
7 Correct 5 ms 2688 KB Output is correct
8 Correct 4 ms 2688 KB Output is correct
9 Correct 4 ms 2688 KB Output is correct
10 Correct 5 ms 2688 KB Output is correct
11 Correct 5 ms 2688 KB Output is correct
12 Correct 5 ms 2688 KB Output is correct
13 Correct 4 ms 2688 KB Output is correct
14 Correct 4 ms 2688 KB Output is correct
15 Correct 5 ms 2664 KB Output is correct
16 Correct 5 ms 2688 KB Output is correct
17 Correct 4 ms 2688 KB Output is correct
18 Correct 4 ms 2688 KB Output is correct
19 Correct 5 ms 2688 KB Output is correct
20 Correct 6 ms 2688 KB Output is correct
21 Correct 6 ms 2688 KB Output is correct
22 Correct 4 ms 2688 KB Output is correct
23 Correct 5 ms 2688 KB Output is correct
24 Correct 5 ms 2688 KB Output is correct
25 Correct 5 ms 2688 KB Output is correct
26 Correct 68 ms 15976 KB Output is correct
27 Correct 81 ms 15848 KB Output is correct
28 Correct 65 ms 15972 KB Output is correct
29 Correct 81 ms 15848 KB Output is correct
30 Correct 82 ms 15844 KB Output is correct
31 Correct 69 ms 15844 KB Output is correct
32 Correct 75 ms 15716 KB Output is correct
33 Correct 67 ms 15848 KB Output is correct
34 Correct 71 ms 15844 KB Output is correct
35 Correct 68 ms 15840 KB Output is correct
36 Correct 64 ms 15972 KB Output is correct
37 Correct 63 ms 15908 KB Output is correct
38 Correct 63 ms 15968 KB Output is correct
39 Correct 64 ms 15840 KB Output is correct
40 Correct 71 ms 15840 KB Output is correct
41 Correct 66 ms 15848 KB Output is correct
42 Correct 67 ms 15848 KB Output is correct
43 Correct 63 ms 15976 KB Output is correct
44 Correct 63 ms 15968 KB Output is correct
45 Correct 103 ms 15968 KB Output is correct
46 Correct 4 ms 2688 KB Output is correct
47 Correct 63 ms 14960 KB Output is correct
48 Correct 60 ms 15080 KB Output is correct
49 Correct 59 ms 14944 KB Output is correct
50 Correct 60 ms 15076 KB Output is correct
51 Correct 61 ms 15020 KB Output is correct
52 Correct 60 ms 14952 KB Output is correct
53 Correct 63 ms 15072 KB Output is correct
54 Correct 59 ms 15080 KB Output is correct
55 Correct 58 ms 15080 KB Output is correct
56 Correct 64 ms 15000 KB Output is correct
57 Correct 59 ms 15080 KB Output is correct
58 Correct 59 ms 15064 KB Output is correct
59 Correct 61 ms 15076 KB Output is correct
60 Correct 58 ms 14952 KB Output is correct
61 Correct 60 ms 15076 KB Output is correct
62 Correct 86 ms 15072 KB Output is correct
63 Correct 84 ms 15072 KB Output is correct
64 Correct 61 ms 15036 KB Output is correct
65 Correct 62 ms 15048 KB Output is correct
66 Correct 62 ms 15000 KB Output is correct
67 Correct 5 ms 2688 KB Output is correct
68 Correct 5 ms 2816 KB Output is correct
69 Correct 5 ms 2816 KB Output is correct
70 Correct 5 ms 2816 KB Output is correct
71 Correct 5 ms 2816 KB Output is correct
72 Correct 5 ms 2816 KB Output is correct
73 Correct 5 ms 2816 KB Output is correct
74 Correct 5 ms 2816 KB Output is correct
75 Correct 5 ms 2816 KB Output is correct
76 Correct 5 ms 2880 KB Output is correct
77 Correct 5 ms 2816 KB Output is correct
78 Correct 6 ms 2944 KB Output is correct
79 Correct 5 ms 2816 KB Output is correct
80 Correct 5 ms 2816 KB Output is correct
81 Correct 4 ms 2688 KB Output is correct
82 Correct 5 ms 2816 KB Output is correct
83 Correct 5 ms 2944 KB Output is correct
84 Correct 5 ms 2816 KB Output is correct
85 Correct 5 ms 2816 KB Output is correct
86 Correct 5 ms 2816 KB Output is correct
87 Correct 6 ms 2816 KB Output is correct
88 Correct 5 ms 2816 KB Output is correct
89 Correct 4 ms 2688 KB Output is correct
90 Correct 5 ms 2944 KB Output is correct
91 Correct 5 ms 2944 KB Output is correct
92 Correct 5 ms 2944 KB Output is correct
93 Correct 5 ms 2944 KB Output is correct
94 Correct 5 ms 2944 KB Output is correct
95 Correct 5 ms 2944 KB Output is correct
96 Correct 5 ms 2944 KB Output is correct
97 Correct 5 ms 2944 KB Output is correct
98 Correct 5 ms 2944 KB Output is correct
99 Correct 5 ms 2944 KB Output is correct
100 Correct 6 ms 2944 KB Output is correct
101 Correct 5 ms 2944 KB Output is correct
102 Correct 6 ms 2944 KB Output is correct
103 Correct 6 ms 2688 KB Output is correct
104 Correct 6 ms 2944 KB Output is correct
105 Correct 6 ms 2944 KB Output is correct
106 Correct 6 ms 2944 KB Output is correct
107 Correct 5 ms 2944 KB Output is correct
108 Correct 5 ms 2944 KB Output is correct
109 Correct 5 ms 2944 KB Output is correct
110 Correct 5 ms 2944 KB Output is correct
111 Correct 5 ms 2688 KB Output is correct
112 Correct 102 ms 15076 KB Output is correct
113 Correct 112 ms 15072 KB Output is correct
114 Correct 104 ms 15076 KB Output is correct
115 Correct 91 ms 15080 KB Output is correct
116 Correct 87 ms 15080 KB Output is correct
117 Correct 87 ms 15036 KB Output is correct
118 Correct 89 ms 14952 KB Output is correct
119 Correct 99 ms 15008 KB Output is correct
120 Correct 92 ms 15080 KB Output is correct
121 Correct 88 ms 15076 KB Output is correct
122 Correct 102 ms 15080 KB Output is correct
123 Correct 92 ms 15076 KB Output is correct
124 Correct 103 ms 15080 KB Output is correct
125 Correct 4 ms 2688 KB Output is correct
126 Correct 100 ms 14944 KB Output is correct
127 Correct 99 ms 15076 KB Output is correct
128 Correct 90 ms 15080 KB Output is correct
129 Correct 161 ms 14944 KB Output is correct
130 Correct 128 ms 15076 KB Output is correct
131 Correct 89 ms 14952 KB Output is correct
132 Correct 125 ms 14948 KB Output is correct
133 Correct 5 ms 2688 KB Output is correct
134 Correct 100 ms 15848 KB Output is correct
135 Correct 127 ms 15968 KB Output is correct
136 Correct 103 ms 15844 KB Output is correct
137 Correct 115 ms 15844 KB Output is correct
138 Correct 119 ms 15720 KB Output is correct
139 Correct 108 ms 15848 KB Output is correct
140 Correct 96 ms 15844 KB Output is correct
141 Correct 96 ms 15784 KB Output is correct
142 Correct 93 ms 15720 KB Output is correct
143 Correct 148 ms 15720 KB Output is correct
144 Correct 155 ms 15712 KB Output is correct
145 Correct 114 ms 15844 KB Output is correct
146 Correct 98 ms 15716 KB Output is correct
147 Correct 4 ms 2688 KB Output is correct
148 Correct 97 ms 15840 KB Output is correct
149 Correct 97 ms 15720 KB Output is correct
150 Correct 100 ms 15844 KB Output is correct
151 Correct 95 ms 15848 KB Output is correct
152 Correct 97 ms 15840 KB Output is correct
153 Correct 91 ms 15720 KB Output is correct
154 Correct 97 ms 15848 KB Output is correct