Submission #504813

# Submission time Handle Problem Language Result Execution time Memory
504813 2022-01-10T09:01:03 Z ToroTN Cryptography (NOI20_crypto) C++14
35 / 100
201 ms 33276 KB
#include<bits/stdc++.h>
using namespace std;
long long n,a[300005],b[300005],fac[300005],fen[300005],c[300005],ans=0;
vector<long long> v;
map<long long,long long> mp;
void update(int u,int val)
{
    while(u<=n)
    {
        fen[u]+=val;
        fen[u]%=1000000007;
        u+=(u&(-u));
    }
}
long long query(long long u)
{
    long long val=0;
    while(u>=1)
    {
        val+=fen[u];
        val%=1000000007;
        u-=(u&(-u));
    }
    return val;
}
int main()
{
    scanf("%lld",&n);
    for(int i=1;i<=n;i++)
    {
        scanf("%lld",&a[i]);
        v.push_back(a[i]);
    }
    v.push_back(-1);
    sort(v.begin(),v.end());
    for(int i=1;i<=n;i++)
    {
        mp[v[i]]=i;
    }
    for(int i=1;i<=n;i++)
    {
        b[i]=mp[a[i]];
    }
    /*for(int i=1;i<=n;i++)
    {
        printf("%d ",b[i]);
    }
    printf("\n");*/
    fac[0]=1;
    for(int i=1;i<=300000;i++)
    {
        fac[i]=fac[i-1]*i;
        fac[i]%=1000000007;
    }
    for(int i=n;i>=1;i--)
    {
        update(b[i],1);
        c[i]=query(b[i]);
    }
    for(int i=1;i<=n;i++)
    {
        //printf("%d ",c[i]);
        ans+=(c[i]-1)*fac[n-i];
        ans%=1000000007;
    }
    printf("%lld\n",ans+1);
    //printf("\n");
}

Compilation message

Crypto.cpp: In function 'int main()':
Crypto.cpp:28:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   28 |     scanf("%lld",&n);
      |     ~~~~~^~~~~~~~~~~
Crypto.cpp:31:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   31 |         scanf("%lld",&a[i]);
      |         ~~~~~^~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 3 ms 2636 KB Output is correct
