답안 #975501

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
975501 2024-05-05T10:46:37 Z AliHasanli Cryptography (NOI20_crypto) C++17
100 / 100
538 ms 34136 KB
#include<bits/stdc++.h>
using namespace std;
map<int,int>mp;
long long fact[300005];
long long a[300005],b[300005],seg[300005*4];
long long query(long long n,long long l,long long r,long long ql,long long qr)
{
    if(l>r || ql>qr || r<ql || l>qr)return 0;
    if(ql<=l && r<=qr)return seg[n];
    return query(2*n,l,(l+r)/2,ql,qr)+query(2*n+1,(l+r)/2+1,r,ql,qr);
}
void update(long long n,long long l,long long r,long long pos)
{
    if(l>r || r<pos || l>pos)return;
    if(l==r){seg[n]=1;return;}
    update(2*n,l,(l+r)/2,pos),update(2*n+1,(l+r)/2+1,r,pos);
    seg[n]=seg[2*n]+seg[2*n+1];
}
void fac(long long n)
{
    fact[0]=1;
    for(long long i=1;i<=300004;i++)
    fact[i]=(i*fact[i-1])%1000000007;
}
int main()
{
    fac(300004);
    long long n;
    cin>>n;
    for(long long i=0;i<n;i++)
    {
        cin>>a[i];
        b[i]=a[i];
    }
    sort(b,b+n);
    for(long long i=1;i<=n;i++)
    mp[b[i-1]]=i;
    long long cavab=1;
    for(long long i=0;i<n;i++)
    {
        //cout<<fact[n-i-1]<<" "<<query(1,1,n,1,mp[a[i]])+1<<endl;
        long long sira=mp[a[i]]-query(1,1,n,1,mp[a[i]]);
        cavab+=(fact[n-i-1]*(sira-1))%1000000007;
        cavab%=1000000007;
        update(1,1,n,mp[a[i]]);
    }
    cout<<cavab;
    return 0;
}


