Submission #1043143

# Submission time Handle Problem Language Result Execution time Memory
1043143 2024-08-04T02:43:44 Z Whisper Cryptography (NOI20_crypto) C++17
100 / 100
100 ms 42436 KB
#include <bits/stdc++.h>

using namespace std;
using ll = long long;

#define int long long
#define FOR(i, a, b) for (int i = (a); i <= (b); i++)
#define FORD(i, a, b) for (int i = (b); i >= (a); i --)
#define REP(i, a) for (int i = 0; i < (a); ++i)
#define REPD(i, a) for (int i = (a) - 1; i >= 0; --i)

#define MASK(i) (1LL << (i))
#define BIT(x, i) (((x) >> (i)) & 1)


constexpr ll LINF = (1ll << 60);
constexpr int INF = (1ll << 30);
constexpr int Mod = 1e9 + 7;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

/*
    Phu Trong from Nguyen Tat Thanh High School for gifted student
*/

template <class X, class Y>
    bool minimize(X &x, const Y &y){
        X eps = 1e-9;
        if (x > y + eps) {x = y; return 1;}
        return 0;
    }

template <class X, class Y>
    bool maximize(X &x, const Y &y){
        X eps = 1e-9;
        if (x + eps < y) {x = y; return 1;}
        return 0;
    }
#define MAX             300005
int nArr;

int A[MAX];

vector<int> comp;

int find(int x){
    return lower_bound(comp.begin(), comp.end(), x) - comp.begin() + 1;
}


int fac[MAX];

struct FenwickTree{
    vector<int> F;
    int n;
    FenwickTree(int _n = 0){
        init(n);
    }
    void init(int _n = 0){
        F.clear();
        this -> n = _n;
        F.resize(n + 5);
    }
    int low_bit(int p){
        return p & (-p);
    }
    void upd(int p){
        for (; p <= n; p += low_bit(p)) F[p] ++;
    }
    int query(int p){
        int res = 0;
        for (; p > 0; p -= low_bit(p)) res += F[p];
        return res;
    }
};

int mul(int x, int y){
    return 1LL * x * y % Mod;
}
void add(int &x, int y){
    x += y;
    if (x >= Mod) x %= Mod;
}

void process(void){
    cin >> nArr;
    for (int i = 1; i <= nArr; ++i) {
        cin >> A[i];
        comp.push_back(A[i]);
    }
    sort(comp.begin(), comp.end());
    comp.resize(unique(comp.begin(), comp.end()) - comp.begin());

    fac[0] = 1;
    for (int i = 1; i <= nArr; ++i) fac[i] = fac[i - 1] * i % Mod;

    int ans = 0;
    FenwickTree ft(nArr);
    for (int i = 1; i <= nArr; ++i){
        A[i] = find(A[i]);
        int val = mul(A[i] - 1 - ft.query(A[i]), fac[nArr - i]);
        add(ans, val);
        ft.upd(A[i]);
    }
    add(ans, 1);
    cout << ans;
}
signed main(){
    #define name "Whisper"
    cin.tie(nullptr) -> sync_with_stdio(false);
    //freopen(name".inp", "r", stdin);
    //freopen(name".out", "w", stdout);
    process();
    return (0 ^ 0);
}




Compilation message

Crypto.cpp: In function 'void process()':
Crypto.cpp:56:13: warning: 'ft.FenwickTree::n' may be used uninitialized in this function [-Wmaybe-uninitialized]
   56 |         init(n);
      |         ~~~~^~~
