답안 #735064

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
735064 2023-05-03T12:55:57 Z vjudge1 Cryptography (NOI20_crypto) C++17
100 / 100
622 ms 111032 KB
#include <bits/stdc++.h>
using namespace std;

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
#define oset tree<int, null_type,less_equal<int>, rb_tree_tag,tree_order_statistics_node_update>

template<typename... T>
void see(T&... args) {((cin >> args), ...);}
template<typename... T>
void put(T&&... args) {((cout << args << ' '), ...);}
template<typename... T>
void putl(T&&... args) {((cout << args << ' '), ...); cout << '\n';}

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define int long long
#define F first
#define S second
#define ii pair<int, int>

#define vt vector
#define pb push_back
#define all(a) (a).begin(), (a).end()
#define sz size()

#define endl '\n'

#define rep(i,a,b) for(int i=a; i<=b; i++)
#define rev(i,b,a) for(int i=b; i>=a; i--)

#define reada(a,x,y) for(int i=x; i<=y; i++){cin >> a[i];}

const int M = 1e9+7;
const int Mxn = 1e6, Nxn = 2*1e5, Mxm = 3e5+5, Nxm = 1005, Dxn = 1e9+1;

int a[Mxm];
vt<int> t[4*Mxm];

void build(int id, int L, int R) {
    if(L == R) {
        t[id].pb(a[L]);
        return;
    }

    int mid = (L+R)/2;
    build(2*id, L, mid);
    build(2*id+1, mid+1, R);

    int n = t[2*id].sz, m = t[2*id+1].sz, i = 0, j = 0;

    while(i < n && j < m) {
        if(t[2*id][i] < t[2*id+1][j]) {
            t[id].pb(t[2*id][i]);
            i++;
        }
        else {
            t[id].pb(t[2*id+1][j]);
            j++;
        }
    }
    while(i < n) {
        t[id].pb(t[2*id][i]);
        i++;
    }
    while(j < m) {
        t[id].pb(t[2*id+1][j]);
        j++;
    }
}

int query(int id, int L, int R, int l, int r, int x) {
    if(L > r || R < l) return 0;
    if(l <= L && R <= r) {
        int n = t[id].sz;
        int k = upper_bound(all(t[id]), x) - t[id].begin();
        return k;
    }

    int mid = (L+R)/2;
    return (query(2*id, L, mid, l, min(r, mid), x) + query(2*id+1, mid+1, R, max(l, mid+1), r, x)) % M;
}

int f[Mxm];

void fact(int n) {
    f[0] = 0;
    f[1] = 1;
    for(int i = 2; i <= n; i++) {
        f[i] = f[i - 1] * i % M;
    }
}

void solve() {
    int n; see(n);
    rep(i,1,n) see(a[i]);

    build(1, 1, n);
    fact(n);

    int s = 0;
    rep(i,1,n) {
        s += ((query(1, 1, n, i+1, n, a[i]) * f[n - i])) % M;
    }
    put((s + 1)%M);
    return;
}

signed main() { IOS
    int t=1;
    //cin >> t;
    while(t--) {
        solve();
    }
    return 0;
}

Compilation message

Crypto.cpp: In function 'long long int query(long long int, long long int, long long int, long long int, long long int, long long int)':
Crypto.cpp:76:13: warning: unused variable 'n' [-Wunused-variable]
   76 |         int n = t[id].sz;
      |             ^
