Submission #330825

# Submission time Handle Problem Language Result Execution time Memory
330825 2020-11-26T16:32:13 Z ThaiBaHung Cryptography (NOI20_crypto) C++14
100 / 100
572 ms 34676 KB
#include <bits/stdc++.h>
using namespace std;
const int N = 3e5 + 3;
const int mod = 1e9 + 7;
int n;
int a[N];
vector < int > num;
map < int, int > id;
long long gt[N];

struct ok
{
    int lo;
    int hi;
    int val;
};
ok Node[4 * N];

void build(int id, int l, int r)
{
    Node[id].lo = l; Node[id].hi = r;
    Node[id].val = 1;

    if (l == r) return;

    int mid = (l + r) / 2;

    build(id * 2, l, mid);
    build(id * 2 + 1, mid + 1, r);

    Node[id].val = Node[id * 2].val + Node[id * 2 + 1].val;
}

void update(int id, int pos)
{
    if (Node[id].lo > pos || Node[id].hi < pos) return;

    if (Node[id].lo == Node[id].hi)
    {
        Node[id].val = 0;
        return;
    }

    update(id * 2, pos);
    update(id * 2 + 1, pos);

    Node[id].val = Node[id * 2].val + Node[id * 2 + 1].val;
}

int getval(int id, int pos)
{
    if (Node[id].lo >= pos) return 0;

    if (Node[id].hi < pos)
        return Node[id].val;

    return getval(id * 2, pos) + getval(id * 2 + 1, pos);
}

int main()
{
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    //freopen("t.inp","r",stdin); freopen("t.out","w",stdout);

    cin >> n;

    for (int i = 1; i <= n; i++)
        cin >> a[i], num.push_back(a[i]);

    sort(num.begin(), num.end());

    for (int i = 0; i < num.size(); i++)
        id[num[i]] = i + 1;

    for (int i = 1; i <= n; i++)
        a[i] = id[a[i]];

    gt[0] = 1;
    for (int i = 1; i <= n; i++)
        gt[i] = gt[i - 1] * 1ll * i, gt[i] %= mod;


    long long res = 0;

    build(1, 1, n);

    for (int i = 1; i <= n; i++)
    {
        int tmp = getval(1, a[i]);

        res += 1ll * tmp * gt[n - i] % mod;
        res %= mod;

        update(1, a[i]);
    }

    cout << (res + 1) % mod;
}

Compilation message

Crypto.cpp: In function 'int main()':
Crypto.cpp:72:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   72 |     for (int i = 0; i < num.size(); i++)
      |                     ~~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 0 ms 364 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