/*
4!*(1-1)+3!(4-1)+2!(1-1)+1!(2-1)+0!(1-1)+1=18+1+1=20;

*/
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 8284 KB Output is correct
2 Correct 4 ms 8284 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 8284 KB Output is correct
2 Correct 4 ms 8284 KB Output is correct
3 Correct 5 ms 8280 KB Output is correct
4 Correct 4 ms 8284 KB Output is correct
5 Correct 4 ms 8284 KB Output is correct
6 Correct 4 ms 8280 KB Output is correct
7 Correct 4 ms 8284 KB Output is correct
8 Correct 4 ms 8284 KB Output is correct
9 Correct 4 ms 8284 KB Output is correct
10 Correct 4 ms 8284 KB Output is correct
11 Correct 4 ms 8284 KB Output is correct
12 Correct 4 ms 8280 KB Output is correct
13 Correct 4 ms 8280 KB Output is correct
14 Correct 4 ms 8284 KB Output is correct
15 Correct 4 ms 8284 KB Output is correct
16 Correct 4 ms 8284 KB Output is correct
17 Correct 4 ms 8492 KB Output is correct
18 Correct 4 ms 8284 KB Output is correct
19 Correct 4 ms 8284 KB Output is correct
20 Correct 4 ms 8284 KB Output is correct
21 Correct 4 ms 8284 KB Output is correct
22 Correct 4 ms 8280 KB Output is correct
23 Correct 4 ms 8284 KB Output is correct
24 Correct 4 ms 8284 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 8284 KB Output is correct
2 Correct 296 ms 30756 KB Output is correct
3 Correct 298 ms 33816 KB Output is correct
4 Correct 297 ms 33836 KB Output is correct
5 Correct 301 ms 34092 KB Output is correct
6 Correct 292 ms 33620 KB Output is correct
7 Correct 295 ms 33668 KB Output is correct
8 Correct 294 ms 33540 KB Output is correct
9 Correct 295 ms 33616 KB Output is correct
10 Correct 293 ms 33608 KB Output is correct
11 Correct 309 ms 33612 KB Output is correct
12 Correct 292 ms 33752 KB Output is correct
13 Correct 291 ms 33616 KB Output is correct
14 Correct 300 ms 34060 KB Output is correct
15 Correct 289 ms 33552 KB Output is correct
16 Correct 288 ms 33620 KB Output is correct
17 Correct 295 ms 33640 KB Output is correct
18 Correct 320 ms 33616 KB Output is correct
19 Correct 312 ms 33744 KB Output is correct
20 Correct 291 ms 33840 KB Output is correct
21 Correct 300 ms 34136 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 8280 KB Output is correct
2 Correct 276 ms 30628 KB Output is correct
3 Correct 268 ms 30680 KB Output is correct
4 Correct 276 ms 30632 KB Output is correct
5 Correct 269 ms 30752 KB Output is correct
6 Correct 276 ms 30680 KB Output is correct
7 Correct 268 ms 30544 KB Output is correct
8 Correct 276 ms 30812 KB Output is correct
9 Correct 271 ms 30756 KB Output is correct
10 Correct 279 ms 30752 KB Output is correct
11 Correct 282 ms 30740 KB Output is correct
12 Correct 268 ms 30744 KB Output is correct
13 Correct 283 ms 30544 KB Output is correct
14 Correct 269 ms 30740 KB Output is correct
15 Correct 275 ms 30928 KB Output is correct
16 Correct 265 ms 30548 KB Output is correct
17 Correct 291 ms 30552 KB Output is correct
18 Correct 269 ms 30752 KB Output is correct
19 Correct 277 ms 30552 KB Output is correct
20 Correct 284 ms 30680 KB Output is correct
21 Correct 283 ms 30764 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 8280 KB Output is correct
2 Correct 6 ms 8540 KB Output is correct
3 Correct 6 ms 8540 KB Output is correct
4 Correct 6 ms 8540 KB Output is correct
5 Correct 6 ms 8644 KB Output is correct
6 Correct 6 ms 8540 KB Output is correct
7 Correct 6 ms 8512 KB Output is correct
8 Correct 6 ms 8540 KB Output is correct
9 Correct 6 ms 8536 KB Output is correct
10 Correct 6 ms 8540 KB Output is correct
11 Correct 6 ms 8708 KB Output is correct
12 Correct 6 ms 8540 KB Output is correct
13 Correct 6 ms 8540 KB Output is correct
14 Correct 6 ms 8540 KB Output is correct
15 Correct 4 ms 8284 KB Output is correct
16 Correct 7 ms 8536 KB Output is correct
17 Correct 6 ms 8540 KB Output is correct
18 Correct 7 ms 8540 KB Output is correct
19 Correct 6 ms 8536 KB Output is correct
20 Correct 6 ms 8536 KB Output is correct
21 Correct 6 ms 8540 KB Output is correct
22 Correct 6 ms 8536 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 8284 KB Output is correct
2 Correct 4 ms 8284 KB Output is correct
3 Correct 5 ms 8280 KB Output is correct
4 Correct 4 ms 8284 KB Output is correct
5 Correct 4 ms 8284 KB Output is correct
6 Correct 4 ms 8280 KB Output is correct
7 Correct 4 ms 8284 KB Output is correct
8 Correct 4 ms 8284 KB Output is correct
9 Correct 4 ms 8284 KB Output is correct
10 Correct 4 ms 8284 KB Output is correct
11 Correct 4 ms 8284 KB Output is correct
12 Correct 4 ms 8280 KB Output is correct
13 Correct 4 ms 8280 KB Output is correct
14 Correct 4 ms 8284 KB Output is correct
15 Correct 4 ms 8284 KB Output is correct
16 Correct 4 ms 8284 KB Output is correct
17 Correct 4 ms 8492 KB Output is correct
18 Correct 4 ms 8284 KB Output is correct
19 Correct 4 ms 8284 KB Output is correct
20 Correct 4 ms 8284 KB Output is correct
21 Correct 4 ms 8284 KB Output is correct
22 Correct 4 ms 8280 KB Output is correct
23 Correct 4 ms 8284 KB Output is correct
24 Correct 4 ms 8284 KB Output is correct
25 Correct 3 ms 8280 KB Output is correct
26 Correct 6 ms 8540 KB Output is correct
27 Correct 6 ms 8540 KB Output is correct
28 Correct 6 ms 8540 KB Output is correct
29 Correct 6 ms 8644 KB Output is correct
30 Correct 6 ms 8540 KB Output is correct
31 Correct 6 ms 8512 KB Output is correct
32 Correct 6 ms 8540 KB Output is correct
33 Correct 6 ms 8536 KB Output is correct
34 Correct 6 ms 8540 KB Output is correct
35 Correct 6 ms 8708 KB Output is correct
36 Correct 6 ms 8540 KB Output is correct
37 Correct 6 ms 8540 KB Output is correct
38 Correct 6 ms 8540 KB Output is correct
39 Correct 4 ms 8284 KB Output is correct
40 Correct 7 ms 8536 KB Output is correct
41 Correct 6 ms 8540 KB Output is correct
42 Correct 7 ms 8540 KB Output is correct
43 Correct 6 ms 8536 KB Output is correct
44 Correct 6 ms 8536 KB Output is correct
45 Correct 6 ms 8540 KB Output is correct
46 Correct 6 ms 8536 KB Output is correct
47 Correct 4 ms 8280 KB Output is correct
48 Correct 6 ms 8540 KB Output is correct
49 Correct 6 ms 8540 KB Output is correct
50 Correct 6 ms 8548 KB Output is correct
51 Correct 7 ms 8540 KB Output is correct
52 Correct 7 ms 8536 KB Output is correct
53 Correct 6 ms 8540 KB Output is correct
54 Correct 6 ms 8724 KB Output is correct
55 Correct 6 ms 8540 KB Output is correct
56 Correct 8 ms 8540 KB Output is correct
57 Correct 7 ms 8540 KB Output is correct
58 Correct 7 ms 8540 KB Output is correct
59 Correct 7 ms 8540 KB Output is correct
60 Correct 6 ms 8508 KB Output is correct
61 Correct 4 ms 8284 KB Output is correct
62 Correct 6 ms 8628 KB Output is correct
63 Correct 6 ms 8540 KB Output is correct
64 Correct 6 ms 8540 KB Output is correct
65 Correct 6 ms 8540 KB Output is correct
66 Correct 6 ms 8540 KB Output is correct
67 Correct 6 ms 8540 KB Output is correct
68 Correct 6 ms 8540 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 8280 KB Output is correct
2 Correct 276 ms 30628 KB Output is correct
3 Correct 268 ms 30680 KB Output is correct
4 Correct 276 ms 30632 KB Output is correct
5 Correct 269 ms 30752 KB Output is correct
6 Correct 276 ms 30680 KB Output is correct
7 Correct 268 ms 30544 KB Output is correct
8 Correct 276 ms 30812 KB Output is correct
9 Correct 271 ms 30756 KB Output is correct
10 Correct 279 ms 30752 KB Output is correct
11 Correct 282 ms 30740 KB Output is correct
12 Correct 268 ms 30744 KB Output is correct
13 Correct 283 ms 30544 KB Output is correct
14 Correct 269 ms 30740 KB Output is correct
15 Correct 275 ms 30928 KB Output is correct
16 Correct 265 ms 30548 KB Output is correct
17 Correct 291 ms 30552 KB Output is correct
18 Correct 269 ms 30752 KB Output is correct
19 Correct 277 ms 30552 KB Output is correct
20 Correct 284 ms 30680 KB Output is correct
21 Correct 283 ms 30764 KB Output is correct
22 Correct 3 ms 8280 KB Output is correct
23 Correct 6 ms 8540 KB Output is correct
24 Correct 6 ms 8540 KB Output is correct
25 Correct 6 ms 8540 KB Output is correct
26 Correct 6 ms 8644 KB Output is correct
27 Correct 6 ms 8540 KB Output is correct
28 Correct 6 ms 8512 KB Output is correct
29 Correct 6 ms 8540 KB Output is correct
30 Correct 6 ms 8536 KB Output is correct
31 Correct 6 ms 8540 KB Output is correct
32 Correct 6 ms 8708 KB Output is correct
33 Correct 6 ms 8540 KB Output is correct
34 Correct 6 ms 8540 KB Output is correct
35 Correct 6 ms 8540 KB Output is correct
36 Correct 4 ms 8284 KB Output is correct
37 Correct 7 ms 8536 KB Output is correct
38 Correct 6 ms 8540 KB Output is correct
39 Correct 7 ms 8540 KB Output is correct
40 Correct 6 ms 8536 KB Output is correct
41 Correct 6 ms 8536 KB Output is correct
42 Correct 6 ms 8540 KB Output is correct
43 Correct 6 ms 8536 KB Output is correct
44 Correct 4 ms 8284 KB Output is correct
45 Correct 489 ms 32788 KB Output is correct
46 Correct 454 ms 32532 KB Output is correct
47 Correct 472 ms 33032 KB Output is correct
48 Correct 473 ms 32852 KB Output is correct
49 Correct 453 ms 32588 KB Output is correct
50 Correct 478 ms 33104 KB Output is correct
51 Correct 460 ms 32596 KB Output is correct
52 Correct 483 ms 32784 KB Output is correct
53 Correct 456 ms 32848 KB Output is correct
54 Correct 480 ms 32532 KB Output is correct
55 Correct 499 ms 33108 KB Output is correct
56 Correct 456 ms 32852 KB Output is correct
57 Correct 473 ms 32648 KB Output is correct
58 Correct 4 ms 8284 KB Output is correct
59 Correct 483 ms 32716 KB Output is correct
60 Correct 481 ms 32596 KB Output is correct
61 Correct 483 ms 32972 KB Output is correct
62 Correct 506 ms 32944 KB Output is correct
63 Correct 453 ms 32884 KB Output is correct
64 Correct 478 ms 32708 KB Output is correct
65 Correct 475 ms 32596 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 8284 KB Output is correct
2 Correct 4 ms 8284 KB Output is correct
3 Correct 5 ms 8280 KB Output is correct
4 Correct 4 ms 8284 KB Output is correct
5 Correct 4 ms 8284 KB Output is correct
6 Correct 4 ms 8280 KB Output is correct
7 Correct 4 ms 8284 KB Output is correct
8 Correct 4 ms 8284 KB Output is correct
9 Correct 4 ms 8284 KB Output is correct
10 Correct 4 ms 8284 KB Output is correct
11 Correct 4 ms 8284 KB Output is correct
12 Correct 4 ms 8280 KB Output is correct
13 Correct 4 ms 8280 KB Output is correct
14 Correct 4 ms 8284 KB Output is correct
15 Correct 4 ms 8284 KB Output is correct
16 Correct 4 ms 8284 KB Output is correct
17 Correct 4 ms 8492 KB Output is correct
18 Correct 4 ms 8284 KB Output is correct
19 Correct 4 ms 8284 KB Output is correct
20 Correct 4 ms 8284 KB Output is correct
21 Correct 4 ms 8284 KB Output is correct
22 Correct 4 ms 8280 KB Output is correct
23 Correct 4 ms 8284 KB Output is correct
24 Correct 4 ms 8284 KB Output is correct
25 Correct 4 ms 8284 KB Output is correct
26 Correct 296 ms 30756 KB Output is correct
27 Correct 298 ms 33816 KB Output is correct
28 Correct 297 ms 33836 KB Output is correct
29 Correct 301 ms 34092 KB Output is correct
30 Correct 292 ms 33620 KB Output is correct
31 Correct 295 ms 33668 KB Output is correct
32 Correct 294 ms 33540 KB Output is correct
33 Correct 295 ms 33616 KB Output is correct
34 Correct 293 ms 33608 KB Output is correct
35 Correct 309 ms 33612 KB Output is correct
36 Correct 292 ms 33752 KB Output is correct
37 Correct 291 ms 33616 KB Output is correct
38 Correct 300 ms 34060 KB Output is correct
39 Correct 289 ms 33552 KB Output is correct
40 Correct 288 ms 33620 KB Output is correct
41 Correct 295 ms 33640 KB Output is correct
42 Correct 320 ms 33616 KB Output is correct
43 Correct 312 ms 33744 KB Output is correct
44 Correct 291 ms 33840 KB Output is correct
45 Correct 300 ms 34136 KB Output is correct
46 Correct 4 ms 8280 KB Output is correct
47 Correct 276 ms 30628 KB Output is correct
48 Correct 268 ms 30680 KB Output is correct
49 Correct 276 ms 30632 KB Output is correct
50 Correct 269 ms 30752 KB Output is correct
51 Correct 276 ms 30680 KB Output is correct
52 Correct 268 ms 30544 KB Output is correct
53 Correct 276 ms 30812 KB Output is correct
54 Correct 271 ms 30756 KB Output is correct
55 Correct 279 ms 30752 KB Output is correct
56 Correct 282 ms 30740 KB Output is correct
57 Correct 268 ms 30744 KB Output is correct
58 Correct 283 ms 30544 KB Output is correct
59 Correct 269 ms 30740 KB Output is correct
60 Correct 275 ms 30928 KB Output is correct
61 Correct 265 ms 30548 KB Output is correct
62 Correct 291 ms 30552 KB Output is correct
63 Correct 269 ms 30752 KB Output is correct
64 Correct 277 ms 30552 KB Output is correct
65 Correct 284 ms 30680 KB Output is correct
66 Correct 283 ms 30764 KB Output is correct
67 Correct 3 ms 8280 KB Output is correct
68 Correct 6 ms 8540 KB Output is correct
69 Correct 6 ms 8540 KB Output is correct
70 Correct 6 ms 8540 KB Output is correct
71 Correct 6 ms 8644 KB Output is correct
72 Correct 6 ms 8540 KB Output is correct
73 Correct 6 ms 8512 KB Output is correct
74 Correct 6 ms 8540 KB Output is correct
75 Correct 6 ms 8536 KB Output is correct
76 Correct 6 ms 8540 KB Output is correct
77 Correct 6 ms 8708 KB Output is correct
78 Correct 6 ms 8540 KB Output is correct
79 Correct 6 ms 8540 KB Output is correct
80 Correct 6 ms 8540 KB Output is correct
81 Correct 4 ms 8284 KB Output is correct
82 Correct 7 ms 8536 KB Output is correct
83 Correct 6 ms 8540 KB Output is correct
84 Correct 7 ms 8540 KB Output is correct
85 Correct 6 ms 8536 KB Output is correct
86 Correct 6 ms 8536 KB Output is correct
87 Correct 6 ms 8540 KB Output is correct
88 Correct 6 ms 8536 KB Output is correct
89 Correct 4 ms 8280 KB Output is correct
90 Correct 6 ms 8540 KB Output is correct
91 Correct 6 ms 8540 KB Output is correct
92 Correct 6 ms 8548 KB Output is correct
93 Correct 7 ms 8540 KB Output is correct
94 Correct 7 ms 8536 KB Output is correct
95 Correct 6 ms 8540 KB Output is correct
96 Correct 6 ms 8724 KB Output is correct
97 Correct 6 ms 8540 KB Output is correct
98 Correct 8 ms 8540 KB Output is correct
99 Correct 7 ms 8540 KB Output is correct
100 Correct 7 ms 8540 KB Output is correct
101 Correct 7 ms 8540 KB Output is correct
102 Correct 6 ms 8508 KB Output is correct
103 Correct 4 ms 8284 KB Output is correct
104 Correct 6 ms 8628 KB Output is correct
105 Correct 6 ms 8540 KB Output is correct
106 Correct 6 ms 8540 KB Output is correct
107 Correct 6 ms 8540 KB Output is correct
108 Correct 6 ms 8540 KB Output is correct
109 Correct 6 ms 8540 KB Output is correct
110 Correct 6 ms 8540 KB Output is correct
111 Correct 4 ms 8284 KB Output is correct
112 Correct 489 ms 32788 KB Output is correct
113 Correct 454 ms 32532 KB Output is correct
114 Correct 472 ms 33032 KB Output is correct
115 Correct 473 ms 32852 KB Output is correct
116 Correct 453 ms 32588 KB Output is correct
117 Correct 478 ms 33104 KB Output is correct
118 Correct 460 ms 32596 KB Output is correct
119 Correct 483 ms 32784 KB Output is correct
120 Correct 456 ms 32848 KB Output is correct
121 Correct 480 ms 32532 KB Output is correct
122 Correct 499 ms 33108 KB Output is correct
123 Correct 456 ms 32852 KB Output is correct
124 Correct 473 ms 32648 KB Output is correct
125 Correct 4 ms 8284 KB Output is correct
126 Correct 483 ms 32716 KB Output is correct
127 Correct 481 ms 32596 KB Output is correct
128 Correct 483 ms 32972 KB Output is correct
129 Correct 506 ms 32944 KB Output is correct
130 Correct 453 ms 32884 KB Output is correct
131 Correct 478 ms 32708 KB Output is correct
132 Correct 475 ms 32596 KB Output is correct
133 Correct 4 ms 8284 KB Output is correct
134 Correct 486 ms 33564 KB Output is correct
135 Correct 520 ms 33676 KB Output is correct
136 Correct 469 ms 33620 KB Output is correct
137 Correct 492 ms 33848 KB Output is correct
138 Correct 512 ms 33848 KB Output is correct
139 Correct 466 ms 33616 KB Output is correct
140 Correct 475 ms 33568 KB Output is correct
141 Correct 499 ms 33688 KB Output is correct
142 Correct 515 ms 33848 KB Output is correct
143 Correct 495 ms 33848 KB Output is correct
144 Correct 508 ms 33844 KB Output is correct
145 Correct 479 ms 33816 KB Output is correct
146 Correct 506 ms 34052 KB Output is correct
147 Correct 4 ms 8284 KB Output is correct
148 Correct 485 ms 33588 KB Output is correct
149 Correct 517 ms 33616 KB Output is correct
150 Correct 538 ms 33896 KB Output is correct
151 Correct 484 ms 33808 KB Output is correct
152 Correct 496 ms 33676 KB Output is correct
153 Correct 530 ms 33672 KB Output is correct
154 Correct 490 ms 33540 KB Output is correct