Submission #949902

# Submission time Handle Problem Language Result Execution time Memory
949902 2024-03-19T21:12:36 Z sondos225 Cryptography (NOI20_crypto) C++17
100 / 100
503 ms 48308 KB
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
template<typename T>using ordered_set = tree<T,null_type,less_equal<T>,rb_tree_tag,tree_order_statistics_node_update>;//find_by_order(ind);
//order_of_key()
#define int long long
#define fast ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
#define pb push_back
#define yes "YES"
#define no "NO"
#define bigg INT_MAX
#define debug(x) cout<<(#x)<<" = " <<x<<endl;
#define all(x) x.begin(),x.end()
#define sz size()
#define nn '\n'
#define mms(x,y) memset(x,y,sizeof(x))
#define forr(i,j,n) for (int i=j; i<n; i++)
#define forn(i,j,n) for (int i=j; i>n; i--)
#define fi first
#define se second
#define la "LA"
#define cinn(x,y) for(int i=0; i<y; i++) cin>>x[i];
#define pii pair<int,int>
//
//int fact(int x)
//{
//    int w=1;
//    forr(i,1,x+1) w*=i;
//}
signed main()
{
//    #ifndef LOCAL
//    freopen("lifeguards.in","r",stdin);
//    freopen("lifeguards.out","w", stdout);
//    #endif
    fast
    int n;
    cin>>n;
    int fact[n];
    int w=1;
    int mod=1000000007;
    fact[0]=0;
    forr(i,1,n) {w*=i; w%=mod; fact[i]=w;}
    int a[n];
    map<int,int> m;
    int b[n];
    forr(i,0,n) { cin>>a[i]; b[i]=a[i];}
    sort(b,b+n);
    forr(i,0,n) m[b[i]]=i+1;
    forr(i,0,n)
    {
        a[i]=m[a[i]];
    }
    ordered_set <int> s;
    int na2s=n-1;
    int ans=0;
    forr(i,0,n)
    {
        int x=a[i]-1;
        //cout<<x<<' '<<s.order_of_key(x)<<endl;
        x-=s.order_of_key(a[i]);
        x*=fact[na2s]%mod;
        x%=mod;
     //   cout<<x<<' '<<endl;
        ans+=x;
        ans%=mod;
        s.insert(a[i]);
        na2s--;
    }
    cout<<(ans+1)%mod;
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 1 ms 456 KB Output is correct
14 Correct 1 ms 344 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 452 KB Output is correct
19 Correct 1 ms 600 KB Output is correct
20 Correct 0 ms 344 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 325 ms 47884 KB Output is correct
3 Correct 342 ms 47912 KB Output is correct
4 Correct 333 ms 47700 KB Output is correct
5 Correct 362 ms 47956 KB Output is correct
6 Correct 330 ms 47952 KB Output is correct
7 Correct 367 ms 47776 KB Output is correct
8 Correct 360 ms 47944 KB Output is correct
9 Correct 361 ms 47952 KB Output is correct
10 Correct 381 ms 47708 KB Output is correct
11 Correct 365 ms 47700 KB Output is correct
12 Correct 341 ms 47844 KB Output is correct
13 Correct 383 ms 47788 KB Output is correct
14 Correct 345 ms 47940 KB Output is correct
15 Correct 400 ms 47852 KB Output is correct
16 Correct 388 ms 47700 KB Output is correct
17 Correct 373 ms 47952 KB Output is correct
18 Correct 375 ms 48308 KB Output is correct
19 Correct 379 ms 47764 KB Output is correct
20 Correct 348 ms 47952 KB Output is correct
21 Correct 396 ms 47760 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 344 ms 47028 KB Output is correct
3 Correct 361 ms 46764 KB Output is correct
4 Correct 371 ms 47180 KB Output is correct
5 Correct 341 ms 47224 KB Output is correct
6 Correct 358 ms 46780 KB Output is correct
7 Correct 393 ms 46936 KB Output is correct
8 Correct 372 ms 46992 KB Output is correct
9 Correct 373 ms 46936 KB Output is correct
10 Correct 364 ms 46876 KB Output is correct
11 Correct 384 ms 46760 KB Output is correct
12 Correct 383 ms 47072 KB Output is correct
13 Correct 351 ms 46928 KB Output is correct
14 Correct 404 ms 46868 KB Output is correct
15 Correct 387 ms 46796 KB Output is correct
16 Correct 395 ms 46792 KB Output is correct
17 Correct 380 ms 47024 KB Output is correct
18 Correct 488 ms 46984 KB Output is correct
19 Correct 370 ms 47236 KB Output is correct
20 Correct 466 ms 46904 KB Output is correct
21 Correct 375 ms 46800 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 2 ms 1112 KB Output is correct
3 Correct 2 ms 856 KB Output is correct
4 Correct 2 ms 860 KB Output is correct
5 Correct 2 ms 860 KB Output is correct
6 Correct 2 ms 860 KB Output is correct
7 Correct 3 ms 860 KB Output is correct
8 Correct 3 ms 860 KB Output is correct
9 Correct 2 ms 860 KB Output is correct
10 Correct 2 ms 860 KB Output is correct
11 Correct 2 ms 860 KB Output is correct
12 Correct 2 ms 724 KB Output is correct
13 Correct 2 ms 860 KB Output is correct
14 Correct 2 ms 860 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 3 ms 860 KB Output is correct
17 Correct 2 ms 860 KB Output is correct
18 Correct 2 ms 860 KB Output is correct
19 Correct 2 ms 860 KB Output is correct
20 Correct 2 ms 860 KB Output is correct
21 Correct 2 ms 856 KB Output is correct
22 Correct 2 ms 860 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 1 ms 456 KB Output is correct
14 Correct 1 ms 344 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 452 KB Output is correct
19 Correct 1 ms 600 KB Output is correct
20 Correct 0 ms 344 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 2 ms 1112 KB Output is correct
27 Correct 2 ms 856 KB Output is correct
28 Correct 2 ms 860 KB Output is correct
29 Correct 2 ms 860 KB Output is correct
30 Correct 2 ms 860 KB Output is correct
31 Correct 3 ms 860 KB Output is correct
32 Correct 3 ms 860 KB Output is correct
33 Correct 2 ms 860 KB Output is correct
34 Correct 2 ms 860 KB Output is correct
35 Correct 2 ms 860 KB Output is correct
36 Correct 2 ms 724 KB Output is correct
37 Correct 2 ms 860 KB Output is correct
38 Correct 2 ms 860 KB Output is correct
39 Correct 0 ms 348 KB Output is correct
40 Correct 3 ms 860 KB Output is correct
41 Correct 2 ms 860 KB Output is correct
42 Correct 2 ms 860 KB Output is correct
43 Correct 2 ms 860 KB Output is correct
44 Correct 2 ms 860 KB Output is correct
45 Correct 2 ms 856 KB Output is correct
46 Correct 2 ms 860 KB Output is correct
47 Correct 0 ms 348 KB Output is correct
48 Correct 2 ms 912 KB Output is correct
49 Correct 2 ms 860 KB Output is correct
50 Correct 2 ms 884 KB Output is correct
51 Correct 2 ms 860 KB Output is correct
52 Correct 2 ms 856 KB Output is correct
53 Correct 2 ms 860 KB Output is correct
54 Correct 2 ms 860 KB Output is correct
55 Correct 2 ms 860 KB Output is correct
56 Correct 2 ms 856 KB Output is correct
57 Correct 2 ms 860 KB Output is correct
58 Correct 2 ms 860 KB Output is correct
59 Correct 2 ms 860 KB Output is correct
60 Correct 2 ms 860 KB Output is correct
61 Correct 1 ms 348 KB Output is correct
62 Correct 2 ms 808 KB Output is correct
63 Correct 2 ms 860 KB Output is correct
64 Correct 2 ms 860 KB Output is correct
65 Correct 2 ms 860 KB Output is correct
66 Correct 2 ms 860 KB Output is correct
67 Correct 2 ms 860 KB Output is correct
68 Correct 2 ms 808 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 344 ms 47028 KB Output is correct
3 Correct 361 ms 46764 KB Output is correct
4 Correct 371 ms 47180 KB Output is correct
5 Correct 341 ms 47224 KB Output is correct
6 Correct 358 ms 46780 KB Output is correct
7 Correct 393 ms 46936 KB Output is correct
8 Correct 372 ms 46992 KB Output is correct
9 Correct 373 ms 46936 KB Output is correct
10 Correct 364 ms 46876 KB Output is correct
11 Correct 384 ms 46760 KB Output is correct
12 Correct 383 ms 47072 KB Output is correct
13 Correct 351 ms 46928 KB Output is correct
14 Correct 404 ms 46868 KB Output is correct
15 Correct 387 ms 46796 KB Output is correct
16 Correct 395 ms 46792 KB Output is correct
17 Correct 380 ms 47024 KB Output is correct
18 Correct 488 ms 46984 KB Output is correct
19 Correct 370 ms 47236 KB Output is correct
20 Correct 466 ms 46904 KB Output is correct
21 Correct 375 ms 46800 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 2 ms 1112 KB Output is correct
24 Correct 2 ms 856 KB Output is correct
25 Correct 2 ms 860 KB Output is correct
26 Correct 2 ms 860 KB Output is correct
27 Correct 2 ms 860 KB Output is correct
28 Correct 3 ms 860 KB Output is correct
29 Correct 3 ms 860 KB Output is correct
30 Correct 2 ms 860 KB Output is correct
31 Correct 2 ms 860 KB Output is correct
32 Correct 2 ms 860 KB Output is correct
33 Correct 2 ms 724 KB Output is correct
34 Correct 2 ms 860 KB Output is correct
35 Correct 2 ms 860 KB Output is correct
36 Correct 0 ms 348 KB Output is correct
37 Correct 3 ms 860 KB Output is correct
38 Correct 2 ms 860 KB Output is correct
39 Correct 2 ms 860 KB Output is correct
40 Correct 2 ms 860 KB Output is correct
41 Correct 2 ms 860 KB Output is correct
42 Correct 2 ms 856 KB Output is correct
43 Correct 2 ms 860 KB Output is correct
44 Correct 1 ms 348 KB Output is correct
45 Correct 423 ms 46932 KB Output is correct
46 Correct 418 ms 46760 KB Output is correct
47 Correct 392 ms 46932 KB Output is correct
48 Correct 435 ms 46892 KB Output is correct
49 Correct 503 ms 47184 KB Output is correct
50 Correct 398 ms 46932 KB Output is correct
51 Correct 446 ms 46932 KB Output is correct
52 Correct 457 ms 46792 KB Output is correct
53 Correct 425 ms 46876 KB Output is correct
54 Correct 472 ms 47068 KB Output is correct
55 Correct 434 ms 46932 KB Output is correct
56 Correct 487 ms 47100 KB Output is correct
57 Correct 433 ms 46928 KB Output is correct
58 Correct 0 ms 344 KB Output is correct
59 Correct 440 ms 46768 KB Output is correct
60 Correct 455 ms 46956 KB Output is correct
61 Correct 460 ms 46932 KB Output is correct
62 Correct 442 ms 46932 KB Output is correct
63 Correct 438 ms 46932 KB Output is correct
64 Correct 467 ms 46896 KB Output is correct
65 Correct 415 ms 46932 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 1 ms 456 KB Output is correct
14 Correct 1 ms 344 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 452 KB Output is correct
19 Correct 1 ms 600 KB Output is correct
20 Correct 0 ms 344 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 325 ms 47884 KB Output is correct
27 Correct 342 ms 47912 KB Output is correct
28 Correct 333 ms 47700 KB Output is correct
29 Correct 362 ms 47956 KB Output is correct
30 Correct 330 ms 47952 KB Output is correct
31 Correct 367 ms 47776 KB Output is correct
32 Correct 360 ms 47944 KB Output is correct
33 Correct 361 ms 47952 KB Output is correct
34 Correct 381 ms 47708 KB Output is correct
35 Correct 365 ms 47700 KB Output is correct
36 Correct 341 ms 47844 KB Output is correct
37 Correct 383 ms 47788 KB Output is correct
38 Correct 345 ms 47940 KB Output is correct
39 Correct 400 ms 47852 KB Output is correct
40 Correct 388 ms 47700 KB Output is correct
41 Correct 373 ms 47952 KB Output is correct
42 Correct 375 ms 48308 KB Output is correct
43 Correct 379 ms 47764 KB Output is correct
44 Correct 348 ms 47952 KB Output is correct
45 Correct 396 ms 47760 KB Output is correct
46 Correct 0 ms 344 KB Output is correct
47 Correct 344 ms 47028 KB Output is correct
48 Correct 361 ms 46764 KB Output is correct
49 Correct 371 ms 47180 KB Output is correct
50 Correct 341 ms 47224 KB Output is correct
51 Correct 358 ms 46780 KB Output is correct
52 Correct 393 ms 46936 KB Output is correct
53 Correct 372 ms 46992 KB Output is correct
54 Correct 373 ms 46936 KB Output is correct
55 Correct 364 ms 46876 KB Output is correct
56 Correct 384 ms 46760 KB Output is correct
57 Correct 383 ms 47072 KB Output is correct
58 Correct 351 ms 46928 KB Output is correct
59 Correct 404 ms 46868 KB Output is correct
60 Correct 387 ms 46796 KB Output is correct
61 Correct 395 ms 46792 KB Output is correct
62 Correct 380 ms 47024 KB Output is correct
63 Correct 488 ms 46984 KB Output is correct
64 Correct 370 ms 47236 KB Output is correct
65 Correct 466 ms 46904 KB Output is correct
66 Correct 375 ms 46800 KB Output is correct
67 Correct 0 ms 348 KB Output is correct
68 Correct 2 ms 1112 KB Output is correct
69 Correct 2 ms 856 KB Output is correct
70 Correct 2 ms 860 KB Output is correct
71 Correct 2 ms 860 KB Output is correct
72 Correct 2 ms 860 KB Output is correct
73 Correct 3 ms 860 KB Output is correct
74 Correct 3 ms 860 KB Output is correct
75 Correct 2 ms 860 KB Output is correct
76 Correct 2 ms 860 KB Output is correct
77 Correct 2 ms 860 KB Output is correct
78 Correct 2 ms 724 KB Output is correct
79 Correct 2 ms 860 KB Output is correct
80 Correct 2 ms 860 KB Output is correct
81 Correct 0 ms 348 KB Output is correct
82 Correct 3 ms 860 KB Output is correct
83 Correct 2 ms 860 KB Output is correct
84 Correct 2 ms 860 KB Output is correct
85 Correct 2 ms 860 KB Output is correct
86 Correct 2 ms 860 KB Output is correct
87 Correct 2 ms 856 KB Output is correct
88 Correct 2 ms 860 KB Output is correct
89 Correct 0 ms 348 KB Output is correct
90 Correct 2 ms 912 KB Output is correct
91 Correct 2 ms 860 KB Output is correct
92 Correct 2 ms 884 KB Output is correct
93 Correct 2 ms 860 KB Output is correct
94 Correct 2 ms 856 KB Output is correct
95 Correct 2 ms 860 KB Output is correct
96 Correct 2 ms 860 KB Output is correct
97 Correct 2 ms 860 KB Output is correct
98 Correct 2 ms 856 KB Output is correct
99 Correct 2 ms 860 KB Output is correct
100 Correct 2 ms 860 KB Output is correct
101 Correct 2 ms 860 KB Output is correct
102 Correct 2 ms 860 KB Output is correct
103 Correct 1 ms 348 KB Output is correct
104 Correct 2 ms 808 KB Output is correct
105 Correct 2 ms 860 KB Output is correct
106 Correct 2 ms 860 KB Output is correct
107 Correct 2 ms 860 KB Output is correct
108 Correct 2 ms 860 KB Output is correct
109 Correct 2 ms 860 KB Output is correct
110 Correct 2 ms 808 KB Output is correct
111 Correct 1 ms 348 KB Output is correct
112 Correct 423 ms 46932 KB Output is correct
113 Correct 418 ms 46760 KB Output is correct
114 Correct 392 ms 46932 KB Output is correct
115 Correct 435 ms 46892 KB Output is correct
116 Correct 503 ms 47184 KB Output is correct
117 Correct 398 ms 46932 KB Output is correct
118 Correct 446 ms 46932 KB Output is correct
119 Correct 457 ms 46792 KB Output is correct
120 Correct 425 ms 46876 KB Output is correct
121 Correct 472 ms 47068 KB Output is correct
122 Correct 434 ms 46932 KB Output is correct
123 Correct 487 ms 47100 KB Output is correct
124 Correct 433 ms 46928 KB Output is correct
125 Correct 0 ms 344 KB Output is correct
126 Correct 440 ms 46768 KB Output is correct
127 Correct 455 ms 46956 KB Output is correct
128 Correct 460 ms 46932 KB Output is correct
129 Correct 442 ms 46932 KB Output is correct
130 Correct 438 ms 46932 KB Output is correct
131 Correct 467 ms 46896 KB Output is correct
132 Correct 415 ms 46932 KB Output is correct
133 Correct 0 ms 348 KB Output is correct
134 Correct 439 ms 47920 KB Output is correct
135 Correct 442 ms 47856 KB Output is correct
136 Correct 433 ms 47884 KB Output is correct
137 Correct 466 ms 47956 KB Output is correct
138 Correct 433 ms 47948 KB Output is correct
139 Correct 492 ms 47780 KB Output is correct
140 Correct 432 ms 47956 KB Output is correct
141 Correct 423 ms 47952 KB Output is correct
142 Correct 465 ms 47852 KB Output is correct
143 Correct 433 ms 47700 KB Output is correct
144 Correct 452 ms 47696 KB Output is correct
145 Correct 438 ms 47876 KB Output is correct
146 Correct 430 ms 47944 KB Output is correct
147 Correct 1 ms 348 KB Output is correct
148 Correct 409 ms 47852 KB Output is correct
149 Correct 437 ms 47952 KB Output is correct
150 Correct 492 ms 47852 KB Output is correct
151 Correct 473 ms 47820 KB Output is correct
152 Correct 442 ms 47848 KB Output is correct
153 Correct 423 ms 47856 KB Output is correct
154 Correct 424 ms 47744 KB Output is correct