2 Correct 3 ms 2636 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 2636 KB Output is correct
2 Correct 3 ms 2636 KB Output is correct
3 Correct 3 ms 2636 KB Output is correct
4 Correct 4 ms 2636 KB Output is correct
5 Correct 3 ms 2636 KB Output is correct
6 Correct 3 ms 2636 KB Output is correct
7 Correct 4 ms 2636 KB Output is correct
8 Correct 3 ms 2636 KB Output is correct
9 Correct 4 ms 2636 KB Output is correct
10 Correct 3 ms 2636 KB Output is correct
11 Correct 3 ms 2636 KB Output is correct
12 Correct 3 ms 2636 KB Output is correct
13 Correct 3 ms 2636 KB Output is correct
14 Correct 3 ms 2636 KB Output is correct
15 Correct 3 ms 2636 KB Output is correct
16 Correct 3 ms 2636 KB Output is correct
17 Correct 3 ms 2636 KB Output is correct
18 Correct 4 ms 2636 KB Output is correct
19 Correct 3 ms 2636 KB Output is correct
20 Correct 3 ms 2636 KB Output is correct
21 Correct 3 ms 2636 KB Output is correct
22 Correct 3 ms 2636 KB Output is correct
23 Correct 3 ms 2596 KB Output is correct
24 Correct 3 ms 2636 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 2636 KB Output is correct
2 Correct 148 ms 33068 KB Output is correct
3 Correct 171 ms 33148 KB Output is correct
4 Correct 160 ms 33128 KB Output is correct
5 Correct 158 ms 33188 KB Output is correct
6 Correct 174 ms 33148 KB Output is correct
7 Correct 167 ms 33128 KB Output is correct
8 Correct 164 ms 33160 KB Output is correct
9 Correct 168 ms 33072 KB Output is correct
10 Correct 170 ms 33060 KB Output is correct
11 Correct 188 ms 33108 KB Output is correct
12 Correct 148 ms 33100 KB Output is correct
13 Correct 152 ms 33064 KB Output is correct
14 Correct 150 ms 33080 KB Output is correct
15 Correct 171 ms 33088 KB Output is correct
16 Correct 168 ms 33052 KB Output is correct
17 Correct 164 ms 33108 KB Output is correct
18 Correct 183 ms 33064 KB Output is correct
19 Correct 144 ms 33144 KB Output is correct
20 Correct 156 ms 33088 KB Output is correct
21 Correct 146 ms 33068 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 2636 KB Output is correct
2 Correct 160 ms 33116 KB Output is correct
3 Correct 146 ms 33092 KB Output is correct
4 Correct 201 ms 33060 KB Output is correct
5 Correct 150 ms 33144 KB Output is correct
6 Correct 149 ms 33036 KB Output is correct
7 Correct 171 ms 33100 KB Output is correct
8 Correct 183 ms 33076 KB Output is correct
9 Correct 159 ms 33100 KB Output is correct
10 Correct 167 ms 33116 KB Output is correct
11 Correct 153 ms 33064 KB Output is correct
12 Correct 154 ms 33164 KB Output is correct
13 Correct 178 ms 33276 KB Output is correct
14 Correct 173 ms 33084 KB Output is correct
15 Correct 153 ms 33152 KB Output is correct
16 Correct 152 ms 33124 KB Output is correct
17 Correct 170 ms 33168 KB Output is correct
18 Correct 159 ms 33076 KB Output is correct
19 Correct 151 ms 33148 KB Output is correct
20 Correct 146 ms 33108 KB Output is correct
21 Correct 159 ms 33096 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 2636 KB Output is correct
2 Correct 5 ms 2892 KB Output is correct
3 Correct 4 ms 2964 KB Output is correct
4 Correct 4 ms 2892 KB Output is correct
5 Correct 4 ms 2892 KB Output is correct
6 Correct 4 ms 2892 KB Output is correct
7 Correct 4 ms 2892 KB Output is correct
8 Correct 4 ms 2892 KB Output is correct
9 Correct 5 ms 2892 KB Output is correct
10 Correct 4 ms 2892 KB Output is correct
11 Correct 4 ms 2948 KB Output is correct
12 Correct 4 ms 2884 KB Output is correct
13 Correct 5 ms 2892 KB Output is correct
14 Correct 4 ms 2892 KB Output is correct
15 Incorrect 3 ms 2636 KB Output isn't correct
16 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 2636 KB Output is correct
2 Correct 3 ms 2636 KB Output is correct
3 Correct 3 ms 2636 KB Output is correct
4 Correct 4 ms 2636 KB Output is correct
5 Correct 3 ms 2636 KB Output is correct
6 Correct 3 ms 2636 KB Output is correct
7 Correct 4 ms 2636 KB Output is correct
8 Correct 3 ms 2636 KB Output is correct
9 Correct 4 ms 2636 KB Output is correct
10 Correct 3 ms 2636 KB Output is correct
11 Correct 3 ms 2636 KB Output is correct
12 Correct 3 ms 2636 KB Output is correct
13 Correct 3 ms 2636 KB Output is correct
14 Correct 3 ms 2636 KB Output is correct
15 Correct 3 ms 2636 KB Output is correct
16 Correct 3 ms 2636 KB Output is correct
17 Correct 3 ms 2636 KB Output is correct
18 Correct 4 ms 2636 KB Output is correct
19 Correct 3 ms 2636 KB Output is correct
20 Correct 3 ms 2636 KB Output is correct
21 Correct 3 ms 2636 KB Output is correct
22 Correct 3 ms 2636 KB Output is correct
23 Correct 3 ms 2596 KB Output is correct
24 Correct 3 ms 2636 KB Output is correct
25 Correct 3 ms 2636 KB Output is correct
26 Correct 5 ms 2892 KB Output is correct
27 Correct 4 ms 2964 KB Output is correct
28 Correct 4 ms 2892 KB Output is correct
29 Correct 4 ms 2892 KB Output is correct
30 Correct 4 ms 2892 KB Output is correct
31 Correct 4 ms 2892 KB Output is correct
32 Correct 4 ms 2892 KB Output is correct
33 Correct 5 ms 2892 KB Output is correct
34 Correct 4 ms 2892 KB Output is correct
35 Correct 4 ms 2948 KB Output is correct
36 Correct 4 ms 2884 KB Output is correct
37 Correct 5 ms 2892 KB Output is correct
38 Correct 4 ms 2892 KB Output is correct
39 Incorrect 3 ms 2636 KB Output isn't correct
40 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 2636 KB Output is correct
2 Correct 160 ms 33116 KB Output is correct
3 Correct 146 ms 33092 KB Output is correct
4 Correct 201 ms 33060 KB Output is correct
5 Correct 150 ms 33144 KB Output is correct
6 Correct 149 ms 33036 KB Output is correct
7 Correct 171 ms 33100 KB Output is correct
8 Correct 183 ms 33076 KB Output is correct
9 Correct 159 ms 33100 KB Output is correct
10 Correct 167 ms 33116 KB Output is correct
11 Correct 153 ms 33064 KB Output is correct
12 Correct 154 ms 33164 KB Output is correct
13 Correct 178 ms 33276 KB Output is correct
14 Correct 173 ms 33084 KB Output is correct
15 Correct 153 ms 33152 KB Output is correct
16 Correct 152 ms 33124 KB Output is correct
17 Correct 170 ms 33168 KB Output is correct
18 Correct 159 ms 33076 KB Output is correct
19 Correct 151 ms 33148 KB Output is correct
20 Correct 146 ms 33108 KB Output is correct
21 Correct 159 ms 33096 KB Output is correct
22 Correct 3 ms 2636 KB Output is correct
23 Correct 5 ms 2892 KB Output is correct
24 Correct 4 ms 2964 KB Output is correct
25 Correct 4 ms 2892 KB Output is correct
26 Correct 4 ms 2892 KB Output is correct
27 Correct 4 ms 2892 KB Output is correct
28 Correct 4 ms 2892 KB Output is correct
29 Correct 4 ms 2892 KB Output is correct
30 Correct 5 ms 2892 KB Output is correct
31 Correct 4 ms 2892 KB Output is correct
32 Correct 4 ms 2948 KB Output is correct
33 Correct 4 ms 2884 KB Output is correct
34 Correct 5 ms 2892 KB Output is correct
35 Correct 4 ms 2892 KB Output is correct
36 Incorrect 3 ms 2636 KB Output isn't correct
37 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 2636 KB Output is correct
2 Correct 3 ms 2636 KB Output is correct
3 Correct 3 ms 2636 KB Output is correct
4 Correct 4 ms 2636 KB Output is correct
5 Correct 3 ms 2636 KB Output is correct
6 Correct 3 ms 2636 KB Output is correct
7 Correct 4 ms 2636 KB Output is correct
8 Correct 3 ms 2636 KB Output is correct
9 Correct 4 ms 2636 KB Output is correct
10 Correct 3 ms 2636 KB Output is correct
11 Correct 3 ms 2636 KB Output is correct
12 Correct 3 ms 2636 KB Output is correct
13 Correct 3 ms 2636 KB Output is correct
14 Correct 3 ms 2636 KB Output is correct
15 Correct 3 ms 2636 KB Output is correct
16 Correct 3 ms 2636 KB Output is correct
17 Correct 3 ms 2636 KB Output is correct
18 Correct 4 ms 2636 KB Output is correct
19 Correct 3 ms 2636 KB Output is correct
20 Correct 3 ms 2636 KB Output is correct
21 Correct 3 ms 2636 KB Output is correct
22 Correct 3 ms 2636 KB Output is correct
23 Correct 3 ms 2596 KB Output is correct
24 Correct 3 ms 2636 KB Output is correct
25 Correct 3 ms 2636 KB Output is correct
26 Correct 148 ms 33068 KB Output is correct
27 Correct 171 ms 33148 KB Output is correct
28 Correct 160 ms 33128 KB Output is correct
29 Correct 158 ms 33188 KB Output is correct
30 Correct 174 ms 33148 KB Output is correct
31 Correct 167 ms 33128 KB Output is correct
32 Correct 164 ms 33160 KB Output is correct
33 Correct 168 ms 33072 KB Output is correct
34 Correct 170 ms 33060 KB Output is correct
35 Correct 188 ms 33108 KB Output is correct
36 Correct 148 ms 33100 KB Output is correct
37 Correct 152 ms 33064 KB Output is correct
38 Correct 150 ms 33080 KB Output is correct
39 Correct 171 ms 33088 KB Output is correct
40 Correct 168 ms 33052 KB Output is correct
41 Correct 164 ms 33108 KB Output is correct
42 Correct 183 ms 33064 KB Output is correct
43 Correct 144 ms 33144 KB Output is correct
44 Correct 156 ms 33088 KB Output is correct
45 Correct 146 ms 33068 KB Output is correct
46 Correct 3 ms 2636 KB Output is correct
47 Correct 160 ms 33116 KB Output is correct
48 Correct 146 ms 33092 KB Output is correct
49 Correct 201 ms 33060 KB Output is correct
50 Correct 150 ms 33144 KB Output is correct
51 Correct 149 ms 33036 KB Output is correct
52 Correct 171 ms 33100 KB Output is correct
53 Correct 183 ms 33076 KB Output is correct
54 Correct 159 ms 33100 KB Output is correct
55 Correct 167 ms 33116 KB Output is correct
56 Correct 153 ms 33064 KB Output is correct
57 Correct 154 ms 33164 KB Output is correct
58 Correct 178 ms 33276 KB Output is correct
59 Correct 173 ms 33084 KB Output is correct
60 Correct 153 ms 33152 KB Output is correct
61 Correct 152 ms 33124 KB Output is correct
62 Correct 170 ms 33168 KB Output is correct
63 Correct 159 ms 33076 KB Output is correct
64 Correct 151 ms 33148 KB Output is correct
65 Correct 146 ms 33108 KB Output is correct
66 Correct 159 ms 33096 KB Output is correct
67 Correct 3 ms 2636 KB Output is correct
68 Correct 5 ms 2892 KB Output is correct
69 Correct 4 ms 2964 KB Output is correct
70 Correct 4 ms 2892 KB Output is correct
71 Correct 4 ms 2892 KB Output is correct
72 Correct 4 ms 2892 KB Output is correct
73 Correct 4 ms 2892 KB Output is correct
74 Correct 4 ms 2892 KB Output is correct
75 Correct 5 ms 2892 KB Output is correct
76 Correct 4 ms 2892 KB Output is correct
77 Correct 4 ms 2948 KB Output is correct
78 Correct 4 ms 2884 KB Output is correct
79 Correct 5 ms 2892 KB Output is correct
80 Correct 4 ms 2892 KB Output is correct
81 Incorrect 3 ms 2636 KB Output isn't correct
82 Halted 0 ms 0 KB -