답안 #563043

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
563043 2022-05-16T06:25:34 Z ddy888 Cryptography (NOI20_crypto) C++17
100 / 100
155 ms 10532 KB
#undef _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
void debug_out() {cerr<<endl;}
template <typename Head, typename... Tail>
void debug_out(Head _H, Tail... _T) {cerr<<" "<<to_string(_H);debug_out(_T...);}
#define debug(...) cerr<<"["<<#__VA_ARGS__<<"]:",debug_out(__VA_ARGS__)
#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); 
#define pb push_back
#define fi first
#define si second
typedef pair<int,int> pi;
typedef vector<int> vi;
typedef tuple<int,int,int> ti;  
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const int MAXN = 300010;
const ll MOD = 1e9 + 7;
int n;
int a[MAXN];
vi vals;
ll fac[MAXN];
ll ans;

ll mult(int x, int y) {
    return (x % MOD * y % MOD) % MOD;
}

ll add(int x, int y) {
    return (x % MOD + y % MOD) % MOD;
}

struct FwTree {
    int sz;
    vector<int> fw, fw2;
    void init(int _n) {sz = _n;fw.resize(_n + 10);fw2.resize(_n + 10);}
    void update(int x, int y, int v) { //inclusive
        for (int tx=x; tx <= sz; tx += tx&(-tx)) fw[tx] += v, fw2[tx] -= v*(x-1);
        for (int ty=y+1; ty <= sz; ty += ty&(-ty)) fw[ty] -= v, fw2[ty] += v*y; 
    }
    int sum(int x) {
        int res = 0;
        for (int tx=x; tx; tx -= tx&(-tx)) res += fw[tx]*x + fw2[tx];
        return res;
    }
    int query(int x, int y) {
        return sum(y) - sum(x - 1);
    }
} fw;

