답안 #1043142

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1043142 2024-08-04T02:41:10 Z vjudge1 Cryptography (NOI20_crypto) C++17
100 / 100
99 ms 45160 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]
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 35416 KB Output is correct
2 Correct 3 ms 35420 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 35416 KB Output is correct
2 Correct 3 ms 35420 KB Output is correct
3 Correct 4 ms 35416 KB Output is correct
4 Correct 4 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 4 ms 35420 KB Output is correct
8 Correct 3 ms 35420 KB Output is correct
9 Correct 4 ms 35420 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 35420 KB Output is correct
15 Correct 4 ms 35420 KB Output is correct
16 Correct 5 ms 35460 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 35420 KB Output is correct
20 Correct 5 ms 35420 KB Output is correct
21 Correct 4 ms 35416 KB Output is correct
22 Correct 4 ms 35420 KB Output is correct
23 Correct 4 ms 35508 KB Output is correct
24 Correct 4 ms 35420 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 35420 KB Output is correct
2 Correct 49 ms 43664 KB Output is correct
3 Correct 47 ms 45008 KB Output is correct
4 Correct 48 ms 44996 KB Output is correct
5 Correct 49 ms 44752 KB Output is correct
6 Correct 49 ms 44780 KB Output is correct
7 Correct 45 ms 44992 KB Output is correct
8 Correct 46 ms 43460 KB Output is correct
9 Correct 47 ms 43508 KB Output is correct
10 Correct 46 ms 43464 KB Output is correct
11 Correct 46 ms 43924 KB Output is correct
12 Correct 48 ms 43972 KB Output is correct
13 Correct 47 ms 44736 KB Output is correct
14 Correct 50 ms 44740 KB Output is correct
15 Correct 52 ms 45004 KB Output is correct
16 Correct 47 ms 43840 KB Output is correct
17 Correct 45 ms 43704 KB Output is correct
18 Correct 47 ms 43472 KB Output is correct
19 Correct 48 ms 44496 KB Output is correct
20 Correct 57 ms 44740 KB Output is correct
21 Correct 48 ms 43576 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 35420 KB Output is correct
2 Correct 45 ms 43992 KB Output is correct
3 Correct 42 ms 44232 KB Output is correct
4 Correct 46 ms 43972 KB Output is correct
5 Correct 44 ms 44376 KB Output is correct
6 Correct 41 ms 42960 KB Output is correct
7 Correct 42 ms 43716 KB Output is correct
8 Correct 44 ms 42980 KB Output is correct
9 Correct 43 ms 43724 KB Output is correct
10 Correct 42 ms 42444 KB Output is correct
11 Correct 43 ms 42448 KB Output is correct
12 Correct 43 ms 42436 KB Output is correct
13 Correct 49 ms 43524 KB Output is correct
14 Correct 41 ms 43376 KB Output is correct
15 Correct 43 ms 42952 KB Output is correct
16 Correct 48 ms 43972 KB Output is correct
17 Correct 42 ms 43980 KB Output is correct
18 Correct 43 ms 44088 KB Output is correct
19 Correct 42 ms 43976 KB Output is correct
20 Correct 42 ms 43160 KB Output is correct
21 Correct 41 ms 43972 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 35416 KB Output is correct
2 Correct 4 ms 35672 KB Output is correct
3 Correct 4 ms 35676 KB Output is correct
4 Correct 4 ms 35560 KB Output is correct
5 Correct 4 ms 35560 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 4 ms 35676 KB Output is correct
10 Correct 5 ms 35928 KB Output is correct
11 Correct 4 ms 35676 KB Output is correct
12 Correct 6 ms 35676 KB Output is correct
13 Correct 5 ms 35676 KB Output is correct
14 Correct 5 ms 35676 KB Output is correct
15 Correct 4 ms 35420 KB Output is correct
16 Correct 4 ms 35492 KB Output is correct
17 Correct 4 ms 35612 KB Output is correct
18 Correct 4 ms 35676 KB Output is correct
19 Correct 4 ms 35676 KB Output is correct
20 Correct 5 ms 35676 KB Output is correct
21 Correct 4 ms 35676 KB Output is correct
22 Correct 4 ms 35676 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 35416 KB Output is correct
2 Correct 3 ms 35420 KB Output is correct
3 Correct 4 ms 35416 KB Output is correct
4 Correct 4 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 4 ms 35420 KB Output is correct
8 Correct 3 ms 35420 KB Output is correct
9 Correct 4 ms 35420 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 35420 KB Output is correct
15 Correct 4 ms 35420 KB Output is correct
16 Correct 5 ms 35460 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 35420 KB Output is correct
20 Correct 5 ms 35420 KB Output is correct
21 Correct 4 ms 35416 KB Output is correct
22 Correct 4 ms 35420 KB Output is correct
23 Correct 4 ms 35508 KB Output is correct
24 Correct 4 ms 35420 KB Output is correct
25 Correct 4 ms 35416 KB Output is correct
26 Correct 4 ms 35672 KB Output is correct
27 Correct 4 ms 35676 KB Output is correct
28 Correct 4 ms 35560 KB Output is correct
29 Correct 4 ms 35560 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 4 ms 35676 KB Output is correct
34 Correct 5 ms 35928 KB Output is correct
35 Correct 4 ms 35676 KB Output is correct
36 Correct 6 ms 35676 KB Output is correct
37 Correct 5 ms 35676 KB Output is correct
38 Correct 5 ms 35676 KB Output is correct
39 Correct 4 ms 35420 KB Output is correct
40 Correct 4 ms 35492 KB Output is correct
41 Correct 4 ms 35612 KB Output is correct
42 Correct 4 ms 35676 KB Output is correct
43 Correct 4 ms 35676 KB Output is correct
44 Correct 5 ms 35676 KB Output is correct
45 Correct 4 ms 35676 KB Output is correct
46 Correct 4 ms 35676 KB Output is correct
47 Correct 3 ms 35420 KB Output is correct
48 Correct 5 ms 35672 KB Output is correct
49 Correct 4 ms 35676 KB Output is correct
50 Correct 4 ms 35676 KB Output is correct
51 Correct 4 ms 35676 KB Output is correct
52 Correct 5 ms 35676 KB Output is correct
53 Correct 4 ms 35592 KB Output is correct
54 Correct 5 ms 35676 KB Output is correct
55 Correct 4 ms 35676 KB Output is correct
56 Correct 5 ms 35492 KB Output is correct
57 Correct 5 ms 35676 KB Output is correct
58 Correct 4 ms 35636 KB Output is correct
59 Correct 4 ms 35676 KB Output is correct
60 Correct 5 ms 35612 KB Output is correct
61 Correct 4 ms 35420 KB Output is correct
62 Correct 5 ms 35676 KB Output is correct
63 Correct 5 ms 35676 KB Output is correct
64 Correct 4 ms 35672 KB Output is correct
65 Correct 5 ms 35676 KB Output is correct
66 Correct 4 ms 35676 KB Output is correct
67 Correct 4 ms 35676 KB Output is correct
68 Correct 4 ms 35676 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 35420 KB Output is correct
2 Correct 45 ms 43992 KB Output is correct
3 Correct 42 ms 44232 KB Output is correct
4 Correct 46 ms 43972 KB Output is correct
5 Correct 44 ms 44376 KB Output is correct
6 Correct 41 ms 42960 KB Output is correct
7 Correct 42 ms 43716 KB Output is correct
8 Correct 44 ms 42980 KB Output is correct
9 Correct 43 ms 43724 KB Output is correct
10 Correct 42 ms 42444 KB Output is correct
11 Correct 43 ms 42448 KB Output is correct
12 Correct 43 ms 42436 KB Output is correct
13 Correct 49 ms 43524 KB Output is correct
14 Correct 41 ms 43376 KB Output is correct
15 Correct 43 ms 42952 KB Output is correct
16 Correct 48 ms 43972 KB Output is correct
17 Correct 42 ms 43980 KB Output is correct
18 Correct 43 ms 44088 KB Output is correct
19 Correct 42 ms 43976 KB Output is correct
20 Correct 42 ms 43160 KB Output is correct
21 Correct 41 ms 43972 KB Output is correct
22 Correct 4 ms 35416 KB Output is correct
23 Correct 4 ms 35672 KB Output is correct
24 Correct 4 ms 35676 KB Output is correct
25 Correct 4 ms 35560 KB Output is correct
26 Correct 4 ms 35560 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 4 ms 35676 KB Output is correct
31 Correct 5 ms 35928 KB Output is correct
32 Correct 4 ms 35676 KB Output is correct
33 Correct 6 ms 35676 KB Output is correct
34 Correct 5 ms 35676 KB Output is correct
35 Correct 5 ms 35676 KB Output is correct
36 Correct 4 ms 35420 KB Output is correct
37 Correct 4 ms 35492 KB Output is correct
38 Correct 4 ms 35612 KB Output is correct
39 Correct 4 ms 35676 KB Output is correct
40 Correct 4 ms 35676 KB Output is correct
41 Correct 5 ms 35676 KB Output is correct
42 Correct 4 ms 35676 KB Output is correct
43 Correct 4 ms 35676 KB Output is correct
44 Correct 4 ms 35416 KB Output is correct
45 Correct 84 ms 43096 KB Output is correct
46 Correct 82 ms 43456 KB Output is correct
47 Correct 81 ms 43644 KB Output is correct
48 Correct 83 ms 42432 KB Output is correct
49 Correct 83 ms 42944 KB Output is correct
50 Correct 86 ms 43212 KB Output is correct
51 Correct 83 ms 42448 KB Output is correct
52 Correct 84 ms 44228 KB Output is correct
53 Correct 82 ms 43972 KB Output is correct
54 Correct 84 ms 43460 KB Output is correct
55 Correct 89 ms 44164 KB Output is correct
56 Correct 80 ms 42704 KB Output is correct
57 Correct 81 ms 42960 KB Output is correct
58 Correct 4 ms 35416 KB Output is correct
59 Correct 94 ms 42428 KB Output is correct
60 Correct 82 ms 42764 KB Output is correct
61 Correct 91 ms 43460 KB Output is correct
62 Correct 80 ms 43200 KB Output is correct
63 Correct 81 ms 42436 KB Output is correct
64 Correct 90 ms 43456 KB Output is correct
65 Correct 84 ms 43076 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 35416 KB Output is correct
2 Correct 3 ms 35420 KB Output is correct
3 Correct 4 ms 35416 KB Output is correct
4 Correct 4 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 4 ms 35420 KB Output is correct
8 Correct 3 ms 35420 KB Output is correct
9 Correct 4 ms 35420 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 35420 KB Output is correct
15 Correct 4 ms 35420 KB Output is correct
16 Correct 5 ms 35460 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 35420 KB Output is correct
20 Correct 5 ms 35420 KB Output is correct
21 Correct 4 ms 35416 KB Output is correct
22 Correct 4 ms 35420 KB Output is correct
23 Correct 4 ms 35508 KB Output is correct
24 Correct 4 ms 35420 KB Output is correct
25 Correct 4 ms 35420 KB Output is correct
26 Correct 49 ms 43664 KB Output is correct
27 Correct 47 ms 45008 KB Output is correct
28 Correct 48 ms 44996 KB Output is correct
29 Correct 49 ms 44752 KB Output is correct
30 Correct 49 ms 44780 KB Output is correct
31 Correct 45 ms 44992 KB Output is correct
32 Correct 46 ms 43460 KB Output is correct
33 Correct 47 ms 43508 KB Output is correct
34 Correct 46 ms 43464 KB Output is correct
35 Correct 46 ms 43924 KB Output is correct
36 Correct 48 ms 43972 KB Output is correct
37 Correct 47 ms 44736 KB Output is correct
38 Correct 50 ms 44740 KB Output is correct
39 Correct 52 ms 45004 KB Output is correct
40 Correct 47 ms 43840 KB Output is correct
41 Correct 45 ms 43704 KB Output is correct
42 Correct 47 ms 43472 KB Output is correct
43 Correct 48 ms 44496 KB Output is correct
44 Correct 57 ms 44740 KB Output is correct
45 Correct 48 ms 43576 KB Output is correct
46 Correct 4 ms 35420 KB Output is correct
47 Correct 45 ms 43992 KB Output is correct
48 Correct 42 ms 44232 KB Output is correct
49 Correct 46 ms 43972 KB Output is correct
50 Correct 44 ms 44376 KB Output is correct
51 Correct 41 ms 42960 KB Output is correct
52 Correct 42 ms 43716 KB Output is correct
53 Correct 44 ms 42980 KB Output is correct
54 Correct 43 ms 43724 KB Output is correct
55 Correct 42 ms 42444 KB Output is correct
56 Correct 43 ms 42448 KB Output is correct
57 Correct 43 ms 42436 KB Output is correct
58 Correct 49 ms 43524 KB Output is correct
59 Correct 41 ms 43376 KB Output is correct
60 Correct 43 ms 42952 KB Output is correct
61 Correct 48 ms 43972 KB Output is correct
62 Correct 42 ms 43980 KB Output is correct
63 Correct 43 ms 44088 KB Output is correct
64 Correct 42 ms 43976 KB Output is correct
65 Correct 42 ms 43160 KB Output is correct
66 Correct 41 ms 43972 KB Output is correct
67 Correct 4 ms 35416 KB Output is correct
68 Correct 4 ms 35672 KB Output is correct
69 Correct 4 ms 35676 KB Output is correct
70 Correct 4 ms 35560 KB Output is correct
71 Correct 4 ms 35560 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 4 ms 35676 KB Output is correct
76 Correct 5 ms 35928 KB Output is correct
77 Correct 4 ms 35676 KB Output is correct
78 Correct 6 ms 35676 KB Output is correct
79 Correct 5 ms 35676 KB Output is correct
80 Correct 5 ms 35676 KB Output is correct
81 Correct 4 ms 35420 KB Output is correct
82 Correct 4 ms 35492 KB Output is correct
83 Correct 4 ms 35612 KB Output is correct
84 Correct 4 ms 35676 KB Output is correct
85 Correct 4 ms 35676 KB Output is correct
86 Correct 5 ms 35676 KB Output is correct
87 Correct 4 ms 35676 KB Output is correct
88 Correct 4 ms 35676 KB Output is correct
89 Correct 3 ms 35420 KB Output is correct
90 Correct 5 ms 35672 KB Output is correct
91 Correct 4 ms 35676 KB Output is correct
92 Correct 4 ms 35676 KB Output is correct
93 Correct 4 ms 35676 KB Output is correct
94 Correct 5 ms 35676 KB Output is correct
95 Correct 4 ms 35592 KB Output is correct
96 Correct 5 ms 35676 KB Output is correct
97 Correct 4 ms 35676 KB Output is correct
98 Correct 5 ms 35492 KB Output is correct
99 Correct 5 ms 35676 KB Output is correct
100 Correct 4 ms 35636 KB Output is correct
101 Correct 4 ms 35676 KB Output is correct
102 Correct 5 ms 35612 KB Output is correct
103 Correct 4 ms 35420 KB Output is correct
104 Correct 5 ms 35676 KB Output is correct
105 Correct 5 ms 35676 KB Output is correct
106 Correct 4 ms 35672 KB Output is correct
107 Correct 5 ms 35676 KB Output is correct
108 Correct 4 ms 35676 KB Output is correct
109 Correct 4 ms 35676 KB Output is correct
110 Correct 4 ms 35676 KB Output is correct
111 Correct 4 ms 35416 KB Output is correct
112 Correct 84 ms 43096 KB Output is correct
113 Correct 82 ms 43456 KB Output is correct
114 Correct 81 ms 43644 KB Output is correct
115 Correct 83 ms 42432 KB Output is correct
116 Correct 83 ms 42944 KB Output is correct
117 Correct 86 ms 43212 KB Output is correct
118 Correct 83 ms 42448 KB Output is correct
119 Correct 84 ms 44228 KB Output is correct
120 Correct 82 ms 43972 KB Output is correct
121 Correct 84 ms 43460 KB Output is correct
122 Correct 89 ms 44164 KB Output is correct
123 Correct 80 ms 42704 KB Output is correct
124 Correct 81 ms 42960 KB Output is correct
125 Correct 4 ms 35416 KB Output is correct
126 Correct 94 ms 42428 KB Output is correct
127 Correct 82 ms 42764 KB Output is correct
128 Correct 91 ms 43460 KB Output is correct
129 Correct 80 ms 43200 KB Output is correct
130 Correct 81 ms 42436 KB Output is correct
131 Correct 90 ms 43456 KB Output is correct
132 Correct 84 ms 43076 KB Output is correct
133 Correct 5 ms 35416 KB Output is correct
134 Correct 84 ms 43720 KB Output is correct
135 Correct 86 ms 43796 KB Output is correct
136 Correct 87 ms 43452 KB Output is correct
137 Correct 86 ms 43460 KB Output is correct
138 Correct 87 ms 44932 KB Output is correct
139 Correct 87 ms 45148 KB Output is correct
140 Correct 84 ms 43964 KB Output is correct
141 Correct 89 ms 43976 KB Output is correct
142 Correct 92 ms 44224 KB Output is correct
143 Correct 99 ms 44568 KB Output is correct
144 Correct 85 ms 43972 KB Output is correct
145 Correct 85 ms 44752 KB Output is correct
146 Correct 86 ms 45156 KB Output is correct
147 Correct 4 ms 35416 KB Output is correct
148 Correct 86 ms 44744 KB Output is correct
149 Correct 87 ms 44228 KB Output is correct
150 Correct 86 ms 43964 KB Output is correct
151 Correct 90 ms 45160 KB Output is correct
152 Correct 87 ms 44476 KB Output is correct
153 Correct 83 ms 43664 KB Output is correct
154 Correct 84 ms 44632 KB Output is correct