답안 #504849

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
504849 2022-01-10T09:12:09 Z ToroTN Cryptography (NOI20_crypto) C++14
100 / 100
471 ms 33280 KB
#include<bits/stdc++.h>
using namespace std;
long long n,a[300005],b[300005],fac[300005],fen[300005],c[300005],ans=0;
vector<long long> v;
map<long long,long long> mp;
void update(long long u,long long val)
{
    while(u<=n)
    {
        fen[u]+=val;
        fen[u]%=1000000007;
        u+=(u&(-u));
    }
}
long long query(long long u)
{
    long long val=0;
    while(u>=1)
    {
        val+=fen[u];
        val%=1000000007;
        u-=(u&(-u));
    }
    return val;
}
int main()
{
    scanf("%lld",&n);
    for(int i=1;i<=n;i++)
    {
        scanf("%lld",&a[i]);
        v.push_back(a[i]);
    }
    v.push_back(-1);
    sort(v.begin(),v.end());
    for(int i=1;i<=n;i++)
    {
        mp[v[i]]=i;
    }
    for(int i=1;i<=n;i++)
    {
        b[i]=mp[a[i]];
    }
    /*for(int i=1;i<=n;i++)
    {
        printf("%lld ",b[i]);
    }
    printf("\n");*/
    fac[0]=1;
    for(int i=1;i<=300000;i++)
    {
        fac[i]=fac[i-1]*i;
        fac[i]%=1000000007;
    }
    for(int i=n;i>=1;i--)
    {
        update(b[i],1);
        c[i]=query(b[i]);
    }
    /*for(int i=1;i<=n;i++)
    {
        printf("%lld ",c[i]);
    }
    printf("\n");*/
    for(int i=1;i<=n;i++)
    {
        ans+=(c[i]-1)*fac[n-i];
        ans%=1000000007;
    }
    printf("%lld\n",(ans+1)%1000000007);
}

Compilation message

Crypto.cpp: In function 'int main()':
Crypto.cpp:28:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   28 |     scanf("%lld",&n);
      |     ~~~~~^~~~~~~~~~~
Crypto.cpp:31:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   31 |         scanf("%lld",&a[i]);
      |         ~~~~~^~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 2636 KB Output is correct
