Submission #1011975

# Submission time Handle Problem Language Result Execution time Memory
1011975 2024-07-01T13:02:59 Z kaopj Cryptography (NOI20_crypto) C++17
88 / 100
1000 ms 33692 KB
#include <iostream>
#include <vector>
#include <algorithm>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define int long long
#define orderedset tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>
#define lgm cin.tie(0)->sync_with_stdio(0);
const int mod = 1e9+7;
using namespace std;
signed main() {
    lgm;
    orderedset s;
    int n;
    cin >> n;
    vector<pair<int,int>> o(n);
    vector<int> num(n);
    for (int i=0;i<n;i++) {
        cin >> num[i];
        o[i]={num[i],i};
    }
    sort(o.begin(),o.end());
    int ans=0;
    for (int i=0;i<n;i++) {
        num[o[i].second]=i;
    }
    vector<int> lesscnt(n);
    int f[n+1];
    f[0]=1;
    f[1]=1;
    for (int i=2;i<=n;i++) {
        f[i]=i*f[i-1]%mod;
    }
    for (int i=n-1;i>=0;i--) {
        int l=0,r=n-1-i,m;
        while (l<r) {
            m=(l+r)>>1;
            if (*s.find_by_order(m) >= num[i]) {
                r=m;
            } else {
                l=m+1;
            }
        }
        lesscnt[i]=l;
        s.insert(num[i]);
    }
    for (int i=0;i<n;i++) {
        ans=(ans+f[n-i-1]*lesscnt[i]%mod)%mod;
    }
    cout << (ans+1)%mod;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 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 0 ms 348 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 612 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 372 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 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 348 KB Output is correct
19 Correct 1 ms 344 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 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 1 ms 348 KB Output is correct
2 Correct 800 ms 30868 KB Output is correct
3 Correct 803 ms 30804 KB Output is correct
4 Correct 775 ms 30804 KB Output is correct
5 Correct 796 ms 30768 KB Output is correct
6 Correct 787 ms 30804 KB Output is correct
7 Correct 828 ms 30928 KB Output is correct
8 Correct 824 ms 30784 KB Output is correct
9 Correct 848 ms 30868 KB Output is correct
10 Correct 819 ms 30800 KB Output is correct
11 Correct 828 ms 30900 KB Output is correct
12 Correct 768 ms 30780 KB Output is correct
13 Correct 745 ms 30968 KB Output is correct
14 Correct 746 ms 30796 KB Output is correct
15 Correct 788 ms 30804 KB Output is correct
16 Correct 810 ms 30800 KB Output is correct
17 Correct 789 ms 30804 KB Output is correct
18 Correct 776 ms 31056 KB Output is correct
19 Correct 763 ms 30848 KB Output is correct
20 Correct 766 ms 30820 KB Output is correct
21 Correct 731 ms 30760 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 796 ms 30804 KB Output is correct
3 Correct 815 ms 30724 KB Output is correct
4 Correct 836 ms 30888 KB Output is correct
5 Correct 799 ms 30808 KB Output is correct
6 Correct 791 ms 30900 KB Output is correct
7 Correct 779 ms 30864 KB Output is correct
8 Correct 784 ms 30816 KB Output is correct
9 Correct 769 ms 30804 KB Output is correct
10 Correct 745 ms 30792 KB Output is correct
11 Correct 748 ms 30804 KB Output is correct
12 Correct 722 ms 30852 KB Output is correct
13 Correct 723 ms 30808 KB Output is correct
14 Correct 750 ms 30804 KB Output is correct
15 Correct 789 ms 30808 KB Output is correct
16 Correct 761 ms 30796 KB Output is correct
17 Correct 811 ms 31056 KB Output is correct
18 Correct 795 ms 30800 KB Output is correct
19 Correct 793 ms 30800 KB Output is correct
20 Correct 766 ms 30956 KB Output is correct
21 Correct 774 ms 30800 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 2 ms 852 KB Output is correct
3 Correct 3 ms 604 KB Output is correct
4 Correct 3 ms 680 KB Output is correct
5 Correct 3 ms 604 KB Output is correct
6 Correct 3 ms 604 KB Output is correct
7 Correct 3 ms 604 KB Output is correct
8 Correct 3 ms 640 KB Output is correct
9 Correct 3 ms 604 KB Output is correct
10 Correct 3 ms 604 KB Output is correct
11 Correct 3 ms 604 KB Output is correct
12 Correct 3 ms 604 KB Output is correct
13 Correct 3 ms 856 KB Output is correct
14 Correct 3 ms 736 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 3 ms 604 KB Output is correct
17 Correct 3 ms 600 KB Output is correct
18 Correct 3 ms 604 KB Output is correct
19 Correct 3 ms 856 KB Output is correct
20 Correct 3 ms 604 KB Output is correct
21 Correct 3 ms 604 KB Output is correct
22 Correct 3 ms 604 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 612 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 372 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 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 348 KB Output is correct
19 Correct 1 ms 344 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 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 344 KB Output is correct
26 Correct 2 ms 852 KB Output is correct
27 Correct 3 ms 604 KB Output is correct
28 Correct 3 ms 680 KB Output is correct
29 Correct 3 ms 604 KB Output is correct
30 Correct 3 ms 604 KB Output is correct
31 Correct 3 ms 604 KB Output is correct
32 Correct 3 ms 640 KB Output is correct
33 Correct 3 ms 604 KB Output is correct
34 Correct 3 ms 604 KB Output is correct
35 Correct 3 ms 604 KB Output is correct
36 Correct 3 ms 604 KB Output is correct
37 Correct 3 ms 856 KB Output is correct
38 Correct 3 ms 736 KB Output is correct
39 Correct 0 ms 348 KB Output is correct
40 Correct 3 ms 604 KB Output is correct
41 Correct 3 ms 600 KB Output is correct
42 Correct 3 ms 604 KB Output is correct
43 Correct 3 ms 856 KB Output is correct
44 Correct 3 ms 604 KB Output is correct
45 Correct 3 ms 604 KB Output is correct
46 Correct 3 ms 604 KB Output is correct
47 Correct 0 ms 452 KB Output is correct
48 Correct 3 ms 556 KB Output is correct
49 Correct 3 ms 604 KB Output is correct
50 Correct 3 ms 600 KB Output is correct
51 Correct 3 ms 604 KB Output is correct
52 Correct 3 ms 768 KB Output is correct
53 Correct 3 ms 604 KB Output is correct
54 Correct 3 ms 604 KB Output is correct
55 Correct 3 ms 788 KB Output is correct
56 Correct 3 ms 564 KB Output is correct
57 Correct 3 ms 604 KB Output is correct
58 Correct 3 ms 556 KB Output is correct
59 Correct 3 ms 604 KB Output is correct
60 Correct 3 ms 724 KB Output is correct
61 Correct 0 ms 344 KB Output is correct
62 Correct 3 ms 556 KB Output is correct
63 Correct 3 ms 564 KB Output is correct
64 Correct 3 ms 604 KB Output is correct
65 Correct 3 ms 604 KB Output is correct
66 Correct 3 ms 604 KB Output is correct
67 Correct 3 ms 604 KB Output is correct
68 Correct 3 ms 604 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 796 ms 30804 KB Output is correct
3 Correct 815 ms 30724 KB Output is correct
4 Correct 836 ms 30888 KB Output is correct
5 Correct 799 ms 30808 KB Output is correct
6 Correct 791 ms 30900 KB Output is correct
7 Correct 779 ms 30864 KB Output is correct
8 Correct 784 ms 30816 KB Output is correct
9 Correct 769 ms 30804 KB Output is correct
10 Correct 745 ms 30792 KB Output is correct
11 Correct 748 ms 30804 KB Output is correct
12 Correct 722 ms 30852 KB Output is correct
13 Correct 723 ms 30808 KB Output is correct
14 Correct 750 ms 30804 KB Output is correct
15 Correct 789 ms 30808 KB Output is correct
16 Correct 761 ms 30796 KB Output is correct
17 Correct 811 ms 31056 KB Output is correct
18 Correct 795 ms 30800 KB Output is correct
19 Correct 793 ms 30800 KB Output is correct
20 Correct 766 ms 30956 KB Output is correct
21 Correct 774 ms 30800 KB Output is correct
22 Correct 0 ms 344 KB Output is correct
23 Correct 2 ms 852 KB Output is correct
24 Correct 3 ms 604 KB Output is correct
25 Correct 3 ms 680 KB Output is correct
26 Correct 3 ms 604 KB Output is correct
27 Correct 3 ms 604 KB Output is correct
28 Correct 3 ms 604 KB Output is correct
29 Correct 3 ms 640 KB Output is correct
30 Correct 3 ms 604 KB Output is correct
31 Correct 3 ms 604 KB Output is correct
32 Correct 3 ms 604 KB Output is correct
33 Correct 3 ms 604 KB Output is correct
34 Correct 3 ms 856 KB Output is correct
35 Correct 3 ms 736 KB Output is correct
36 Correct 0 ms 348 KB Output is correct
37 Correct 3 ms 604 KB Output is correct
38 Correct 3 ms 600 KB Output is correct
39 Correct 3 ms 604 KB Output is correct
40 Correct 3 ms 856 KB Output is correct
41 Correct 3 ms 604 KB Output is correct
42 Correct 3 ms 604 KB Output is correct
43 Correct 3 ms 604 KB Output is correct
44 Correct 0 ms 348 KB Output is correct
45 Correct 965 ms 32872 KB Output is correct
46 Correct 950 ms 32836 KB Output is correct
47 Correct 915 ms 32848 KB Output is correct
48 Correct 896 ms 32852 KB Output is correct
49 Correct 922 ms 32868 KB Output is correct
50 Correct 861 ms 32872 KB Output is correct
51 Correct 911 ms 32848 KB Output is correct
52 Correct 952 ms 32852 KB Output is correct
53 Correct 907 ms 32848 KB Output is correct
54 Correct 908 ms 32776 KB Output is correct
55 Correct 901 ms 32740 KB Output is correct
56 Correct 947 ms 32844 KB Output is correct
57 Correct 930 ms 32812 KB Output is correct
58 Correct 1 ms 344 KB Output is correct
59 Correct 929 ms 32764 KB Output is correct
60 Correct 944 ms 32772 KB Output is correct
61 Correct 991 ms 32696 KB Output is correct
62 Correct 942 ms 32712 KB Output is correct
63 Correct 968 ms 32908 KB Output is correct
64 Correct 911 ms 32848 KB Output is correct
65 Correct 982 ms 32848 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 612 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 372 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 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 348 KB Output is correct
19 Correct 1 ms 344 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 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 1 ms 348 KB Output is correct
26 Correct 800 ms 30868 KB Output is correct
27 Correct 803 ms 30804 KB Output is correct
28 Correct 775 ms 30804 KB Output is correct
29 Correct 796 ms 30768 KB Output is correct
30 Correct 787 ms 30804 KB Output is correct
31 Correct 828 ms 30928 KB Output is correct
32 Correct 824 ms 30784 KB Output is correct
33 Correct 848 ms 30868 KB Output is correct
34 Correct 819 ms 30800 KB Output is correct
35 Correct 828 ms 30900 KB Output is correct
36 Correct 768 ms 30780 KB Output is correct
37 Correct 745 ms 30968 KB Output is correct
38 Correct 746 ms 30796 KB Output is correct
39 Correct 788 ms 30804 KB Output is correct
40 Correct 810 ms 30800 KB Output is correct
41 Correct 789 ms 30804 KB Output is correct
42 Correct 776 ms 31056 KB Output is correct
43 Correct 763 ms 30848 KB Output is correct
44 Correct 766 ms 30820 KB Output is correct
45 Correct 731 ms 30760 KB Output is correct
46 Correct 0 ms 348 KB Output is correct
47 Correct 796 ms 30804 KB Output is correct
48 Correct 815 ms 30724 KB Output is correct
49 Correct 836 ms 30888 KB Output is correct
50 Correct 799 ms 30808 KB Output is correct
51 Correct 791 ms 30900 KB Output is correct
52 Correct 779 ms 30864 KB Output is correct
53 Correct 784 ms 30816 KB Output is correct
54 Correct 769 ms 30804 KB Output is correct
55 Correct 745 ms 30792 KB Output is correct
56 Correct 748 ms 30804 KB Output is correct
57 Correct 722 ms 30852 KB Output is correct
58 Correct 723 ms 30808 KB Output is correct
59 Correct 750 ms 30804 KB Output is correct
60 Correct 789 ms 30808 KB Output is correct
61 Correct 761 ms 30796 KB Output is correct
62 Correct 811 ms 31056 KB Output is correct
63 Correct 795 ms 30800 KB Output is correct
64 Correct 793 ms 30800 KB Output is correct
65 Correct 766 ms 30956 KB Output is correct
66 Correct 774 ms 30800 KB Output is correct
67 Correct 0 ms 344 KB Output is correct
68 Correct 2 ms 852 KB Output is correct
69 Correct 3 ms 604 KB Output is correct
70 Correct 3 ms 680 KB Output is correct
71 Correct 3 ms 604 KB Output is correct
72 Correct 3 ms 604 KB Output is correct
73 Correct 3 ms 604 KB Output is correct
74 Correct 3 ms 640 KB Output is correct
75 Correct 3 ms 604 KB Output is correct
76 Correct 3 ms 604 KB Output is correct
77 Correct 3 ms 604 KB Output is correct
78 Correct 3 ms 604 KB Output is correct
79 Correct 3 ms 856 KB Output is correct
80 Correct 3 ms 736 KB Output is correct
81 Correct 0 ms 348 KB Output is correct
82 Correct 3 ms 604 KB Output is correct
83 Correct 3 ms 600 KB Output is correct
84 Correct 3 ms 604 KB Output is correct
85 Correct 3 ms 856 KB Output is correct
86 Correct 3 ms 604 KB Output is correct
87 Correct 3 ms 604 KB Output is correct
88 Correct 3 ms 604 KB Output is correct
89 Correct 0 ms 452 KB Output is correct
90 Correct 3 ms 556 KB Output is correct
91 Correct 3 ms 604 KB Output is correct
92 Correct 3 ms 600 KB Output is correct
93 Correct 3 ms 604 KB Output is correct
94 Correct 3 ms 768 KB Output is correct
95 Correct 3 ms 604 KB Output is correct
96 Correct 3 ms 604 KB Output is correct
97 Correct 3 ms 788 KB Output is correct
98 Correct 3 ms 564 KB Output is correct
99 Correct 3 ms 604 KB Output is correct
100 Correct 3 ms 556 KB Output is correct
101 Correct 3 ms 604 KB Output is correct
102 Correct 3 ms 724 KB Output is correct
103 Correct 0 ms 344 KB Output is correct
104 Correct 3 ms 556 KB Output is correct
105 Correct 3 ms 564 KB Output is correct
106 Correct 3 ms 604 KB Output is correct
107 Correct 3 ms 604 KB Output is correct
108 Correct 3 ms 604 KB Output is correct
109 Correct 3 ms 604 KB Output is correct
110 Correct 3 ms 604 KB Output is correct
111 Correct 0 ms 348 KB Output is correct
112 Correct 965 ms 32872 KB Output is correct
113 Correct 950 ms 32836 KB Output is correct
114 Correct 915 ms 32848 KB Output is correct
115 Correct 896 ms 32852 KB Output is correct
116 Correct 922 ms 32868 KB Output is correct
117 Correct 861 ms 32872 KB Output is correct
118 Correct 911 ms 32848 KB Output is correct
119 Correct 952 ms 32852 KB Output is correct
120 Correct 907 ms 32848 KB Output is correct
121 Correct 908 ms 32776 KB Output is correct
122 Correct 901 ms 32740 KB Output is correct
123 Correct 947 ms 32844 KB Output is correct
124 Correct 930 ms 32812 KB Output is correct
125 Correct 1 ms 344 KB Output is correct
126 Correct 929 ms 32764 KB Output is correct
127 Correct 944 ms 32772 KB Output is correct
128 Correct 991 ms 32696 KB Output is correct
129 Correct 942 ms 32712 KB Output is correct
130 Correct 968 ms 32908 KB Output is correct
131 Correct 911 ms 32848 KB Output is correct
132 Correct 982 ms 32848 KB Output is correct
133 Correct 1 ms 348 KB Output is correct
134 Execution timed out 1002 ms 33692 KB Time limit exceeded
135 Halted 0 ms 0 KB -