int main() {
    fast;   
    cin >> n;
    fac[0] = 1;
    for (int i = 1; i <= n; ++i) {
        cin >> a[i];
        vals.pb(a[i]);
        fac[i] = mult(fac[i - 1], i);
    }
    sort(vals.begin(), vals.end());
    vals.erase(unique(vals.begin(), vals.end()), vals.end());
    for (int i = 1; i <= n; ++i) {
        a[i] = lower_bound(vals.begin(), vals.end(), a[i]) - vals.begin() + 1;
    }
    fw.init(n);
    for (int i = 1; i <= n; ++i) {
        fw.update(a[i], a[i], 1);
        int pos = a[i] - fw.query(1, a[i]);
        ll contribute = mult(pos, fac[n - i]);
        ans = add(ans, contribute);
    }
    ans = add(ans, 1);
    cout << ans;
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 336 KB Output is correct
12 Correct 0 ms 340 KB Output is correct
13 Correct 0 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 0 ms 340 KB Output is correct
17 Correct 0 ms 340 KB Output is correct
18 Correct 1 ms 280 KB Output is correct
19 Correct 0 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 0 ms 340 KB Output is correct
22 Correct 0 ms 340 KB Output is correct
23 Correct 0 ms 212 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 90 ms 10444 KB Output is correct
3 Correct 91 ms 10528 KB Output is correct
4 Correct 89 ms 10308 KB Output is correct
5 Correct 100 ms 10532 KB Output is correct
6 Correct 88 ms 10396 KB Output is correct
7 Correct 89 ms 10304 KB Output is correct
8 Correct 87 ms 10360 KB Output is correct
9 Correct 87 ms 10352 KB Output is correct
10 Correct 94 ms 10308 KB Output is correct
11 Correct 91 ms 10304 KB Output is correct
12 Correct 89 ms 10444 KB Output is correct
13 Correct 90 ms 10304 KB Output is correct
14 Correct 95 ms 10360 KB Output is correct
15 Correct 99 ms 10280 KB Output is correct
16 Correct 92 ms 10364 KB Output is correct
17 Correct 92 ms 10388 KB Output is correct
18 Correct 90 ms 10308 KB Output is correct
19 Correct 88 ms 10316 KB Output is correct
20 Correct 87 ms 10364 KB Output is correct
21 Correct 87 ms 10400 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 85 ms 9456 KB Output is correct
3 Correct 84 ms 9404 KB Output is correct
4 Correct 82 ms 9544 KB Output is correct
5 Correct 82 ms 9448 KB Output is correct
6 Correct 81 ms 9444 KB Output is correct
7 Correct 81 ms 9360 KB Output is correct
8 Correct 87 ms 9552 KB Output is correct
9 Correct 84 ms 9352 KB Output is correct
10 Correct 82 ms 9492 KB Output is correct
11 Correct 80 ms 9440 KB Output is correct
12 Correct 85 ms 9388 KB Output is correct
13 Correct 84 ms 9456 KB Output is correct
14 Correct 91 ms 9400 KB Output is correct
15 Correct 86 ms 9368 KB Output is correct
16 Correct 83 ms 9392 KB Output is correct
17 Correct 84 ms 9448 KB Output is correct
18 Correct 84 ms 9492 KB Output is correct
19 Correct 81 ms 9332 KB Output is correct
20 Correct 100 ms 9452 KB Output is correct
21 Correct 82 ms 9344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 2 ms 356 KB Output is correct
6 Correct 1 ms 352 KB Output is correct
7 Correct 2 ms 348 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 352 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 1 ms 352 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 0 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 424 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 336 KB Output is correct
12 Correct 0 ms 340 KB Output is correct
13 Correct 0 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 0 ms 340 KB Output is correct
17 Correct 0 ms 340 KB Output is correct
18 Correct 1 ms 280 KB Output is correct
19 Correct 0 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 0 ms 340 KB Output is correct
22 Correct 0 ms 340 KB Output is correct
23 Correct 0 ms 212 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 0 ms 340 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 1 ms 340 KB Output is correct
29 Correct 2 ms 356 KB Output is correct
30 Correct 1 ms 352 KB Output is correct
31 Correct 2 ms 348 KB Output is correct
32 Correct 1 ms 340 KB Output is correct
33 Correct 1 ms 352 KB Output is correct
34 Correct 1 ms 348 KB Output is correct
35 Correct 1 ms 352 KB Output is correct
36 Correct 1 ms 348 KB Output is correct
37 Correct 1 ms 340 KB Output is correct
38 Correct 1 ms 340 KB Output is correct
39 Correct 0 ms 340 KB Output is correct
40 Correct 1 ms 340 KB Output is correct
41 Correct 1 ms 340 KB Output is correct
42 Correct 1 ms 340 KB Output is correct
43 Correct 1 ms 340 KB Output is correct
44 Correct 1 ms 424 KB Output is correct
45 Correct 1 ms 340 KB Output is correct
46 Correct 1 ms 348 KB Output is correct
47 Correct 1 ms 212 KB Output is correct
48 Correct 2 ms 340 KB Output is correct
49 Correct 1 ms 340 KB Output is correct
50 Correct 1 ms 340 KB Output is correct
51 Correct 1 ms 340 KB Output is correct
52 Correct 2 ms 340 KB Output is correct
53 Correct 2 ms 340 KB Output is correct
54 Correct 2 ms 400 KB Output is correct
55 Correct 1 ms 340 KB Output is correct
56 Correct 1 ms 388 KB Output is correct
57 Correct 1 ms 340 KB Output is correct
58 Correct 1 ms 340 KB Output is correct
59 Correct 1 ms 340 KB Output is correct
60 Correct 2 ms 356 KB Output is correct
61 Correct 0 ms 340 KB Output is correct
62 Correct 1 ms 340 KB Output is correct
63 Correct 1 ms 352 KB Output is correct
64 Correct 2 ms 340 KB Output is correct
65 Correct 2 ms 340 KB Output is correct
66 Correct 1 ms 340 KB Output is correct
67 Correct 2 ms 340 KB Output is correct
68 Correct 2 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 85 ms 9456 KB Output is correct
3 Correct 84 ms 9404 KB Output is correct
4 Correct 82 ms 9544 KB Output is correct
5 Correct 82 ms 9448 KB Output is correct
6 Correct 81 ms 9444 KB Output is correct
7 Correct 81 ms 9360 KB Output is correct
8 Correct 87 ms 9552 KB Output is correct
9 Correct 84 ms 9352 KB Output is correct
10 Correct 82 ms 9492 KB Output is correct
11 Correct 80 ms 9440 KB Output is correct
12 Correct 85 ms 9388 KB Output is correct
13 Correct 84 ms 9456 KB Output is correct
14 Correct 91 ms 9400 KB Output is correct
15 Correct 86 ms 9368 KB Output is correct
16 Correct 83 ms 9392 KB Output is correct
17 Correct 84 ms 9448 KB Output is correct
18 Correct 84 ms 9492 KB Output is correct
19 Correct 81 ms 9332 KB Output is correct
20 Correct 100 ms 9452 KB Output is correct
21 Correct 82 ms 9344 KB Output is correct
22 Correct 0 ms 340 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 2 ms 356 KB Output is correct
27 Correct 1 ms 352 KB Output is correct
28 Correct 2 ms 348 KB Output is correct
29 Correct 1 ms 340 KB Output is correct
30 Correct 1 ms 352 KB Output is correct
31 Correct 1 ms 348 KB Output is correct
32 Correct 1 ms 352 KB Output is correct
33 Correct 1 ms 348 KB Output is correct
34 Correct 1 ms 340 KB Output is correct
35 Correct 1 ms 340 KB Output is correct
36 Correct 0 ms 340 KB Output is correct
37 Correct 1 ms 340 KB Output is correct
38 Correct 1 ms 340 KB Output is correct
39 Correct 1 ms 340 KB Output is correct
40 Correct 1 ms 340 KB Output is correct
41 Correct 1 ms 424 KB Output is correct
42 Correct 1 ms 340 KB Output is correct
43 Correct 1 ms 348 KB Output is correct
44 Correct 0 ms 340 KB Output is correct
45 Correct 141 ms 9452 KB Output is correct
46 Correct 137 ms 9404 KB Output is correct
47 Correct 138 ms 9388 KB Output is correct
48 Correct 135 ms 9480 KB Output is correct
49 Correct 134 ms 9532 KB Output is correct
50 Correct 143 ms 9408 KB Output is correct
51 Correct 145 ms 9404 KB Output is correct
52 Correct 140 ms 9452 KB Output is correct
53 Correct 134 ms 9444 KB Output is correct
54 Correct 138 ms 9536 KB Output is correct
55 Correct 138 ms 9412 KB Output is correct
56 Correct 139 ms 9532 KB Output is correct
57 Correct 139 ms 9532 KB Output is correct
58 Correct 1 ms 212 KB Output is correct
59 Correct 133 ms 9448 KB Output is correct
60 Correct 135 ms 9404 KB Output is correct
61 Correct 134 ms 9404 KB Output is correct
62 Correct 138 ms 9408 KB Output is correct
63 Correct 135 ms 9364 KB Output is correct
64 Correct 139 ms 9408 KB Output is correct
65 Correct 150 ms 9408 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 336 KB Output is correct
12 Correct 0 ms 340 KB Output is correct
13 Correct 0 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 0 ms 340 KB Output is correct
17 Correct 0 ms 340 KB Output is correct
18 Correct 1 ms 280 KB Output is correct
19 Correct 0 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 0 ms 340 KB Output is correct
22 Correct 0 ms 340 KB Output is correct
23 Correct 0 ms 212 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 90 ms 10444 KB Output is correct
27 Correct 91 ms 10528 KB Output is correct
28 Correct 89 ms 10308 KB Output is correct
29 Correct 100 ms 10532 KB Output is correct
30 Correct 88 ms 10396 KB Output is correct
31 Correct 89 ms 10304 KB Output is correct
32 Correct 87 ms 10360 KB Output is correct
33 Correct 87 ms 10352 KB Output is correct
34 Correct 94 ms 10308 KB Output is correct
35 Correct 91 ms 10304 KB Output is correct
36 Correct 89 ms 10444 KB Output is correct
37 Correct 90 ms 10304 KB Output is correct
38 Correct 95 ms 10360 KB Output is correct
39 Correct 99 ms 10280 KB Output is correct
40 Correct 92 ms 10364 KB Output is correct
41 Correct 92 ms 10388 KB Output is correct
42 Correct 90 ms 10308 KB Output is correct
43 Correct 88 ms 10316 KB Output is correct
44 Correct 87 ms 10364 KB Output is correct
45 Correct 87 ms 10400 KB Output is correct
46 Correct 1 ms 340 KB Output is correct
47 Correct 85 ms 9456 KB Output is correct
48 Correct 84 ms 9404 KB Output is correct
49 Correct 82 ms 9544 KB Output is correct
50 Correct 82 ms 9448 KB Output is correct
51 Correct 81 ms 9444 KB Output is correct
52 Correct 81 ms 9360 KB Output is correct
53 Correct 87 ms 9552 KB Output is correct
54 Correct 84 ms 9352 KB Output is correct
55 Correct 82 ms 9492 KB Output is correct
56 Correct 80 ms 9440 KB Output is correct
57 Correct 85 ms 9388 KB Output is correct
58 Correct 84 ms 9456 KB Output is correct
59 Correct 91 ms 9400 KB Output is correct
60 Correct 86 ms 9368 KB Output is correct
61 Correct 83 ms 9392 KB Output is correct
62 Correct 84 ms 9448 KB Output is correct
63 Correct 84 ms 9492 KB Output is correct
64 Correct 81 ms 9332 KB Output is correct
65 Correct 100 ms 9452 KB Output is correct
66 Correct 82 ms 9344 KB Output is correct
67 Correct 0 ms 340 KB Output is correct
68 Correct 1 ms 340 KB Output is correct
69 Correct 1 ms 340 KB Output is correct
70 Correct 1 ms 340 KB Output is correct
71 Correct 2 ms 356 KB Output is correct
72 Correct 1 ms 352 KB Output is correct
73 Correct 2 ms 348 KB Output is correct
74 Correct 1 ms 340 KB Output is correct
75 Correct 1 ms 352 KB Output is correct
76 Correct 1 ms 348 KB Output is correct
77 Correct 1 ms 352 KB Output is correct
78 Correct 1 ms 348 KB Output is correct
79 Correct 1 ms 340 KB Output is correct
80 Correct 1 ms 340 KB Output is correct
81 Correct 0 ms 340 KB Output is correct
82 Correct 1 ms 340 KB Output is correct
83 Correct 1 ms 340 KB Output is correct
84 Correct 1 ms 340 KB Output is correct
85 Correct 1 ms 340 KB Output is correct
86 Correct 1 ms 424 KB Output is correct
87 Correct 1 ms 340 KB Output is correct
88 Correct 1 ms 348 KB Output is correct
89 Correct 1 ms 212 KB Output is correct
90 Correct 2 ms 340 KB Output is correct
91 Correct 1 ms 340 KB Output is correct
92 Correct 1 ms 340 KB Output is correct
93 Correct 1 ms 340 KB Output is correct
94 Correct 2 ms 340 KB Output is correct
95 Correct 2 ms 340 KB Output is correct
96 Correct 2 ms 400 KB Output is correct
97 Correct 1 ms 340 KB Output is correct
98 Correct 1 ms 388 KB Output is correct
99 Correct 1 ms 340 KB Output is correct
100 Correct 1 ms 340 KB Output is correct
101 Correct 1 ms 340 KB Output is correct
102 Correct 2 ms 356 KB Output is correct
103 Correct 0 ms 340 KB Output is correct
104 Correct 1 ms 340 KB Output is correct
105 Correct 1 ms 352 KB Output is correct
106 Correct 2 ms 340 KB Output is correct
107 Correct 2 ms 340 KB Output is correct
108 Correct 1 ms 340 KB Output is correct
109 Correct 2 ms 340 KB Output is correct
110 Correct 2 ms 340 KB Output is correct
111 Correct 0 ms 340 KB Output is correct
112 Correct 141 ms 9452 KB Output is correct
113 Correct 137 ms 9404 KB Output is correct
114 Correct 138 ms 9388 KB Output is correct
115 Correct 135 ms 9480 KB Output is correct
116 Correct 134 ms 9532 KB Output is correct
117 Correct 143 ms 9408 KB Output is correct
118 Correct 145 ms 9404 KB Output is correct
119 Correct 140 ms 9452 KB Output is correct
120 Correct 134 ms 9444 KB Output is correct
121 Correct 138 ms 9536 KB Output is correct
122 Correct 138 ms 9412 KB Output is correct
123 Correct 139 ms 9532 KB Output is correct
124 Correct 139 ms 9532 KB Output is correct
125 Correct 1 ms 212 KB Output is correct
126 Correct 133 ms 9448 KB Output is correct
127 Correct 135 ms 9404 KB Output is correct
128 Correct 134 ms 9404 KB Output is correct
129 Correct 138 ms 9408 KB Output is correct
130 Correct 135 ms 9364 KB Output is correct
131 Correct 139 ms 9408 KB Output is correct
132 Correct 150 ms 9408 KB Output is correct
133 Correct 1 ms 212 KB Output is correct
134 Correct 149 ms 10408 KB Output is correct
135 Correct 140 ms 10324 KB Output is correct
136 Correct 155 ms 10408 KB Output is correct
137 Correct 138 ms 10312 KB Output is correct
138 Correct 148 ms 10436 KB Output is correct
139 Correct 137 ms 10416 KB Output is correct
140 Correct 141 ms 10352 KB Output is correct
141 Correct 141 ms 10364 KB Output is correct
142 Correct 144 ms 10356 KB Output is correct
143 Correct 139 ms 10480 KB Output is correct
144 Correct 154 ms 10372 KB Output is correct
145 Correct 139 ms 10356 KB Output is correct
146 Correct 140 ms 10492 KB Output is correct
147 Correct 0 ms 340 KB Output is correct
148 Correct 139 ms 10308 KB Output is correct
149 Correct 148 ms 10328 KB Output is correct
150 Correct 140 ms 10356 KB Output is correct
151 Correct 140 ms 10320 KB Output is correct
152 Correct 138 ms 10396 KB Output is correct
153 Correct 144 ms 10376 KB Output is correct
154 Correct 143 ms 10404 KB Output is correct