17 Correct 1 ms 364 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
19 Correct 1 ms 364 KB Output is correct
20 Correct 1 ms 364 KB Output is correct
21 Correct 1 ms 364 KB Output is correct
22 Correct 1 ms 364 KB Output is correct
23 Correct 1 ms 364 KB Output is correct
24 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 263 ms 34404 KB Output is correct
3 Correct 261 ms 34416 KB Output is correct
4 Correct 257 ms 34404 KB Output is correct
5 Correct 272 ms 34392 KB Output is correct
6 Correct 260 ms 34404 KB Output is correct
7 Correct 256 ms 34404 KB Output is correct
8 Correct 258 ms 34404 KB Output is correct
9 Correct 260 ms 34404 KB Output is correct
10 Correct 256 ms 34412 KB Output is correct
11 Correct 258 ms 34404 KB Output is correct
12 Correct 262 ms 34404 KB Output is correct
13 Correct 273 ms 34404 KB Output is correct
14 Correct 261 ms 34404 KB Output is correct
15 Correct 262 ms 34404 KB Output is correct
16 Correct 259 ms 34404 KB Output is correct
17 Correct 262 ms 34404 KB Output is correct
18 Correct 259 ms 34404 KB Output is correct
19 Correct 268 ms 34396 KB Output is correct
20 Correct 258 ms 34404 KB Output is correct
21 Correct 262 ms 34404 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 256 ms 33380 KB Output is correct
3 Correct 250 ms 33380 KB Output is correct
4 Correct 252 ms 33508 KB Output is correct
5 Correct 251 ms 33508 KB Output is correct
6 Correct 253 ms 33380 KB Output is correct
7 Correct 254 ms 33380 KB Output is correct
8 Correct 249 ms 33508 KB Output is correct
9 Correct 252 ms 33508 KB Output is correct
10 Correct 255 ms 33380 KB Output is correct
11 Correct 251 ms 33436 KB Output is correct
12 Correct 258 ms 33380 KB Output is correct
13 Correct 255 ms 33380 KB Output is correct
14 Correct 252 ms 33380 KB Output is correct
15 Correct 255 ms 33380 KB Output is correct
16 Correct 263 ms 33380 KB Output is correct
17 Correct 253 ms 33508 KB Output is correct
18 Correct 263 ms 33380 KB Output is correct
19 Correct 251 ms 33380 KB Output is correct
20 Correct 252 ms 33380 KB Output is correct
21 Correct 255 ms 33380 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 3 ms 620 KB Output is correct
3 Correct 3 ms 620 KB Output is correct
4 Correct 3 ms 620 KB Output is correct
5 Correct 3 ms 748 KB Output is correct
6 Correct 3 ms 620 KB Output is correct
7 Correct 3 ms 620 KB Output is correct
8 Correct 3 ms 620 KB Output is correct
9 Correct 3 ms 620 KB Output is correct
10 Correct 3 ms 620 KB Output is correct
11 Correct 4 ms 620 KB Output is correct
12 Correct 3 ms 620 KB Output is correct
13 Correct 3 ms 620 KB Output is correct
14 Correct 3 ms 620 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 3 ms 620 KB Output is correct
17 Correct 3 ms 620 KB Output is correct
18 Correct 3 ms 620 KB Output is correct
19 Correct 3 ms 620 KB Output is correct
20 Correct 3 ms 620 KB Output is correct
21 Correct 3 ms 620 KB Output is correct
22 Correct 3 ms 620 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 0 ms 364 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
17 Correct 1 ms 364 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
19 Correct 1 ms 364 KB Output is correct
20 Correct 1 ms 364 KB Output is correct
21 Correct 1 ms 364 KB Output is correct
22 Correct 1 ms 364 KB Output is correct
23 Correct 1 ms 364 KB Output is correct
24 Correct 1 ms 364 KB Output is correct
25 Correct 1 ms 364 KB Output is correct
26 Correct 3 ms 620 KB Output is correct
27 Correct 3 ms 620 KB Output is correct
28 Correct 3 ms 620 KB Output is correct
29 Correct 3 ms 748 KB Output is correct
30 Correct 3 ms 620 KB Output is correct
31 Correct 3 ms 620 KB Output is correct
32 Correct 3 ms 620 KB Output is correct
33 Correct 3 ms 620 KB Output is correct
34 Correct 3 ms 620 KB Output is correct
35 Correct 4 ms 620 KB Output is correct
36 Correct 3 ms 620 KB Output is correct
37 Correct 3 ms 620 KB Output is correct
38 Correct 3 ms 620 KB Output is correct
39 Correct 1 ms 364 KB Output is correct
40 Correct 3 ms 620 KB Output is correct
41 Correct 3 ms 620 KB Output is correct
42 Correct 3 ms 620 KB Output is correct
43 Correct 3 ms 620 KB Output is correct
44 Correct 3 ms 620 KB Output is correct
45 Correct 3 ms 620 KB Output is correct
46 Correct 3 ms 620 KB Output is correct
47 Correct 1 ms 364 KB Output is correct
48 Correct 3 ms 620 KB Output is correct
49 Correct 3 ms 620 KB Output is correct
50 Correct 3 ms 620 KB Output is correct
51 Correct 3 ms 620 KB Output is correct
52 Correct 3 ms 620 KB Output is correct
53 Correct 3 ms 620 KB Output is correct
54 Correct 3 ms 620 KB Output is correct
55 Correct 3 ms 620 KB Output is correct
56 Correct 4 ms 620 KB Output is correct
57 Correct 3 ms 620 KB Output is correct
58 Correct 3 ms 620 KB Output is correct
59 Correct 114 ms 748 KB Output is correct
60 Correct 3 ms 620 KB Output is correct
61 Correct 1 ms 364 KB Output is correct
62 Correct 3 ms 620 KB Output is correct
63 Correct 3 ms 620 KB Output is correct
64 Correct 3 ms 620 KB Output is correct
65 Correct 3 ms 620 KB Output is correct
66 Correct 3 ms 620 KB Output is correct
67 Correct 3 ms 620 KB Output is correct
68 Correct 3 ms 620 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 256 ms 33380 KB Output is correct
3 Correct 250 ms 33380 KB Output is correct
4 Correct 252 ms 33508 KB Output is correct
5 Correct 251 ms 33508 KB Output is correct
6 Correct 253 ms 33380 KB Output is correct
7 Correct 254 ms 33380 KB Output is correct
8 Correct 249 ms 33508 KB Output is correct
9 Correct 252 ms 33508 KB Output is correct
10 Correct 255 ms 33380 KB Output is correct
11 Correct 251 ms 33436 KB Output is correct
12 Correct 258 ms 33380 KB Output is correct
13 Correct 255 ms 33380 KB Output is correct
14 Correct 252 ms 33380 KB Output is correct
15 Correct 255 ms 33380 KB Output is correct
16 Correct 263 ms 33380 KB Output is correct
17 Correct 253 ms 33508 KB Output is correct
18 Correct 263 ms 33380 KB Output is correct
19 Correct 251 ms 33380 KB Output is correct
20 Correct 252 ms 33380 KB Output is correct
21 Correct 255 ms 33380 KB Output is correct
22 Correct 1 ms 364 KB Output is correct
23 Correct 3 ms 620 KB Output is correct
24 Correct 3 ms 620 KB Output is correct
25 Correct 3 ms 620 KB Output is correct
26 Correct 3 ms 748 KB Output is correct
27 Correct 3 ms 620 KB Output is correct
28 Correct 3 ms 620 KB Output is correct
29 Correct 3 ms 620 KB Output is correct
30 Correct 3 ms 620 KB Output is correct
31 Correct 3 ms 620 KB Output is correct
32 Correct 4 ms 620 KB Output is correct
33 Correct 3 ms 620 KB Output is correct
34 Correct 3 ms 620 KB Output is correct
35 Correct 3 ms 620 KB Output is correct
36 Correct 1 ms 364 KB Output is correct
37 Correct 3 ms 620 KB Output is correct
38 Correct 3 ms 620 KB Output is correct
39 Correct 3 ms 620 KB Output is correct
40 Correct 3 ms 620 KB Output is correct
41 Correct 3 ms 620 KB Output is correct
42 Correct 3 ms 620 KB Output is correct
43 Correct 3 ms 620 KB Output is correct
44 Correct 1 ms 384 KB Output is correct
45 Correct 541 ms 33508 KB Output is correct
46 Correct 557 ms 33508 KB Output is correct
47 Correct 546 ms 33424 KB Output is correct
48 Correct 544 ms 33508 KB Output is correct
49 Correct 543 ms 33380 KB Output is correct
50 Correct 534 ms 33508 KB Output is correct
51 Correct 547 ms 33508 KB Output is correct
52 Correct 546 ms 33664 KB Output is correct
53 Correct 535 ms 33380 KB Output is correct
54 Correct 544 ms 33380 KB Output is correct
55 Correct 544 ms 33508 KB Output is correct
56 Correct 540 ms 33380 KB Output is correct
57 Correct 536 ms 33380 KB Output is correct
58 Correct 1 ms 364 KB Output is correct
59 Correct 534 ms 33456 KB Output is correct
60 Correct 547 ms 33380 KB Output is correct
61 Correct 531 ms 33384 KB Output is correct
62 Correct 534 ms 33380 KB Output is correct
63 Correct 538 ms 33508 KB Output is correct
64 Correct 531 ms 33380 KB Output is correct
65 Correct 536 ms 33520 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 0 ms 364 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
17 Correct 1 ms 364 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
19 Correct 1 ms 364 KB Output is correct
20 Correct 1 ms 364 KB Output is correct
21 Correct 1 ms 364 KB Output is correct
22 Correct 1 ms 364 KB Output is correct
23 Correct 1 ms 364 KB Output is correct
24 Correct 1 ms 364 KB Output is correct
25 Correct 1 ms 364 KB Output is correct
26 Correct 263 ms 34404 KB Output is correct
27 Correct 261 ms 34416 KB Output is correct
28 Correct 257 ms 34404 KB Output is correct
29 Correct 272 ms 34392 KB Output is correct
30 Correct 260 ms 34404 KB Output is correct
31 Correct 256 ms 34404 KB Output is correct
32 Correct 258 ms 34404 KB Output is correct
33 Correct 260 ms 34404 KB Output is correct
34 Correct 256 ms 34412 KB Output is correct
35 Correct 258 ms 34404 KB Output is correct
36 Correct 262 ms 34404 KB Output is correct
37 Correct 273 ms 34404 KB Output is correct
38 Correct 261 ms 34404 KB Output is correct
39 Correct 262 ms 34404 KB Output is correct
40 Correct 259 ms 34404 KB Output is correct
41 Correct 262 ms 34404 KB Output is correct
42 Correct 259 ms 34404 KB Output is correct
43 Correct 268 ms 34396 KB Output is correct
44 Correct 258 ms 34404 KB Output is correct
45 Correct 262 ms 34404 KB Output is correct
46 Correct 1 ms 364 KB Output is correct
47 Correct 256 ms 33380 KB Output is correct
48 Correct 250 ms 33380 KB Output is correct
49 Correct 252 ms 33508 KB Output is correct
50 Correct 251 ms 33508 KB Output is correct
51 Correct 253 ms 33380 KB Output is correct
52 Correct 254 ms 33380 KB Output is correct
53 Correct 249 ms 33508 KB Output is correct
54 Correct 252 ms 33508 KB Output is correct
55 Correct 255 ms 33380 KB Output is correct
56 Correct 251 ms 33436 KB Output is correct
57 Correct 258 ms 33380 KB Output is correct
58 Correct 255 ms 33380 KB Output is correct
59 Correct 252 ms 33380 KB Output is correct
60 Correct 255 ms 33380 KB Output is correct
61 Correct 263 ms 33380 KB Output is correct
62 Correct 253 ms 33508 KB Output is correct
63 Correct 263 ms 33380 KB Output is correct
64 Correct 251 ms 33380 KB Output is correct
65 Correct 252 ms 33380 KB Output is correct
66 Correct 255 ms 33380 KB Output is correct
67 Correct 1 ms 364 KB Output is correct
68 Correct 3 ms 620 KB Output is correct
69 Correct 3 ms 620 KB Output is correct
70 Correct 3 ms 620 KB Output is correct
71 Correct 3 ms 748 KB Output is correct
72 Correct 3 ms 620 KB Output is correct
73 Correct 3 ms 620 KB Output is correct
74 Correct 3 ms 620 KB Output is correct
75 Correct 3 ms 620 KB Output is correct
76 Correct 3 ms 620 KB Output is correct
77 Correct 4 ms 620 KB Output is correct
78 Correct 3 ms 620 KB Output is correct
79 Correct 3 ms 620 KB Output is correct
80 Correct 3 ms 620 KB Output is correct
81 Correct 1 ms 364 KB Output is correct
82 Correct 3 ms 620 KB Output is correct
83 Correct 3 ms 620 KB Output is correct
84 Correct 3 ms 620 KB Output is correct
85 Correct 3 ms 620 KB Output is correct
86 Correct 3 ms 620 KB Output is correct
87 Correct 3 ms 620 KB Output is correct
88 Correct 3 ms 620 KB Output is correct
89 Correct 1 ms 364 KB Output is correct
90 Correct 3 ms 620 KB Output is correct
91 Correct 3 ms 620 KB Output is correct
92 Correct 3 ms 620 KB Output is correct
93 Correct 3 ms 620 KB Output is correct
94 Correct 3 ms 620 KB Output is correct
95 Correct 3 ms 620 KB Output is correct
96 Correct 3 ms 620 KB Output is correct
97 Correct 3 ms 620 KB Output is correct
98 Correct 4 ms 620 KB Output is correct
99 Correct 3 ms 620 KB Output is correct
100 Correct 3 ms 620 KB Output is correct
101 Correct 114 ms 748 KB Output is correct
102 Correct 3 ms 620 KB Output is correct
103 Correct 1 ms 364 KB Output is correct
104 Correct 3 ms 620 KB Output is correct
105 Correct 3 ms 620 KB Output is correct
106 Correct 3 ms 620 KB Output is correct
107 Correct 3 ms 620 KB Output is correct
108 Correct 3 ms 620 KB Output is correct
109 Correct 3 ms 620 KB Output is correct
110 Correct 3 ms 620 KB Output is correct
111 Correct 1 ms 384 KB Output is correct
112 Correct 541 ms 33508 KB Output is correct
113 Correct 557 ms 33508 KB Output is correct
114 Correct 546 ms 33424 KB Output is correct
115 Correct 544 ms 33508 KB Output is correct
116 Correct 543 ms 33380 KB Output is correct
117 Correct 534 ms 33508 KB Output is correct
118 Correct 547 ms 33508 KB Output is correct
119 Correct 546 ms 33664 KB Output is correct
120 Correct 535 ms 33380 KB Output is correct
121 Correct 544 ms 33380 KB Output is correct
122 Correct 544 ms 33508 KB Output is correct
123 Correct 540 ms 33380 KB Output is correct
124 Correct 536 ms 33380 KB Output is correct
125 Correct 1 ms 364 KB Output is correct
126 Correct 534 ms 33456 KB Output is correct
127 Correct 547 ms 33380 KB Output is correct
128 Correct 531 ms 33384 KB Output is correct
129 Correct 534 ms 33380 KB Output is correct
130 Correct 538 ms 33508 KB Output is correct
131 Correct 531 ms 33380 KB Output is correct
132 Correct 536 ms 33520 KB Output is correct
133 Correct 1 ms 364 KB Output is correct
134 Correct 554 ms 34404 KB Output is correct
135 Correct 545 ms 34404 KB Output is correct
136 Correct 547 ms 34404 KB Output is correct
137 Correct 548 ms 34404 KB Output is correct
138 Correct 545 ms 34404 KB Output is correct
139 Correct 540 ms 34404 KB Output is correct
140 Correct 534 ms 34404 KB Output is correct
141 Correct 567 ms 34404 KB Output is correct
142 Correct 572 ms 34448 KB Output is correct
143 Correct 537 ms 34404 KB Output is correct
144 Correct 571 ms 34404 KB Output is correct
145 Correct 556 ms 34352 KB Output is correct
146 Correct 555 ms 34404 KB Output is correct
147 Correct 1 ms 364 KB Output is correct
148 Correct 547 ms 34416 KB Output is correct
149 Correct 554 ms 34676 KB Output is correct
150 Correct 538 ms 34660 KB Output is correct
151 Correct 544 ms 34404 KB Output is correct
152 Correct 539 ms 34404 KB Output is correct
153 Correct 552 ms 34404 KB Output is correct
154 Correct 546 ms 34404 KB Output is correct