Crypto.cpp:56:13: warning: 'ft.FenwickTree::n' may be used uninitialized in this function [-Wmaybe-uninitialized]
# Verdict Execution time Memory Grader output
1 Correct 4 ms 35416 KB Output is correct
2 Correct 4 ms 35420 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 35416 KB Output is correct
2 Correct 4 ms 35420 KB Output is correct
3 Correct 4 ms 35420 KB Output is correct
4 Correct 3 ms 35420 KB Output is correct
5 Correct 4 ms 35420 KB Output is correct
6 Correct 4 ms 35420 KB Output is correct
7 Correct 5 ms 35540 KB Output is correct
8 Correct 4 ms 35420 KB Output is correct
9 Correct 4 ms 35496 KB Output is correct
10 Correct 4 ms 35420 KB Output is correct
11 Correct 5 ms 35420 KB Output is correct
12 Correct 4 ms 35420 KB Output is correct
13 Correct 4 ms 35420 KB Output is correct
14 Correct 4 ms 35432 KB Output is correct
15 Correct 4 ms 35372 KB Output is correct
16 Correct 4 ms 35396 KB Output is correct
17 Correct 4 ms 35420 KB Output is correct
18 Correct 4 ms 35420 KB Output is correct
19 Correct 4 ms 35512 KB Output is correct
20 Correct 4 ms 35432 KB Output is correct
21 Correct 5 ms 35420 KB Output is correct
22 Correct 3 ms 35436 KB Output is correct
23 Correct 4 ms 35420 KB Output is correct
24 Correct 4 ms 35420 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 35416 KB Output is correct
2 Correct 46 ms 40652 KB Output is correct
3 Correct 53 ms 42240 KB Output is correct
4 Correct 46 ms 40612 KB Output is correct
5 Correct 48 ms 40820 KB Output is correct
6 Correct 48 ms 40512 KB Output is correct
7 Correct 47 ms 41424 KB Output is correct
8 Correct 44 ms 40656 KB Output is correct
9 Correct 47 ms 41156 KB Output is correct
10 Correct 45 ms 41680 KB Output is correct
11 Correct 45 ms 41240 KB Output is correct
12 Correct 50 ms 40916 KB Output is correct
13 Correct 47 ms 41160 KB Output is correct
14 Correct 50 ms 41424 KB Output is correct
15 Correct 48 ms 41924 KB Output is correct
16 Correct 56 ms 42192 KB Output is correct
17 Correct 46 ms 40656 KB Output is correct
18 Correct 52 ms 40656 KB Output is correct
19 Correct 53 ms 41168 KB Output is correct
20 Correct 51 ms 41156 KB Output is correct
21 Correct 47 ms 42180 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 35420 KB Output is correct
2 Correct 41 ms 41704 KB Output is correct
3 Correct 43 ms 40844 KB Output is correct
4 Correct 44 ms 41288 KB Output is correct
5 Correct 45 ms 42172 KB Output is correct
6 Correct 42 ms 41672 KB Output is correct
7 Correct 44 ms 42112 KB Output is correct
8 Correct 44 ms 41680 KB Output is correct
9 Correct 43 ms 40648 KB Output is correct
10 Correct 45 ms 42324 KB Output is correct
11 Correct 45 ms 41416 KB Output is correct
12 Correct 41 ms 41168 KB Output is correct
13 Correct 42 ms 42188 KB Output is correct
14 Correct 41 ms 40500 KB Output is correct
15 Correct 42 ms 41680 KB Output is correct
16 Correct 41 ms 40656 KB Output is correct
17 Correct 44 ms 41920 KB Output is correct
18 Correct 43 ms 41420 KB Output is correct
19 Correct 41 ms 41160 KB Output is correct
20 Correct 45 ms 42180 KB Output is correct
21 Correct 41 ms 40900 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 35420 KB Output is correct
2 Correct 4 ms 35604 KB Output is correct
3 Correct 5 ms 35420 KB Output is correct
4 Correct 4 ms 35676 KB Output is correct
5 Correct 5 ms 35676 KB Output is correct
6 Correct 5 ms 35676 KB Output is correct
7 Correct 5 ms 35676 KB Output is correct
8 Correct 4 ms 35676 KB Output is correct
9 Correct 5 ms 35676 KB Output is correct
10 Correct 5 ms 35676 KB Output is correct
11 Correct 4 ms 35420 KB Output is correct
12 Correct 4 ms 35448 KB Output is correct
13 Correct 4 ms 35676 KB Output is correct
14 Correct 5 ms 35420 KB Output is correct
15 Correct 4 ms 35420 KB Output is correct
16 Correct 4 ms 35676 KB Output is correct
17 Correct 4 ms 35676 KB Output is correct
18 Correct 4 ms 35420 KB Output is correct
19 Correct 4 ms 35676 KB Output is correct
20 Correct 5 ms 35676 KB Output is correct
21 Correct 5 ms 35420 KB Output is correct
22 Correct 4 ms 35464 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 35416 KB Output is correct
2 Correct 4 ms 35420 KB Output is correct
3 Correct 4 ms 35420 KB Output is correct
4 Correct 3 ms 35420 KB Output is correct
5 Correct 4 ms 35420 KB Output is correct
6 Correct 4 ms 35420 KB Output is correct
7 Correct 5 ms 35540 KB Output is correct
8 Correct 4 ms 35420 KB Output is correct
9 Correct 4 ms 35496 KB Output is correct
10 Correct 4 ms 35420 KB Output is correct
11 Correct 5 ms 35420 KB Output is correct
12 Correct 4 ms 35420 KB Output is correct
13 Correct 4 ms 35420 KB Output is correct
14 Correct 4 ms 35432 KB Output is correct
15 Correct 4 ms 35372 KB Output is correct
16 Correct 4 ms 35396 KB Output is correct
17 Correct 4 ms 35420 KB Output is correct
18 Correct 4 ms 35420 KB Output is correct
19 Correct 4 ms 35512 KB Output is correct
20 Correct 4 ms 35432 KB Output is correct
21 Correct 5 ms 35420 KB Output is correct
22 Correct 3 ms 35436 KB Output is correct
23 Correct 4 ms 35420 KB Output is correct
24 Correct 4 ms 35420 KB Output is correct
25 Correct 4 ms 35420 KB Output is correct
26 Correct 4 ms 35604 KB Output is correct
27 Correct 5 ms 35420 KB Output is correct
28 Correct 4 ms 35676 KB Output is correct
29 Correct 5 ms 35676 KB Output is correct
30 Correct 5 ms 35676 KB Output is correct
31 Correct 5 ms 35676 KB Output is correct
32 Correct 4 ms 35676 KB Output is correct
33 Correct 5 ms 35676 KB Output is correct
34 Correct 5 ms 35676 KB Output is correct
35 Correct 4 ms 35420 KB Output is correct
36 Correct 4 ms 35448 KB Output is correct
37 Correct 4 ms 35676 KB Output is correct
38 Correct 5 ms 35420 KB Output is correct
39 Correct 4 ms 35420 KB Output is correct
40 Correct 4 ms 35676 KB Output is correct
41 Correct 4 ms 35676 KB Output is correct
42 Correct 4 ms 35420 KB Output is correct
43 Correct 4 ms 35676 KB Output is correct
44 Correct 5 ms 35676 KB Output is correct
45 Correct 5 ms 35420 KB Output is correct
46 Correct 4 ms 35464 KB Output is correct
47 Correct 4 ms 35420 KB Output is correct
48 Correct 4 ms 35676 KB Output is correct
49 Correct 4 ms 35676 KB Output is correct
50 Correct 4 ms 35676 KB Output is correct
51 Correct 5 ms 35420 KB Output is correct
52 Correct 4 ms 35528 KB Output is correct
53 Correct 4 ms 35676 KB Output is correct
54 Correct 5 ms 35420 KB Output is correct
55 Correct 5 ms 35676 KB Output is correct
56 Correct 4 ms 35676 KB Output is correct
57 Correct 5 ms 35676 KB Output is correct
58 Correct 5 ms 35672 KB Output is correct
59 Correct 4 ms 35672 KB Output is correct
60 Correct 4 ms 35636 KB Output is correct
61 Correct 4 ms 35420 KB Output is correct
62 Correct 4 ms 35672 KB Output is correct
63 Correct 4 ms 35676 KB Output is correct
64 Correct 5 ms 35676 KB Output is correct
65 Correct 4 ms 35676 KB Output is correct
66 Correct 5 ms 35676 KB Output is correct
67 Correct 5 ms 35552 KB Output is correct
68 Correct 5 ms 35504 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 35420 KB Output is correct
2 Correct 41 ms 41704 KB Output is correct
3 Correct 43 ms 40844 KB Output is correct
4 Correct 44 ms 41288 KB Output is correct
5 Correct 45 ms 42172 KB Output is correct
6 Correct 42 ms 41672 KB Output is correct
7 Correct 44 ms 42112 KB Output is correct
8 Correct 44 ms 41680 KB Output is correct
9 Correct 43 ms 40648 KB Output is correct
10 Correct 45 ms 42324 KB Output is correct
11 Correct 45 ms 41416 KB Output is correct
12 Correct 41 ms 41168 KB Output is correct
13 Correct 42 ms 42188 KB Output is correct
14 Correct 41 ms 40500 KB Output is correct
15 Correct 42 ms 41680 KB Output is correct
16 Correct 41 ms 40656 KB Output is correct
17 Correct 44 ms 41920 KB Output is correct
18 Correct 43 ms 41420 KB Output is correct
19 Correct 41 ms 41160 KB Output is correct
20 Correct 45 ms 42180 KB Output is correct
21 Correct 41 ms 40900 KB Output is correct
22 Correct 4 ms 35420 KB Output is correct
23 Correct 4 ms 35604 KB Output is correct
24 Correct 5 ms 35420 KB Output is correct
25 Correct 4 ms 35676 KB Output is correct
26 Correct 5 ms 35676 KB Output is correct
27 Correct 5 ms 35676 KB Output is correct
28 Correct 5 ms 35676 KB Output is correct
29 Correct 4 ms 35676 KB Output is correct
30 Correct 5 ms 35676 KB Output is correct
31 Correct 5 ms 35676 KB Output is correct
32 Correct 4 ms 35420 KB Output is correct
33 Correct 4 ms 35448 KB Output is correct
34 Correct 4 ms 35676 KB Output is correct
35 Correct 5 ms 35420 KB Output is correct
36 Correct 4 ms 35420 KB Output is correct
37 Correct 4 ms 35676 KB Output is correct
38 Correct 4 ms 35676 KB Output is correct
39 Correct 4 ms 35420 KB Output is correct
40 Correct 4 ms 35676 KB Output is correct
41 Correct 5 ms 35676 KB Output is correct
42 Correct 5 ms 35420 KB Output is correct
43 Correct 4 ms 35464 KB Output is correct
44 Correct 5 ms 35420 KB Output is correct
45 Correct 83 ms 40968 KB Output is correct
46 Correct 89 ms 41740 KB Output is correct
47 Correct 84 ms 42212 KB Output is correct
48 Correct 85 ms 40952 KB Output is correct
49 Correct 80 ms 40496 KB Output is correct
50 Correct 85 ms 42040 KB Output is correct
51 Correct 81 ms 40636 KB Output is correct
52 Correct 84 ms 40700 KB Output is correct
53 Correct 84 ms 40900 KB Output is correct
54 Correct 87 ms 41384 KB Output is correct
55 Correct 85 ms 41580 KB Output is correct
56 Correct 89 ms 41920 KB Output is correct
57 Correct 86 ms 41896 KB Output is correct
58 Correct 4 ms 35416 KB Output is correct
59 Correct 86 ms 40820 KB Output is correct
60 Correct 83 ms 42256 KB Output is correct
61 Correct 84 ms 41672 KB Output is correct
62 Correct 97 ms 41152 KB Output is correct
63 Correct 97 ms 41936 KB Output is correct
64 Correct 100 ms 41920 KB Output is correct
65 Correct 83 ms 40896 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 35416 KB Output is correct
2 Correct 4 ms 35420 KB Output is correct
3 Correct 4 ms 35420 KB Output is correct
4 Correct 3 ms 35420 KB Output is correct
5 Correct 4 ms 35420 KB Output is correct
6 Correct 4 ms 35420 KB Output is correct
7 Correct 5 ms 35540 KB Output is correct
8 Correct 4 ms 35420 KB Output is correct
9 Correct 4 ms 35496 KB Output is correct
10 Correct 4 ms 35420 KB Output is correct
11 Correct 5 ms 35420 KB Output is correct
12 Correct 4 ms 35420 KB Output is correct
13 Correct 4 ms 35420 KB Output is correct
14 Correct 4 ms 35432 KB Output is correct
15 Correct 4 ms 35372 KB Output is correct
16 Correct 4 ms 35396 KB Output is correct
17 Correct 4 ms 35420 KB Output is correct
18 Correct 4 ms 35420 KB Output is correct
19 Correct 4 ms 35512 KB Output is correct
20 Correct 4 ms 35432 KB Output is correct
21 Correct 5 ms 35420 KB Output is correct
22 Correct 3 ms 35436 KB Output is correct
23 Correct 4 ms 35420 KB Output is correct
24 Correct 4 ms 35420 KB Output is correct
25 Correct 4 ms 35416 KB Output is correct
26 Correct 46 ms 40652 KB Output is correct
27 Correct 53 ms 42240 KB Output is correct
28 Correct 46 ms 40612 KB Output is correct
29 Correct 48 ms 40820 KB Output is correct
30 Correct 48 ms 40512 KB Output is correct
31 Correct 47 ms 41424 KB Output is correct
32 Correct 44 ms 40656 KB Output is correct
33 Correct 47 ms 41156 KB Output is correct
34 Correct 45 ms 41680 KB Output is correct
35 Correct 45 ms 41240 KB Output is correct
36 Correct 50 ms 40916 KB Output is correct
37 Correct 47 ms 41160 KB Output is correct
38 Correct 50 ms 41424 KB Output is correct
39 Correct 48 ms 41924 KB Output is correct
40 Correct 56 ms 42192 KB Output is correct
41 Correct 46 ms 40656 KB Output is correct
42 Correct 52 ms 40656 KB Output is correct
43 Correct 53 ms 41168 KB Output is correct
44 Correct 51 ms 41156 KB Output is correct
45 Correct 47 ms 42180 KB Output is correct
46 Correct 4 ms 35420 KB Output is correct
47 Correct 41 ms 41704 KB Output is correct
48 Correct 43 ms 40844 KB Output is correct
49 Correct 44 ms 41288 KB Output is correct
50 Correct 45 ms 42172 KB Output is correct
51 Correct 42 ms 41672 KB Output is correct
52 Correct 44 ms 42112 KB Output is correct
53 Correct 44 ms 41680 KB Output is correct
54 Correct 43 ms 40648 KB Output is correct
55 Correct 45 ms 42324 KB Output is correct
56 Correct 45 ms 41416 KB Output is correct
57 Correct 41 ms 41168 KB Output is correct
58 Correct 42 ms 42188 KB Output is correct
59 Correct 41 ms 40500 KB Output is correct
60 Correct 42 ms 41680 KB Output is correct
61 Correct 41 ms 40656 KB Output is correct
62 Correct 44 ms 41920 KB Output is correct
63 Correct 43 ms 41420 KB Output is correct
64 Correct 41 ms 41160 KB Output is correct
65 Correct 45 ms 42180 KB Output is correct
66 Correct 41 ms 40900 KB Output is correct
67 Correct 4 ms 35420 KB Output is correct
68 Correct 4 ms 35604 KB Output is correct
69 Correct 5 ms 35420 KB Output is correct
70 Correct 4 ms 35676 KB Output is correct
71 Correct 5 ms 35676 KB Output is correct
72 Correct 5 ms 35676 KB Output is correct
73 Correct 5 ms 35676 KB Output is correct
74 Correct 4 ms 35676 KB Output is correct
75 Correct 5 ms 35676 KB Output is correct
76 Correct 5 ms 35676 KB Output is correct
77 Correct 4 ms 35420 KB Output is correct
78 Correct 4 ms 35448 KB Output is correct
79 Correct 4 ms 35676 KB Output is correct
80 Correct 5 ms 35420 KB Output is correct
81 Correct 4 ms 35420 KB Output is correct
82 Correct 4 ms 35676 KB Output is correct
83 Correct 4 ms 35676 KB Output is correct
84 Correct 4 ms 35420 KB Output is correct
85 Correct 4 ms 35676 KB Output is correct
86 Correct 5 ms 35676 KB Output is correct
87 Correct 5 ms 35420 KB Output is correct
88 Correct 4 ms 35464 KB Output is correct
89 Correct 4 ms 35420 KB Output is correct
90 Correct 4 ms 35676 KB Output is correct
91 Correct 4 ms 35676 KB Output is correct
92 Correct 4 ms 35676 KB Output is correct
93 Correct 5 ms 35420 KB Output is correct
94 Correct 4 ms 35528 KB Output is correct
95 Correct 4 ms 35676 KB Output is correct
96 Correct 5 ms 35420 KB Output is correct
97 Correct 5 ms 35676 KB Output is correct
98 Correct 4 ms 35676 KB Output is correct
99 Correct 5 ms 35676 KB Output is correct
100 Correct 5 ms 35672 KB Output is correct
101 Correct 4 ms 35672 KB Output is correct
102 Correct 4 ms 35636 KB Output is correct
103 Correct 4 ms 35420 KB Output is correct
104 Correct 4 ms 35672 KB Output is correct
105 Correct 4 ms 35676 KB Output is correct
106 Correct 5 ms 35676 KB Output is correct
107 Correct 4 ms 35676 KB Output is correct
108 Correct 5 ms 35676 KB Output is correct
109 Correct 5 ms 35552 KB Output is correct
110 Correct 5 ms 35504 KB Output is correct
111 Correct 5 ms 35420 KB Output is correct
112 Correct 83 ms 40968 KB Output is correct
113 Correct 89 ms 41740 KB Output is correct
114 Correct 84 ms 42212 KB Output is correct
115 Correct 85 ms 40952 KB Output is correct
116 Correct 80 ms 40496 KB Output is correct
117 Correct 85 ms 42040 KB Output is correct
118 Correct 81 ms 40636 KB Output is correct
119 Correct 84 ms 40700 KB Output is correct
120 Correct 84 ms 40900 KB Output is correct
121 Correct 87 ms 41384 KB Output is correct
122 Correct 85 ms 41580 KB Output is correct
123 Correct 89 ms 41920 KB Output is correct
124 Correct 86 ms 41896 KB Output is correct
125 Correct 4 ms 35416 KB Output is correct
126 Correct 86 ms 40820 KB Output is correct
127 Correct 83 ms 42256 KB Output is correct
128 Correct 84 ms 41672 KB Output is correct
129 Correct 97 ms 41152 KB Output is correct
130 Correct 97 ms 41936 KB Output is correct
131 Correct 100 ms 41920 KB Output is correct
132 Correct 83 ms 40896 KB Output is correct
133 Correct 4 ms 35420 KB Output is correct
134 Correct 85 ms 41496 KB Output is correct
135 Correct 86 ms 40896 KB Output is correct
136 Correct 88 ms 42044 KB Output is correct
137 Correct 88 ms 40636 KB Output is correct
138 Correct 91 ms 42436 KB Output is correct
139 Correct 90 ms 40900 KB Output is correct
140 Correct 90 ms 41664 KB Output is correct
141 Correct 87 ms 41920 KB Output is correct
142 Correct 85 ms 40648 KB Output is correct
143 Correct 88 ms 41160 KB Output is correct
144 Correct 87 ms 40900 KB Output is correct
145 Correct 86 ms 41412 KB Output is correct
146 Correct 85 ms 40656 KB Output is correct
147 Correct 4 ms 35416 KB Output is correct
148 Correct 87 ms 41448 KB Output is correct
149 Correct 91 ms 40892 KB Output is correct
150 Correct 91 ms 42176 KB Output is correct
151 Correct 90 ms 42416 KB Output is correct
152 Correct 87 ms 40640 KB Output is correct
153 Correct 85 ms 40644 KB Output is correct
154 Correct 88 ms 41192 KB Output is correct