2 Correct 3 ms 2660 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 2636 KB Output is correct
2 Correct 3 ms 2660 KB Output is correct
3 Correct 2 ms 2636 KB Output is correct
4 Correct 2 ms 2636 KB Output is correct
5 Correct 3 ms 2636 KB Output is correct
6 Correct 3 ms 2636 KB Output is correct
7 Correct 2 ms 2636 KB Output is correct
8 Correct 3 ms 2636 KB Output is correct
9 Correct 3 ms 2636 KB Output is correct
10 Correct 2 ms 2636 KB Output is correct
11 Correct 3 ms 2636 KB Output is correct
12 Correct 3 ms 2636 KB Output is correct
13 Correct 2 ms 2636 KB Output is correct
14 Correct 3 ms 2636 KB Output is correct
15 Correct 2 ms 2636 KB Output is correct
16 Correct 2 ms 2636 KB Output is correct
17 Correct 2 ms 2636 KB Output is correct
18 Correct 3 ms 2636 KB Output is correct
19 Correct 3 ms 2636 KB Output is correct
20 Correct 3 ms 2636 KB Output is correct
21 Correct 3 ms 2636 KB Output is correct
22 Correct 3 ms 2636 KB Output is correct
23 Correct 2 ms 2636 KB Output is correct
24 Correct 3 ms 2636 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2636 KB Output is correct
2 Correct 161 ms 33176 KB Output is correct
3 Correct 163 ms 33096 KB Output is correct
4 Correct 167 ms 33068 KB Output is correct
5 Correct 142 ms 33048 KB Output is correct
6 Correct 149 ms 33076 KB Output is correct
7 Correct 173 ms 33088 KB Output is correct
8 Correct 183 ms 33148 KB Output is correct
9 Correct 163 ms 33148 KB Output is correct
10 Correct 175 ms 33100 KB Output is correct
11 Correct 164 ms 33048 KB Output is correct
12 Correct 163 ms 33064 KB Output is correct
13 Correct 141 ms 33164 KB Output is correct
14 Correct 167 ms 33064 KB Output is correct
15 Correct 165 ms 33152 KB Output is correct
16 Correct 179 ms 33144 KB Output is correct
17 Correct 177 ms 33116 KB Output is correct
18 Correct 166 ms 33160 KB Output is correct
19 Correct 145 ms 33064 KB Output is correct
20 Correct 157 ms 33144 KB Output is correct
21 Correct 166 ms 33156 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 2636 KB Output is correct
2 Correct 159 ms 33044 KB Output is correct
3 Correct 144 ms 33064 KB Output is correct
4 Correct 162 ms 33064 KB Output is correct
5 Correct 179 ms 33172 KB Output is correct
6 Correct 150 ms 33152 KB Output is correct
7 Correct 158 ms 33064 KB Output is correct
8 Correct 162 ms 33172 KB Output is correct
9 Correct 165 ms 33124 KB Output is correct
10 Correct 162 ms 33052 KB Output is correct
11 Correct 161 ms 33180 KB Output is correct
12 Correct 144 ms 33056 KB Output is correct
13 Correct 155 ms 33156 KB Output is correct
14 Correct 153 ms 33156 KB Output is correct
15 Correct 163 ms 33120 KB Output is correct
16 Correct 160 ms 33164 KB Output is correct
17 Correct 159 ms 33148 KB Output is correct
18 Correct 153 ms 33132 KB Output is correct
19 Correct 173 ms 33116 KB Output is correct
20 Correct 145 ms 33064 KB Output is correct
21 Correct 161 ms 33156 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 2636 KB Output is correct
2 Correct 5 ms 2892 KB Output is correct
3 Correct 4 ms 2892 KB Output is correct
4 Correct 4 ms 2892 KB Output is correct
5 Correct 4 ms 2892 KB Output is correct
6 Correct 4 ms 2892 KB Output is correct
7 Correct 3 ms 2892 KB Output is correct
8 Correct 4 ms 2892 KB Output is correct
9 Correct 4 ms 2892 KB Output is correct
10 Correct 4 ms 2892 KB Output is correct
11 Correct 3 ms 2892 KB Output is correct
12 Correct 4 ms 2892 KB Output is correct
13 Correct 4 ms 2892 KB Output is correct
14 Correct 5 ms 2892 KB Output is correct
15 Correct 3 ms 2636 KB Output is correct
16 Correct 5 ms 2904 KB Output is correct
17 Correct 4 ms 2892 KB Output is correct
18 Correct 4 ms 2892 KB Output is correct
19 Correct 4 ms 2892 KB Output is correct
20 Correct 4 ms 2892 KB Output is correct
21 Correct 4 ms 2860 KB Output is correct
22 Correct 4 ms 2892 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 2636 KB Output is correct
2 Correct 3 ms 2660 KB Output is correct
3 Correct 2 ms 2636 KB Output is correct
4 Correct 2 ms 2636 KB Output is correct
5 Correct 3 ms 2636 KB Output is correct
6 Correct 3 ms 2636 KB Output is correct
7 Correct 2 ms 2636 KB Output is correct
8 Correct 3 ms 2636 KB Output is correct
9 Correct 3 ms 2636 KB Output is correct
10 Correct 2 ms 2636 KB Output is correct
11 Correct 3 ms 2636 KB Output is correct
12 Correct 3 ms 2636 KB Output is correct
13 Correct 2 ms 2636 KB Output is correct
14 Correct 3 ms 2636 KB Output is correct
15 Correct 2 ms 2636 KB Output is correct
16 Correct 2 ms 2636 KB Output is correct
17 Correct 2 ms 2636 KB Output is correct
18 Correct 3 ms 2636 KB Output is correct
19 Correct 3 ms 2636 KB Output is correct
20 Correct 3 ms 2636 KB Output is correct
21 Correct 3 ms 2636 KB Output is correct
22 Correct 3 ms 2636 KB Output is correct
23 Correct 2 ms 2636 KB Output is correct
24 Correct 3 ms 2636 KB Output is correct
25 Correct 3 ms 2636 KB Output is correct
26 Correct 5 ms 2892 KB Output is correct
27 Correct 4 ms 2892 KB Output is correct
28 Correct 4 ms 2892 KB Output is correct
29 Correct 4 ms 2892 KB Output is correct
30 Correct 4 ms 2892 KB Output is correct
31 Correct 3 ms 2892 KB Output is correct
32 Correct 4 ms 2892 KB Output is correct
33 Correct 4 ms 2892 KB Output is correct
34 Correct 4 ms 2892 KB Output is correct
35 Correct 3 ms 2892 KB Output is correct
36 Correct 4 ms 2892 KB Output is correct
37 Correct 4 ms 2892 KB Output is correct
38 Correct 5 ms 2892 KB Output is correct
39 Correct 3 ms 2636 KB Output is correct
40 Correct 5 ms 2904 KB Output is correct
41 Correct 4 ms 2892 KB Output is correct
42 Correct 4 ms 2892 KB Output is correct
43 Correct 4 ms 2892 KB Output is correct
44 Correct 4 ms 2892 KB Output is correct
45 Correct 4 ms 2860 KB Output is correct
46 Correct 4 ms 2892 KB Output is correct
47 Correct 4 ms 2636 KB Output is correct
48 Correct 5 ms 2900 KB Output is correct
49 Correct 6 ms 2948 KB Output is correct
50 Correct 4 ms 2892 KB Output is correct
51 Correct 4 ms 2892 KB Output is correct
52 Correct 4 ms 2892 KB Output is correct
53 Correct 4 ms 2892 KB Output is correct
54 Correct 5 ms 2892 KB Output is correct
55 Correct 5 ms 2944 KB Output is correct
56 Correct 5 ms 3016 KB Output is correct
57 Correct 4 ms 2892 KB Output is correct
58 Correct 4 ms 2892 KB Output is correct
59 Correct 6 ms 2892 KB Output is correct
60 Correct 4 ms 2948 KB Output is correct
61 Correct 4 ms 2704 KB Output is correct
62 Correct 5 ms 2940 KB Output is correct
63 Correct 5 ms 2880 KB Output is correct
64 Correct 4 ms 2892 KB Output is correct
65 Correct 5 ms 2892 KB Output is correct
66 Correct 5 ms 2944 KB Output is correct
67 Correct 4 ms 2980 KB Output is correct
68 Correct 4 ms 2892 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 2636 KB Output is correct
2 Correct 159 ms 33044 KB Output is correct
3 Correct 144 ms 33064 KB Output is correct
4 Correct 162 ms 33064 KB Output is correct
5 Correct 179 ms 33172 KB Output is correct
6 Correct 150 ms 33152 KB Output is correct
7 Correct 158 ms 33064 KB Output is correct
8 Correct 162 ms 33172 KB Output is correct
9 Correct 165 ms 33124 KB Output is correct
10 Correct 162 ms 33052 KB Output is correct
11 Correct 161 ms 33180 KB Output is correct
12 Correct 144 ms 33056 KB Output is correct
13 Correct 155 ms 33156 KB Output is correct
14 Correct 153 ms 33156 KB Output is correct
15 Correct 163 ms 33120 KB Output is correct
16 Correct 160 ms 33164 KB Output is correct
17 Correct 159 ms 33148 KB Output is correct
18 Correct 153 ms 33132 KB Output is correct
19 Correct 173 ms 33116 KB Output is correct
20 Correct 145 ms 33064 KB Output is correct
21 Correct 161 ms 33156 KB Output is correct
22 Correct 3 ms 2636 KB Output is correct
23 Correct 5 ms 2892 KB Output is correct
24 Correct 4 ms 2892 KB Output is correct
25 Correct 4 ms 2892 KB Output is correct
26 Correct 4 ms 2892 KB Output is correct
27 Correct 4 ms 2892 KB Output is correct
28 Correct 3 ms 2892 KB Output is correct
29 Correct 4 ms 2892 KB Output is correct
30 Correct 4 ms 2892 KB Output is correct
31 Correct 4 ms 2892 KB Output is correct
32 Correct 3 ms 2892 KB Output is correct
33 Correct 4 ms 2892 KB Output is correct
34 Correct 4 ms 2892 KB Output is correct
35 Correct 5 ms 2892 KB Output is correct
36 Correct 3 ms 2636 KB Output is correct
37 Correct 5 ms 2904 KB Output is correct
38 Correct 4 ms 2892 KB Output is correct
39 Correct 4 ms 2892 KB Output is correct
40 Correct 4 ms 2892 KB Output is correct
41 Correct 4 ms 2892 KB Output is correct
42 Correct 4 ms 2860 KB Output is correct
43 Correct 4 ms 2892 KB Output is correct
44 Correct 3 ms 2636 KB Output is correct
45 Correct 430 ms 33124 KB Output is correct
46 Correct 374 ms 33056 KB Output is correct
47 Correct 448 ms 33076 KB Output is correct
48 Correct 439 ms 33156 KB Output is correct
49 Correct 416 ms 33120 KB Output is correct
50 Correct 422 ms 33120 KB Output is correct
51 Correct 471 ms 33132 KB Output is correct
52 Correct 378 ms 33168 KB Output is correct
53 Correct 398 ms 33196 KB Output is correct
54 Correct 404 ms 33192 KB Output is correct
55 Correct 393 ms 33176 KB Output is correct
56 Correct 387 ms 33052 KB Output is correct
57 Correct 355 ms 33056 KB Output is correct
58 Correct 2 ms 2636 KB Output is correct
59 Correct 392 ms 33164 KB Output is correct
60 Correct 341 ms 33064 KB Output is correct
61 Correct 367 ms 33168 KB Output is correct
62 Correct 340 ms 33144 KB Output is correct
63 Correct 390 ms 33136 KB Output is correct
64 Correct 381 ms 33212 KB Output is correct
65 Correct 368 ms 33200 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 2636 KB Output is correct
2 Correct 3 ms 2660 KB Output is correct
3 Correct 2 ms 2636 KB Output is correct
4 Correct 2 ms 2636 KB Output is correct
5 Correct 3 ms 2636 KB Output is correct
6 Correct 3 ms 2636 KB Output is correct
7 Correct 2 ms 2636 KB Output is correct
8 Correct 3 ms 2636 KB Output is correct
9 Correct 3 ms 2636 KB Output is correct
10 Correct 2 ms 2636 KB Output is correct
11 Correct 3 ms 2636 KB Output is correct
12 Correct 3 ms 2636 KB Output is correct
13 Correct 2 ms 2636 KB Output is correct
14 Correct 3 ms 2636 KB Output is correct
15 Correct 2 ms 2636 KB Output is correct
16 Correct 2 ms 2636 KB Output is correct
17 Correct 2 ms 2636 KB Output is correct
18 Correct 3 ms 2636 KB Output is correct
19 Correct 3 ms 2636 KB Output is correct
20 Correct 3 ms 2636 KB Output is correct
21 Correct 3 ms 2636 KB Output is correct
22 Correct 3 ms 2636 KB Output is correct
23 Correct 2 ms 2636 KB Output is correct
24 Correct 3 ms 2636 KB Output is correct
25 Correct 2 ms 2636 KB Output is correct
26 Correct 161 ms 33176 KB Output is correct
27 Correct 163 ms 33096 KB Output is correct
28 Correct 167 ms 33068 KB Output is correct
29 Correct 142 ms 33048 KB Output is correct
30 Correct 149 ms 33076 KB Output is correct
31 Correct 173 ms 33088 KB Output is correct
32 Correct 183 ms 33148 KB Output is correct
33 Correct 163 ms 33148 KB Output is correct
34 Correct 175 ms 33100 KB Output is correct
35 Correct 164 ms 33048 KB Output is correct
36 Correct 163 ms 33064 KB Output is correct
37 Correct 141 ms 33164 KB Output is correct
38 Correct 167 ms 33064 KB Output is correct
39 Correct 165 ms 33152 KB Output is correct
40 Correct 179 ms 33144 KB Output is correct
41 Correct 177 ms 33116 KB Output is correct
42 Correct 166 ms 33160 KB Output is correct
43 Correct 145 ms 33064 KB Output is correct
44 Correct 157 ms 33144 KB Output is correct
45 Correct 166 ms 33156 KB Output is correct
46 Correct 3 ms 2636 KB Output is correct
47 Correct 159 ms 33044 KB Output is correct
48 Correct 144 ms 33064 KB Output is correct
49 Correct 162 ms 33064 KB Output is correct
50 Correct 179 ms 33172 KB Output is correct
51 Correct 150 ms 33152 KB Output is correct
52 Correct 158 ms 33064 KB Output is correct
53 Correct 162 ms 33172 KB Output is correct
54 Correct 165 ms 33124 KB Output is correct
55 Correct 162 ms 33052 KB Output is correct
56 Correct 161 ms 33180 KB Output is correct
57 Correct 144 ms 33056 KB Output is correct
58 Correct 155 ms 33156 KB Output is correct
59 Correct 153 ms 33156 KB Output is correct
60 Correct 163 ms 33120 KB Output is correct
61 Correct 160 ms 33164 KB Output is correct
62 Correct 159 ms 33148 KB Output is correct
63 Correct 153 ms 33132 KB Output is correct
64 Correct 173 ms 33116 KB Output is correct
65 Correct 145 ms 33064 KB Output is correct
66 Correct 161 ms 33156 KB Output is correct
67 Correct 3 ms 2636 KB Output is correct
68 Correct 5 ms 2892 KB Output is correct
69 Correct 4 ms 2892 KB Output is correct
70 Correct 4 ms 2892 KB Output is correct
71 Correct 4 ms 2892 KB Output is correct
72 Correct 4 ms 2892 KB Output is correct
73 Correct 3 ms 2892 KB Output is correct
74 Correct 4 ms 2892 KB Output is correct
75 Correct 4 ms 2892 KB Output is correct
76 Correct 4 ms 2892 KB Output is correct
77 Correct 3 ms 2892 KB Output is correct
78 Correct 4 ms 2892 KB Output is correct
79 Correct 4 ms 2892 KB Output is correct
80 Correct 5 ms 2892 KB Output is correct
81 Correct 3 ms 2636 KB Output is correct
82 Correct 5 ms 2904 KB Output is correct
83 Correct 4 ms 2892 KB Output is correct
84 Correct 4 ms 2892 KB Output is correct
85 Correct 4 ms 2892 KB Output is correct
86 Correct 4 ms 2892 KB Output is correct
87 Correct 4 ms 2860 KB Output is correct
88 Correct 4 ms 2892 KB Output is correct
89 Correct 4 ms 2636 KB Output is correct
90 Correct 5 ms 2900 KB Output is correct
91 Correct 6 ms 2948 KB Output is correct
92 Correct 4 ms 2892 KB Output is correct
93 Correct 4 ms 2892 KB Output is correct
94 Correct 4 ms 2892 KB Output is correct
95 Correct 4 ms 2892 KB Output is correct
96 Correct 5 ms 2892 KB Output is correct
97 Correct 5 ms 2944 KB Output is correct
98 Correct 5 ms 3016 KB Output is correct
99 Correct 4 ms 2892 KB Output is correct
100 Correct 4 ms 2892 KB Output is correct
101 Correct 6 ms 2892 KB Output is correct
102 Correct 4 ms 2948 KB Output is correct
103 Correct 4 ms 2704 KB Output is correct
104 Correct 5 ms 2940 KB Output is correct
105 Correct 5 ms 2880 KB Output is correct
106 Correct 4 ms 2892 KB Output is correct
107 Correct 5 ms 2892 KB Output is correct
108 Correct 5 ms 2944 KB Output is correct
109 Correct 4 ms 2980 KB Output is correct
110 Correct 4 ms 2892 KB Output is correct
111 Correct 3 ms 2636 KB Output is correct
112 Correct 430 ms 33124 KB Output is correct
113 Correct 374 ms 33056 KB Output is correct
114 Correct 448 ms 33076 KB Output is correct
115 Correct 439 ms 33156 KB Output is correct
116 Correct 416 ms 33120 KB Output is correct
117 Correct 422 ms 33120 KB Output is correct
118 Correct 471 ms 33132 KB Output is correct
119 Correct 378 ms 33168 KB Output is correct
120 Correct 398 ms 33196 KB Output is correct
121 Correct 404 ms 33192 KB Output is correct
122 Correct 393 ms 33176 KB Output is correct
123 Correct 387 ms 33052 KB Output is correct
124 Correct 355 ms 33056 KB Output is correct
125 Correct 2 ms 2636 KB Output is correct
126 Correct 392 ms 33164 KB Output is correct
127 Correct 341 ms 33064 KB Output is correct
128 Correct 367 ms 33168 KB Output is correct
129 Correct 340 ms 33144 KB Output is correct
130 Correct 390 ms 33136 KB Output is correct
131 Correct 381 ms 33212 KB Output is correct
132 Correct 368 ms 33200 KB Output is correct
133 Correct 3 ms 2636 KB Output is correct
134 Correct 372 ms 33224 KB Output is correct
135 Correct 365 ms 33056 KB Output is correct
136 Correct 388 ms 33116 KB Output is correct
137 Correct 388 ms 33144 KB Output is correct
138 Correct 391 ms 33072 KB Output is correct
139 Correct 402 ms 33088 KB Output is correct
140 Correct 452 ms 33080 KB Output is correct
141 Correct 387 ms 33096 KB Output is correct
142 Correct 405 ms 33048 KB Output is correct
143 Correct 379 ms 33248 KB Output is correct
144 Correct 359 ms 33136 KB Output is correct
145 Correct 361 ms 33144 KB Output is correct
146 Correct 376 ms 33280 KB Output is correct
147 Correct 3 ms 2636 KB Output is correct
148 Correct 412 ms 33152 KB Output is correct
149 Correct 356 ms 33144 KB Output is correct
150 Correct 353 ms 33080 KB Output is correct
151 Correct 360 ms 33136 KB Output is correct
152 Correct 345 ms 33116 KB Output is correct
153 Correct 351 ms 33124 KB Output is correct
154 Correct 412 ms 33128 KB Output is correct