# 결과 실행 시간 메모리 Grader output
1 Correct 14 ms 28500 KB Output is correct
2 Correct 15 ms 28484 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 14 ms 28500 KB Output is correct
2 Correct 15 ms 28484 KB Output is correct
3 Correct 15 ms 28508 KB Output is correct
4 Correct 15 ms 28500 KB Output is correct
5 Correct 15 ms 28516 KB Output is correct
6 Correct 16 ms 28516 KB Output is correct
7 Correct 16 ms 28500 KB Output is correct
8 Correct 15 ms 28512 KB Output is correct
9 Correct 16 ms 28500 KB Output is correct
10 Correct 15 ms 28488 KB Output is correct
11 Correct 15 ms 28516 KB Output is correct
12 Correct 15 ms 28448 KB Output is correct
13 Correct 15 ms 28512 KB Output is correct
14 Correct 15 ms 28436 KB Output is correct
15 Correct 15 ms 28460 KB Output is correct
16 Correct 14 ms 28396 KB Output is correct
17 Correct 15 ms 28512 KB Output is correct
18 Correct 16 ms 28516 KB Output is correct
19 Correct 14 ms 28416 KB Output is correct
20 Correct 14 ms 28484 KB Output is correct
21 Correct 16 ms 28512 KB Output is correct
22 Correct 15 ms 28416 KB Output is correct
23 Correct 17 ms 28492 KB Output is correct
24 Correct 15 ms 28544 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 15 ms 28508 KB Output is correct
2 Correct 287 ms 110820 KB Output is correct
3 Correct 272 ms 110824 KB Output is correct
4 Correct 271 ms 110852 KB Output is correct
5 Correct 293 ms 110840 KB Output is correct
6 Correct 279 ms 110900 KB Output is correct
7 Correct 268 ms 110820 KB Output is correct
8 Correct 265 ms 110820 KB Output is correct
9 Correct 265 ms 110888 KB Output is correct
10 Correct 264 ms 110832 KB Output is correct
11 Correct 271 ms 110816 KB Output is correct
12 Correct 278 ms 110736 KB Output is correct
13 Correct 291 ms 110780 KB Output is correct
14 Correct 282 ms 110820 KB Output is correct
15 Correct 280 ms 110792 KB Output is correct
16 Correct 286 ms 110784 KB Output is correct
17 Correct 277 ms 110816 KB Output is correct
18 Correct 303 ms 110800 KB Output is correct
19 Correct 270 ms 110824 KB Output is correct
20 Correct 275 ms 110936 KB Output is correct
21 Correct 278 ms 110824 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 15 ms 28476 KB Output is correct
2 Correct 273 ms 109868 KB Output is correct
3 Correct 265 ms 109832 KB Output is correct
4 Correct 267 ms 109856 KB Output is correct
5 Correct 270 ms 109788 KB Output is correct
6 Correct 261 ms 109864 KB Output is correct
7 Correct 274 ms 109864 KB Output is correct
8 Correct 271 ms 109864 KB Output is correct
9 Correct 262 ms 109916 KB Output is correct
10 Correct 258 ms 109736 KB Output is correct
11 Correct 273 ms 109780 KB Output is correct
12 Correct 288 ms 109864 KB Output is correct
13 Correct 322 ms 109860 KB Output is correct
14 Correct 264 ms 109864 KB Output is correct
15 Correct 272 ms 109752 KB Output is correct
16 Correct 265 ms 109848 KB Output is correct
17 Correct 277 ms 109844 KB Output is correct
18 Correct 274 ms 109772 KB Output is correct
19 Correct 277 ms 109860 KB Output is correct
20 Correct 283 ms 109936 KB Output is correct
21 Correct 272 ms 109768 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 15 ms 28500 KB Output is correct
2 Correct 17 ms 29084 KB Output is correct
3 Correct 17 ms 29112 KB Output is correct
4 Correct 18 ms 29108 KB Output is correct
5 Correct 18 ms 29036 KB Output is correct
6 Correct 18 ms 29224 KB Output is correct
7 Correct 17 ms 29008 KB Output is correct
8 Correct 17 ms 29056 KB Output is correct
9 Correct 18 ms 29012 KB Output is correct
10 Correct 17 ms 29112 KB Output is correct
11 Correct 17 ms 29104 KB Output is correct
12 Correct 18 ms 29092 KB Output is correct
13 Correct 18 ms 29032 KB Output is correct
14 Correct 19 ms 29012 KB Output is correct
15 Correct 16 ms 28500 KB Output is correct
16 Correct 18 ms 29036 KB Output is correct
17 Correct 17 ms 29100 KB Output is correct
18 Correct 17 ms 29008 KB Output is correct
19 Correct 17 ms 29012 KB Output is correct
20 Correct 17 ms 29044 KB Output is correct
21 Correct 18 ms 29112 KB Output is correct
22 Correct 19 ms 29056 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 14 ms 28500 KB Output is correct
2 Correct 15 ms 28484 KB Output is correct
3 Correct 15 ms 28508 KB Output is correct
4 Correct 15 ms 28500 KB Output is correct
5 Correct 15 ms 28516 KB Output is correct
6 Correct 16 ms 28516 KB Output is correct
7 Correct 16 ms 28500 KB Output is correct
8 Correct 15 ms 28512 KB Output is correct
9 Correct 16 ms 28500 KB Output is correct
10 Correct 15 ms 28488 KB Output is correct
11 Correct 15 ms 28516 KB Output is correct
12 Correct 15 ms 28448 KB Output is correct
13 Correct 15 ms 28512 KB Output is correct
14 Correct 15 ms 28436 KB Output is correct
15 Correct 15 ms 28460 KB Output is correct
16 Correct 14 ms 28396 KB Output is correct
17 Correct 15 ms 28512 KB Output is correct
18 Correct 16 ms 28516 KB Output is correct
19 Correct 14 ms 28416 KB Output is correct
20 Correct 14 ms 28484 KB Output is correct
21 Correct 16 ms 28512 KB Output is correct
22 Correct 15 ms 28416 KB Output is correct
23 Correct 17 ms 28492 KB Output is correct
24 Correct 15 ms 28544 KB Output is correct
25 Correct 15 ms 28500 KB Output is correct
26 Correct 17 ms 29084 KB Output is correct
27 Correct 17 ms 29112 KB Output is correct
28 Correct 18 ms 29108 KB Output is correct
29 Correct 18 ms 29036 KB Output is correct
30 Correct 18 ms 29224 KB Output is correct
31 Correct 17 ms 29008 KB Output is correct
32 Correct 17 ms 29056 KB Output is correct
33 Correct 18 ms 29012 KB Output is correct
34 Correct 17 ms 29112 KB Output is correct
35 Correct 17 ms 29104 KB Output is correct
36 Correct 18 ms 29092 KB Output is correct
37 Correct 18 ms 29032 KB Output is correct
38 Correct 19 ms 29012 KB Output is correct
39 Correct 16 ms 28500 KB Output is correct
40 Correct 18 ms 29036 KB Output is correct
41 Correct 17 ms 29100 KB Output is correct
42 Correct 17 ms 29008 KB Output is correct
43 Correct 17 ms 29012 KB Output is correct
44 Correct 17 ms 29044 KB Output is correct
45 Correct 18 ms 29112 KB Output is correct
46 Correct 19 ms 29056 KB Output is correct
47 Correct 14 ms 28512 KB Output is correct
48 Correct 16 ms 29036 KB Output is correct
49 Correct 18 ms 29036 KB Output is correct
50 Correct 17 ms 29012 KB Output is correct
51 Correct 17 ms 29128 KB Output is correct
52 Correct 17 ms 29012 KB Output is correct
53 Correct 19 ms 29012 KB Output is correct
54 Correct 17 ms 29064 KB Output is correct
55 Correct 18 ms 29064 KB Output is correct
56 Correct 18 ms 29092 KB Output is correct
57 Correct 19 ms 29012 KB Output is correct
58 Correct 19 ms 29012 KB Output is correct
59 Correct 18 ms 28988 KB Output is correct
60 Correct 17 ms 29036 KB Output is correct
61 Correct 15 ms 28500 KB Output is correct
62 Correct 16 ms 29032 KB Output is correct
63 Correct 17 ms 29128 KB Output is correct
64 Correct 18 ms 29112 KB Output is correct
65 Correct 18 ms 29084 KB Output is correct
66 Correct 17 ms 29092 KB Output is correct
67 Correct 17 ms 29088 KB Output is correct
68 Correct 18 ms 29124 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 15 ms 28476 KB Output is correct
2 Correct 273 ms 109868 KB Output is correct
3 Correct 265 ms 109832 KB Output is correct
4 Correct 267 ms 109856 KB Output is correct
5 Correct 270 ms 109788 KB Output is correct
6 Correct 261 ms 109864 KB Output is correct
7 Correct 274 ms 109864 KB Output is correct
8 Correct 271 ms 109864 KB Output is correct
9 Correct 262 ms 109916 KB Output is correct
10 Correct 258 ms 109736 KB Output is correct
11 Correct 273 ms 109780 KB Output is correct
12 Correct 288 ms 109864 KB Output is correct
13 Correct 322 ms 109860 KB Output is correct
14 Correct 264 ms 109864 KB Output is correct
15 Correct 272 ms 109752 KB Output is correct
16 Correct 265 ms 109848 KB Output is correct
17 Correct 277 ms 109844 KB Output is correct
18 Correct 274 ms 109772 KB Output is correct
19 Correct 277 ms 109860 KB Output is correct
20 Correct 283 ms 109936 KB Output is correct
21 Correct 272 ms 109768 KB Output is correct
22 Correct 15 ms 28500 KB Output is correct
23 Correct 17 ms 29084 KB Output is correct
24 Correct 17 ms 29112 KB Output is correct
25 Correct 18 ms 29108 KB Output is correct
26 Correct 18 ms 29036 KB Output is correct
27 Correct 18 ms 29224 KB Output is correct
28 Correct 17 ms 29008 KB Output is correct
29 Correct 17 ms 29056 KB Output is correct
30 Correct 18 ms 29012 KB Output is correct
31 Correct 17 ms 29112 KB Output is correct
32 Correct 17 ms 29104 KB Output is correct
33 Correct 18 ms 29092 KB Output is correct
34 Correct 18 ms 29032 KB Output is correct
35 Correct 19 ms 29012 KB Output is correct
36 Correct 16 ms 28500 KB Output is correct
37 Correct 18 ms 29036 KB Output is correct
38 Correct 17 ms 29100 KB Output is correct
39 Correct 17 ms 29008 KB Output is correct
40 Correct 17 ms 29012 KB Output is correct
41 Correct 17 ms 29044 KB Output is correct
42 Correct 18 ms 29112 KB Output is correct
43 Correct 19 ms 29056 KB Output is correct
44 Correct 17 ms 28500 KB Output is correct
45 Correct 457 ms 109880 KB Output is correct
46 Correct 452 ms 109864 KB Output is correct
47 Correct 460 ms 109856 KB Output is correct
48 Correct 484 ms 109872 KB Output is correct
49 Correct 497 ms 109860 KB Output is correct
50 Correct 500 ms 109796 KB Output is correct
51 Correct 508 ms 109868 KB Output is correct
52 Correct 489 ms 109904 KB Output is correct
53 Correct 476 ms 109864 KB Output is correct
54 Correct 475 ms 109864 KB Output is correct
55 Correct 479 ms 109860 KB Output is correct
56 Correct 469 ms 109864 KB Output is correct
57 Correct 469 ms 109864 KB Output is correct
58 Correct 19 ms 28500 KB Output is correct
59 Correct 482 ms 109868 KB Output is correct
60 Correct 485 ms 109864 KB Output is correct
61 Correct 491 ms 109804 KB Output is correct
62 Correct 545 ms 109992 KB Output is correct
63 Correct 478 ms 109752 KB Output is correct
64 Correct 526 ms 109868 KB Output is correct
65 Correct 488 ms 109872 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 14 ms 28500 KB Output is correct
2 Correct 15 ms 28484 KB Output is correct
3 Correct 15 ms 28508 KB Output is correct
4 Correct 15 ms 28500 KB Output is correct
5 Correct 15 ms 28516 KB Output is correct
6 Correct 16 ms 28516 KB Output is correct
7 Correct 16 ms 28500 KB Output is correct
8 Correct 15 ms 28512 KB Output is correct
9 Correct 16 ms 28500 KB Output is correct
10 Correct 15 ms 28488 KB Output is correct
11 Correct 15 ms 28516 KB Output is correct
12 Correct 15 ms 28448 KB Output is correct
13 Correct 15 ms 28512 KB Output is correct
14 Correct 15 ms 28436 KB Output is correct
15 Correct 15 ms 28460 KB Output is correct
16 Correct 14 ms 28396 KB Output is correct
17 Correct 15 ms 28512 KB Output is correct
18 Correct 16 ms 28516 KB Output is correct
19 Correct 14 ms 28416 KB Output is correct
20 Correct 14 ms 28484 KB Output is correct
21 Correct 16 ms 28512 KB Output is correct
22 Correct 15 ms 28416 KB Output is correct
23 Correct 17 ms 28492 KB Output is correct
24 Correct 15 ms 28544 KB Output is correct
25 Correct 15 ms 28508 KB Output is correct
26 Correct 287 ms 110820 KB Output is correct
27 Correct 272 ms 110824 KB Output is correct
28 Correct 271 ms 110852 KB Output is correct
29 Correct 293 ms 110840 KB Output is correct
30 Correct 279 ms 110900 KB Output is correct
31 Correct 268 ms 110820 KB Output is correct
32 Correct 265 ms 110820 KB Output is correct
33 Correct 265 ms 110888 KB Output is correct
34 Correct 264 ms 110832 KB Output is correct
35 Correct 271 ms 110816 KB Output is correct
36 Correct 278 ms 110736 KB Output is correct
37 Correct 291 ms 110780 KB Output is correct
38 Correct 282 ms 110820 KB Output is correct
39 Correct 280 ms 110792 KB Output is correct
40 Correct 286 ms 110784 KB Output is correct
41 Correct 277 ms 110816 KB Output is correct
42 Correct 303 ms 110800 KB Output is correct
43 Correct 270 ms 110824 KB Output is correct
44 Correct 275 ms 110936 KB Output is correct
45 Correct 278 ms 110824 KB Output is correct
46 Correct 15 ms 28476 KB Output is correct
47 Correct 273 ms 109868 KB Output is correct
48 Correct 265 ms 109832 KB Output is correct
49 Correct 267 ms 109856 KB Output is correct
50 Correct 270 ms 109788 KB Output is correct
51 Correct 261 ms 109864 KB Output is correct
52 Correct 274 ms 109864 KB Output is correct
53 Correct 271 ms 109864 KB Output is correct
54 Correct 262 ms 109916 KB Output is correct
55 Correct 258 ms 109736 KB Output is correct
56 Correct 273 ms 109780 KB Output is correct
57 Correct 288 ms 109864 KB Output is correct
58 Correct 322 ms 109860 KB Output is correct
59 Correct 264 ms 109864 KB Output is correct
60 Correct 272 ms 109752 KB Output is correct
61 Correct 265 ms 109848 KB Output is correct
62 Correct 277 ms 109844 KB Output is correct
63 Correct 274 ms 109772 KB Output is correct
64 Correct 277 ms 109860 KB Output is correct
65 Correct 283 ms 109936 KB Output is correct
66 Correct 272 ms 109768 KB Output is correct
67 Correct 15 ms 28500 KB Output is correct
68 Correct 17 ms 29084 KB Output is correct
69 Correct 17 ms 29112 KB Output is correct
70 Correct 18 ms 29108 KB Output is correct
71 Correct 18 ms 29036 KB Output is correct
72 Correct 18 ms 29224 KB Output is correct
73 Correct 17 ms 29008 KB Output is correct
74 Correct 17 ms 29056 KB Output is correct
75 Correct 18 ms 29012 KB Output is correct
76 Correct 17 ms 29112 KB Output is correct
77 Correct 17 ms 29104 KB Output is correct
78 Correct 18 ms 29092 KB Output is correct
79 Correct 18 ms 29032 KB Output is correct
80 Correct 19 ms 29012 KB Output is correct
81 Correct 16 ms 28500 KB Output is correct
82 Correct 18 ms 29036 KB Output is correct
83 Correct 17 ms 29100 KB Output is correct
84 Correct 17 ms 29008 KB Output is correct
85 Correct 17 ms 29012 KB Output is correct
86 Correct 17 ms 29044 KB Output is correct
87 Correct 18 ms 29112 KB Output is correct
88 Correct 19 ms 29056 KB Output is correct
89 Correct 14 ms 28512 KB Output is correct
90 Correct 16 ms 29036 KB Output is correct
91 Correct 18 ms 29036 KB Output is correct
92 Correct 17 ms 29012 KB Output is correct
93 Correct 17 ms 29128 KB Output is correct
94 Correct 17 ms 29012 KB Output is correct
95 Correct 19 ms 29012 KB Output is correct
96 Correct 17 ms 29064 KB Output is correct
97 Correct 18 ms 29064 KB Output is correct
98 Correct 18 ms 29092 KB Output is correct
99 Correct 19 ms 29012 KB Output is correct
100 Correct 19 ms 29012 KB Output is correct
101 Correct 18 ms 28988 KB Output is correct
102 Correct 17 ms 29036 KB Output is correct
103 Correct 15 ms 28500 KB Output is correct
104 Correct 16 ms 29032 KB Output is correct
105 Correct 17 ms 29128 KB Output is correct
106 Correct 18 ms 29112 KB Output is correct
107 Correct 18 ms 29084 KB Output is correct
108 Correct 17 ms 29092 KB Output is correct
109 Correct 17 ms 29088 KB Output is correct
110 Correct 18 ms 29124 KB Output is correct
111 Correct 17 ms 28500 KB Output is correct
112 Correct 457 ms 109880 KB Output is correct
113 Correct 452 ms 109864 KB Output is correct
114 Correct 460 ms 109856 KB Output is correct
115 Correct 484 ms 109872 KB Output is correct
116 Correct 497 ms 109860 KB Output is correct
117 Correct 500 ms 109796 KB Output is correct
118 Correct 508 ms 109868 KB Output is correct
119 Correct 489 ms 109904 KB Output is correct
120 Correct 476 ms 109864 KB Output is correct
121 Correct 475 ms 109864 KB Output is correct
122 Correct 479 ms 109860 KB Output is correct
123 Correct 469 ms 109864 KB Output is correct
124 Correct 469 ms 109864 KB Output is correct
125 Correct 19 ms 28500 KB Output is correct
126 Correct 482 ms 109868 KB Output is correct
127 Correct 485 ms 109864 KB Output is correct
128 Correct 491 ms 109804 KB Output is correct
129 Correct 545 ms 109992 KB Output is correct
130 Correct 478 ms 109752 KB Output is correct
131 Correct 526 ms 109868 KB Output is correct
132 Correct 488 ms 109872 KB Output is correct
133 Correct 16 ms 28500 KB Output is correct
134 Correct 498 ms 110816 KB Output is correct
135 Correct 498 ms 110820 KB Output is correct
136 Correct 490 ms 110816 KB Output is correct
137 Correct 509 ms 110828 KB Output is correct
138 Correct 487 ms 110800 KB Output is correct
139 Correct 521 ms 110824 KB Output is correct
140 Correct 568 ms 110896 KB Output is correct
141 Correct 622 ms 110900 KB Output is correct
142 Correct 508 ms 110784 KB Output is correct
143 Correct 493 ms 110824 KB Output is correct
144 Correct 496 ms 110824 KB Output is correct
145 Correct 453 ms 110824 KB Output is correct
146 Correct 440 ms 110784 KB Output is correct
147 Correct 15 ms 28500 KB Output is correct
148 Correct 442 ms 110924 KB Output is correct
149 Correct 435 ms 111032 KB Output is correct
150 Correct 470 ms 110824 KB Output is correct
151 Correct 451 ms 110924 KB Output is correct
152 Correct 447 ms 110936 KB Output is correct
153 Correct 453 ms 110872 KB Output is correct
154 Correct 449 ms 110828 KB Output is correct