Submission #997031

# Submission time Handle Problem Language Result Execution time Memory
997031 2024-06-11T15:42:10 Z cpptowin Cryptography (NOI20_crypto) C++17
100 / 100
118 ms 24004 KB
#include <bits/stdc++.h>
#define fo(i, d, c) for (int i = d; i <= c; i++)
#define fod(i, c, d) for (int i = c; i >= d; i--)
#define maxn 1000010
#define N 1010
#define fi first
#define se second
#define pb emplace_back
#define en cout << "\n";
#define int long long
#define inf (int)1e18
#define pii pair<int, int>
#define vii vector<pii>
#define lb(x) x & -x
#define bit(i, j) ((i >> j) & 1)
#define offbit(i, j) (i ^ (1LL << j))
#define onbit(i, j) (i | (1LL << j))
#define vi vector<int>
#define all(x) x.begin(),x.end()
template <typename T1, typename T2>
bool minimize(T1 &a, T2 b)
{
    if (a > b)
    {
        a = b;
        return true;
    }
    return false;
}
template <typename T1, typename T2>
bool maximize(T1 &a, T2 b)
{
    if (a < b)
    {
        a = b;
        return true;
    }
    return false;
}
using namespace std;
const int nsqrt = 450;
const int mod = 1e9 + 7;
int n,a[maxn];
vi nen;
int f[maxn];
struct BIT
{
    int t[maxn];
    void up(int x,int val)
    {
        for( ; x < maxn ; x += lb(x)) t[x] += val;
    }
    int get(int x)
    {
        int ans = 0;
        for( ; x ; x -= lb(x)) ans += t[x];
        return ans;
    }
}t;
main()
{
#define name "TASK"
    if (fopen(name ".inp", "r"))
    {
        freopen(name ".inp", "r", stdin);
        freopen(name ".out", "w", stdout);
    }
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> n;
    fo(i,1,n)
    {
        cin >> a[i];
        nen.pb(a[i]);
    }
    sort(all(nen));
    nen.erase(unique(all(nen)),nen.end());
    fo(i,1,n) a[i] = lower_bound(all(nen),a[i]) - nen.begin() + 1;
    f[0] = 1;
    fo(i,1,maxn - 1) f[i] = f[i - 1] * i % mod;
    int ans = 0;
    fo(i,1,n) 
    {
        ans = (ans + (a[i] - 1 - t.get(a[i])) * f[n - i] % mod) % mod;
        t.up(a[i],1);
    }
    cout << (ans + 1) % mod;
}

Compilation message

Crypto.cpp:60:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   60 | main()
      | ^~~~
Crypto.cpp: In function 'int main()':
Crypto.cpp:65:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   65 |         freopen(name ".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
Crypto.cpp:66:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   66 |         freopen(name ".out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 6 ms 14684 KB Output is correct
2 Correct 6 ms 14684 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 14684 KB Output is correct
2 Correct 6 ms 14684 KB Output is correct
3 Correct 6 ms 14684 KB Output is correct
4 Correct 6 ms 14680 KB Output is correct
5 Correct 6 ms 14824 KB Output is correct
6 Correct 6 ms 14680 KB Output is correct
7 Correct 6 ms 14684 KB Output is correct
8 Correct 6 ms 14684 KB Output is correct
9 Correct 6 ms 14684 KB Output is correct
10 Correct 6 ms 14684 KB Output is correct
11 Correct 6 ms 14684 KB Output is correct
12 Correct 6 ms 14684 KB Output is correct
13 Correct 6 ms 14812 KB Output is correct
14 Correct 7 ms 14684 KB Output is correct
15 Correct 6 ms 14684 KB Output is correct
16 Correct 6 ms 14820 KB Output is correct
17 Correct 6 ms 14684 KB Output is correct
18 Correct 6 ms 14684 KB Output is correct
19 Correct 6 ms 14820 KB Output is correct
20 Correct 6 ms 14684 KB Output is correct
21 Correct 6 ms 14680 KB Output is correct
22 Correct 7 ms 14684 KB Output is correct
23 Correct 6 ms 14684 KB Output is correct
24 Correct 6 ms 14680 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 14812 KB Output is correct
2 Correct 51 ms 18876 KB Output is correct
3 Correct 51 ms 18112 KB Output is correct
4 Correct 53 ms 18880 KB Output is correct
5 Correct 50 ms 18620 KB Output is correct
6 Correct 52 ms 17856 KB Output is correct
7 Correct 56 ms 19480 KB Output is correct
8 Correct 57 ms 20160 KB Output is correct
9 Correct 55 ms 19352 KB Output is correct
10 Correct 60 ms 20160 KB Output is correct
11 Correct 56 ms 20168 KB Output is correct
12 Correct 50 ms 18144 KB Output is correct
13 Correct 50 ms 18952 KB Output is correct
14 Correct 50 ms 17860 KB Output is correct
15 Correct 56 ms 20920 KB Output is correct
16 Correct 56 ms 19624 KB Output is correct
17 Correct 58 ms 20672 KB Output is correct
18 Correct 55 ms 20168 KB Output is correct
19 Correct 51 ms 18368 KB Output is correct
20 Correct 52 ms 17984 KB Output is correct
21 Correct 51 ms 18624 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 14680 KB Output is correct
2 Correct 47 ms 20088 KB Output is correct
3 Correct 48 ms 20344 KB Output is correct
4 Correct 52 ms 20108 KB Output is correct
5 Correct 49 ms 19392 KB Output is correct
6 Correct 47 ms 19772 KB Output is correct
7 Correct 49 ms 19304 KB Output is correct
8 Correct 54 ms 20548 KB Output is correct
9 Correct 53 ms 20176 KB Output is correct
10 Correct 48 ms 20620 KB Output is correct
11 Correct 47 ms 20152 KB Output is correct
12 Correct 51 ms 19384 KB Output is correct
13 Correct 49 ms 19908 KB Output is correct
14 Correct 47 ms 20760 KB Output is correct
15 Correct 48 ms 19880 KB Output is correct
16 Correct 48 ms 20928 KB Output is correct
17 Correct 50 ms 20340 KB Output is correct
18 Correct 47 ms 19388 KB Output is correct
19 Correct 48 ms 20380 KB Output is correct
20 Correct 49 ms 21052 KB Output is correct
21 Correct 48 ms 20160 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 14684 KB Output is correct
2 Correct 6 ms 14684 KB Output is correct
3 Correct 7 ms 14872 KB Output is correct
4 Correct 7 ms 14684 KB Output is correct
5 Correct 7 ms 14684 KB Output is correct
6 Correct 7 ms 14884 KB Output is correct
7 Correct 7 ms 14884 KB Output is correct
8 Correct 7 ms 14684 KB Output is correct
9 Correct 7 ms 14884 KB Output is correct
10 Correct 7 ms 14684 KB Output is correct
11 Correct 7 ms 14884 KB Output is correct
12 Correct 7 ms 14884 KB Output is correct
13 Correct 7 ms 14684 KB Output is correct
14 Correct 7 ms 14876 KB Output is correct
15 Correct 7 ms 14684 KB Output is correct
16 Correct 6 ms 14940 KB Output is correct
17 Correct 7 ms 14896 KB Output is correct
18 Correct 7 ms 14940 KB Output is correct
19 Correct 7 ms 14888 KB Output is correct
20 Correct 7 ms 14940 KB Output is correct
21 Correct 7 ms 14856 KB Output is correct
22 Correct 7 ms 14940 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 14684 KB Output is correct
2 Correct 6 ms 14684 KB Output is correct
3 Correct 6 ms 14684 KB Output is correct
4 Correct 6 ms 14680 KB Output is correct
5 Correct 6 ms 14824 KB Output is correct
6 Correct 6 ms 14680 KB Output is correct
7 Correct 6 ms 14684 KB Output is correct
8 Correct 6 ms 14684 KB Output is correct
9 Correct 6 ms 14684 KB Output is correct
10 Correct 6 ms 14684 KB Output is correct
11 Correct 6 ms 14684 KB Output is correct
12 Correct 6 ms 14684 KB Output is correct
13 Correct 6 ms 14812 KB Output is correct
14 Correct 7 ms 14684 KB Output is correct
15 Correct 6 ms 14684 KB Output is correct
16 Correct 6 ms 14820 KB Output is correct
17 Correct 6 ms 14684 KB Output is correct
18 Correct 6 ms 14684 KB Output is correct
19 Correct 6 ms 14820 KB Output is correct
20 Correct 6 ms 14684 KB Output is correct
21 Correct 6 ms 14680 KB Output is correct
22 Correct 7 ms 14684 KB Output is correct
23 Correct 6 ms 14684 KB Output is correct
24 Correct 6 ms 14680 KB Output is correct
25 Correct 6 ms 14684 KB Output is correct
26 Correct 6 ms 14684 KB Output is correct
27 Correct 7 ms 14872 KB Output is correct
28 Correct 7 ms 14684 KB Output is correct
29 Correct 7 ms 14684 KB Output is correct
30 Correct 7 ms 14884 KB Output is correct
31 Correct 7 ms 14884 KB Output is correct
32 Correct 7 ms 14684 KB Output is correct
33 Correct 7 ms 14884 KB Output is correct
34 Correct 7 ms 14684 KB Output is correct
35 Correct 7 ms 14884 KB Output is correct
36 Correct 7 ms 14884 KB Output is correct
37 Correct 7 ms 14684 KB Output is correct
38 Correct 7 ms 14876 KB Output is correct
39 Correct 7 ms 14684 KB Output is correct
40 Correct 6 ms 14940 KB Output is correct
41 Correct 7 ms 14896 KB Output is correct
42 Correct 7 ms 14940 KB Output is correct
43 Correct 7 ms 14888 KB Output is correct
44 Correct 7 ms 14940 KB Output is correct
45 Correct 7 ms 14856 KB Output is correct
46 Correct 7 ms 14940 KB Output is correct
47 Correct 6 ms 14684 KB Output is correct
48 Correct 7 ms 14940 KB Output is correct
49 Correct 7 ms 14940 KB Output is correct
50 Correct 7 ms 14820 KB Output is correct
51 Correct 7 ms 14896 KB Output is correct
52 Correct 7 ms 14940 KB Output is correct
53 Correct 7 ms 14868 KB Output is correct
54 Correct 7 ms 14940 KB Output is correct
55 Correct 7 ms 14940 KB Output is correct
56 Correct 7 ms 14940 KB Output is correct
57 Correct 7 ms 14940 KB Output is correct
58 Correct 7 ms 14916 KB Output is correct
59 Correct 7 ms 14940 KB Output is correct
60 Correct 7 ms 14768 KB Output is correct
61 Correct 6 ms 14684 KB Output is correct
62 Correct 7 ms 14940 KB Output is correct
63 Correct 7 ms 14940 KB Output is correct
64 Correct 7 ms 14908 KB Output is correct
65 Correct 7 ms 14940 KB Output is correct
66 Correct 7 ms 14908 KB Output is correct
67 Correct 7 ms 14940 KB Output is correct
68 Correct 7 ms 14940 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 14680 KB Output is correct
2 Correct 47 ms 20088 KB Output is correct
3 Correct 48 ms 20344 KB Output is correct
4 Correct 52 ms 20108 KB Output is correct
5 Correct 49 ms 19392 KB Output is correct
6 Correct 47 ms 19772 KB Output is correct
7 Correct 49 ms 19304 KB Output is correct
8 Correct 54 ms 20548 KB Output is correct
9 Correct 53 ms 20176 KB Output is correct
10 Correct 48 ms 20620 KB Output is correct
11 Correct 47 ms 20152 KB Output is correct
12 Correct 51 ms 19384 KB Output is correct
13 Correct 49 ms 19908 KB Output is correct
14 Correct 47 ms 20760 KB Output is correct
15 Correct 48 ms 19880 KB Output is correct
16 Correct 48 ms 20928 KB Output is correct
17 Correct 50 ms 20340 KB Output is correct
18 Correct 47 ms 19388 KB Output is correct
19 Correct 48 ms 20380 KB Output is correct
20 Correct 49 ms 21052 KB Output is correct
21 Correct 48 ms 20160 KB Output is correct
22 Correct 6 ms 14684 KB Output is correct
23 Correct 6 ms 14684 KB Output is correct
24 Correct 7 ms 14872 KB Output is correct
25 Correct 7 ms 14684 KB Output is correct
26 Correct 7 ms 14684 KB Output is correct
27 Correct 7 ms 14884 KB Output is correct
28 Correct 7 ms 14884 KB Output is correct
29 Correct 7 ms 14684 KB Output is correct
30 Correct 7 ms 14884 KB Output is correct
31 Correct 7 ms 14684 KB Output is correct
32 Correct 7 ms 14884 KB Output is correct
33 Correct 7 ms 14884 KB Output is correct
34 Correct 7 ms 14684 KB Output is correct
35 Correct 7 ms 14876 KB Output is correct
36 Correct 7 ms 14684 KB Output is correct
37 Correct 6 ms 14940 KB Output is correct
38 Correct 7 ms 14896 KB Output is correct
39 Correct 7 ms 14940 KB Output is correct
40 Correct 7 ms 14888 KB Output is correct
41 Correct 7 ms 14940 KB Output is correct
42 Correct 7 ms 14856 KB Output is correct
43 Correct 7 ms 14940 KB Output is correct
44 Correct 7 ms 14680 KB Output is correct
45 Correct 99 ms 21344 KB Output is correct
46 Correct 101 ms 22344 KB Output is correct
47 Correct 99 ms 21696 KB Output is correct
48 Correct 98 ms 22692 KB Output is correct
49 Correct 99 ms 22976 KB Output is correct
50 Correct 112 ms 21436 KB Output is correct
51 Correct 109 ms 22204 KB Output is correct
52 Correct 100 ms 21692 KB Output is correct
53 Correct 98 ms 22860 KB Output is correct
54 Correct 102 ms 22204 KB Output is correct
55 Correct 98 ms 22716 KB Output is correct
56 Correct 97 ms 21696 KB Output is correct
57 Correct 99 ms 21688 KB Output is correct
58 Correct 6 ms 14684 KB Output is correct
59 Correct 99 ms 22152 KB Output is correct
60 Correct 97 ms 20160 KB Output is correct
61 Correct 97 ms 21440 KB Output is correct
62 Correct 100 ms 22452 KB Output is correct
63 Correct 99 ms 21424 KB Output is correct
64 Correct 99 ms 22716 KB Output is correct
65 Correct 97 ms 22200 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 14684 KB Output is correct
2 Correct 6 ms 14684 KB Output is correct
3 Correct 6 ms 14684 KB Output is correct
4 Correct 6 ms 14680 KB Output is correct
5 Correct 6 ms 14824 KB Output is correct
6 Correct 6 ms 14680 KB Output is correct
7 Correct 6 ms 14684 KB Output is correct
8 Correct 6 ms 14684 KB Output is correct
9 Correct 6 ms 14684 KB Output is correct
10 Correct 6 ms 14684 KB Output is correct
11 Correct 6 ms 14684 KB Output is correct
12 Correct 6 ms 14684 KB Output is correct
13 Correct 6 ms 14812 KB Output is correct
14 Correct 7 ms 14684 KB Output is correct
15 Correct 6 ms 14684 KB Output is correct
16 Correct 6 ms 14820 KB Output is correct
17 Correct 6 ms 14684 KB Output is correct
18 Correct 6 ms 14684 KB Output is correct
19 Correct 6 ms 14820 KB Output is correct
20 Correct 6 ms 14684 KB Output is correct
21 Correct 6 ms 14680 KB Output is correct
22 Correct 7 ms 14684 KB Output is correct
23 Correct 6 ms 14684 KB Output is correct
24 Correct 6 ms 14680 KB Output is correct
25 Correct 6 ms 14812 KB Output is correct
26 Correct 51 ms 18876 KB Output is correct
27 Correct 51 ms 18112 KB Output is correct
28 Correct 53 ms 18880 KB Output is correct
29 Correct 50 ms 18620 KB Output is correct
30 Correct 52 ms 17856 KB Output is correct
31 Correct 56 ms 19480 KB Output is correct
32 Correct 57 ms 20160 KB Output is correct
33 Correct 55 ms 19352 KB Output is correct
34 Correct 60 ms 20160 KB Output is correct
35 Correct 56 ms 20168 KB Output is correct
36 Correct 50 ms 18144 KB Output is correct
37 Correct 50 ms 18952 KB Output is correct
38 Correct 50 ms 17860 KB Output is correct
39 Correct 56 ms 20920 KB Output is correct
40 Correct 56 ms 19624 KB Output is correct
41 Correct 58 ms 20672 KB Output is correct
42 Correct 55 ms 20168 KB Output is correct
43 Correct 51 ms 18368 KB Output is correct
44 Correct 52 ms 17984 KB Output is correct
45 Correct 51 ms 18624 KB Output is correct
46 Correct 6 ms 14680 KB Output is correct
47 Correct 47 ms 20088 KB Output is correct
48 Correct 48 ms 20344 KB Output is correct
49 Correct 52 ms 20108 KB Output is correct
50 Correct 49 ms 19392 KB Output is correct
51 Correct 47 ms 19772 KB Output is correct
52 Correct 49 ms 19304 KB Output is correct
53 Correct 54 ms 20548 KB Output is correct
54 Correct 53 ms 20176 KB Output is correct
55 Correct 48 ms 20620 KB Output is correct
56 Correct 47 ms 20152 KB Output is correct
57 Correct 51 ms 19384 KB Output is correct
58 Correct 49 ms 19908 KB Output is correct
59 Correct 47 ms 20760 KB Output is correct
60 Correct 48 ms 19880 KB Output is correct
61 Correct 48 ms 20928 KB Output is correct
62 Correct 50 ms 20340 KB Output is correct
63 Correct 47 ms 19388 KB Output is correct
64 Correct 48 ms 20380 KB Output is correct
65 Correct 49 ms 21052 KB Output is correct
66 Correct 48 ms 20160 KB Output is correct
67 Correct 6 ms 14684 KB Output is correct
68 Correct 6 ms 14684 KB Output is correct
69 Correct 7 ms 14872 KB Output is correct
70 Correct 7 ms 14684 KB Output is correct
71 Correct 7 ms 14684 KB Output is correct
72 Correct 7 ms 14884 KB Output is correct
73 Correct 7 ms 14884 KB Output is correct
74 Correct 7 ms 14684 KB Output is correct
75 Correct 7 ms 14884 KB Output is correct
76 Correct 7 ms 14684 KB Output is correct
77 Correct 7 ms 14884 KB Output is correct
78 Correct 7 ms 14884 KB Output is correct
79 Correct 7 ms 14684 KB Output is correct
80 Correct 7 ms 14876 KB Output is correct
81 Correct 7 ms 14684 KB Output is correct
82 Correct 6 ms 14940 KB Output is correct
83 Correct 7 ms 14896 KB Output is correct
84 Correct 7 ms 14940 KB Output is correct
85 Correct 7 ms 14888 KB Output is correct
86 Correct 7 ms 14940 KB Output is correct
87 Correct 7 ms 14856 KB Output is correct
88 Correct 7 ms 14940 KB Output is correct
89 Correct 6 ms 14684 KB Output is correct
90 Correct 7 ms 14940 KB Output is correct
91 Correct 7 ms 14940 KB Output is correct
92 Correct 7 ms 14820 KB Output is correct
93 Correct 7 ms 14896 KB Output is correct
94 Correct 7 ms 14940 KB Output is correct
95 Correct 7 ms 14868 KB Output is correct
96 Correct 7 ms 14940 KB Output is correct
97 Correct 7 ms 14940 KB Output is correct
98 Correct 7 ms 14940 KB Output is correct
99 Correct 7 ms 14940 KB Output is correct
100 Correct 7 ms 14916 KB Output is correct
101 Correct 7 ms 14940 KB Output is correct
102 Correct 7 ms 14768 KB Output is correct
103 Correct 6 ms 14684 KB Output is correct
104 Correct 7 ms 14940 KB Output is correct
105 Correct 7 ms 14940 KB Output is correct
106 Correct 7 ms 14908 KB Output is correct
107 Correct 7 ms 14940 KB Output is correct
108 Correct 7 ms 14908 KB Output is correct
109 Correct 7 ms 14940 KB Output is correct
110 Correct 7 ms 14940 KB Output is correct
111 Correct 7 ms 14680 KB Output is correct
112 Correct 99 ms 21344 KB Output is correct
113 Correct 101 ms 22344 KB Output is correct
114 Correct 99 ms 21696 KB Output is correct
115 Correct 98 ms 22692 KB Output is correct
116 Correct 99 ms 22976 KB Output is correct
117 Correct 112 ms 21436 KB Output is correct
118 Correct 109 ms 22204 KB Output is correct
119 Correct 100 ms 21692 KB Output is correct
120 Correct 98 ms 22860 KB Output is correct
121 Correct 102 ms 22204 KB Output is correct
122 Correct 98 ms 22716 KB Output is correct
123 Correct 97 ms 21696 KB Output is correct
124 Correct 99 ms 21688 KB Output is correct
125 Correct 6 ms 14684 KB Output is correct
126 Correct 99 ms 22152 KB Output is correct
127 Correct 97 ms 20160 KB Output is correct
128 Correct 97 ms 21440 KB Output is correct
129 Correct 100 ms 22452 KB Output is correct
130 Correct 99 ms 21424 KB Output is correct
131 Correct 99 ms 22716 KB Output is correct
132 Correct 97 ms 22200 KB Output is correct
133 Correct 6 ms 14684 KB Output is correct
134 Correct 118 ms 23660 KB Output is correct
135 Correct 109 ms 22208 KB Output is correct
136 Correct 102 ms 22720 KB Output is correct
137 Correct 115 ms 23744 KB Output is correct
138 Correct 101 ms 23112 KB Output is correct
139 Correct 102 ms 23740 KB Output is correct
140 Correct 104 ms 24004 KB Output is correct
141 Correct 114 ms 24000 KB Output is correct
142 Correct 116 ms 22800 KB Output is correct
143 Correct 101 ms 22460 KB Output is correct
144 Correct 101 ms 23584 KB Output is correct
145 Correct 102 ms 22720 KB Output is correct
146 Correct 102 ms 22976 KB Output is correct
147 Correct 6 ms 14820 KB Output is correct
148 Correct 101 ms 23484 KB Output is correct
149 Correct 106 ms 22892 KB Output is correct
150 Correct 101 ms 22964 KB Output is correct
151 Correct 114 ms 24004 KB Output is correct
152 Correct 103 ms 22996 KB Output is correct
153 Correct 100 ms 22204 KB Output is correct
154 Correct 102 ms 22236 KB Output is correct