Submission #975500

# Submission time Handle Problem Language Result Execution time Memory
975500 2024-05-05T10:39:25 Z AliHasanli Cryptography (NOI20_crypto) C++17
25 / 100
318 ms 34100 KB
#include<bits/stdc++.h>
using namespace std;
map<int,int>mp;
long long fact[300005];
long long a[300005],b[300005],c[300005],seg[1200005];
long long query(long long n,long long l,long long r,long long ql,long long qr)
{
    if(l>r || ql>qr || r<ql || l>qr)return 0;
    if(ql<=l && r<=qr)return seg[n];
    return query(2*n,l,(l+r)/2,ql,qr)+query(2*n+1,(l+r)/2+1,r,ql,qr);
}
void update(long long n,long long l,long long r,long long pos)
{
    if(l>r || r<pos || l>pos)return;
    if(l==r){seg[n]=1;return;}
    update(2*n,l,(l+r)/2,pos),update(2*n+1,(l+r)/2+1,r,pos);
    seg[n]=seg[2*n]+seg[2*n+1];
}
void fac(long long n)
{
    fact[0]=1;
    for(long long i=1;i<=300004;i++)
    fact[i]=(i*fact[i-1])%1000000007;
}
int main()
{
    fac(300004);
    long long n;
    cin>>n;
    for(long long i=0;i<n;i++)
    {
        cin>>a[i];
        b[i]=a[i];
    }
    sort(b,b+n);
    for(long long i=1;i<=n;i++)
    mp[b[i-1]]=i;
    long long cavab=1;
    for(long long i=0;i<n;i++)
    {
        //cout<<fact[n-i-1]<<" "<<query(1,1,n,1,mp[a[i]])+1<<endl;
        long long sira=mp[a[i]]-query(1,1,n,1,mp[a[i]]);
        cavab+=(fact[n-i-1]*(sira-1))%1000000007;
        update(1,1,n,mp[a[i]]);
    }
    cout<<cavab;
    return 0;
}


/*
4!*(1-1)+3!(4-1)+2!(1-1)+1!(2-1)+0!(1-1)+1=18+1+1=20;

*/
# Verdict Execution time Memory Grader output
1 Correct 3 ms 9048 KB Output is correct
2 Correct 4 ms 8796 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 9048 KB Output is correct
2 Correct 4 ms 8796 KB Output is correct
3 Correct 3 ms 8796 KB Output is correct
4 Correct 4 ms 8792 KB Output is correct
5 Correct 4 ms 8796 KB Output is correct
6 Correct 3 ms 8792 KB Output is correct
7 Correct 3 ms 8796 KB Output is correct
8 Correct 3 ms 8792 KB Output is correct
9 Correct 4 ms 8792 KB Output is correct
10 Correct 3 ms 8796 KB Output is correct
11 Correct 4 ms 8796 KB Output is correct
12 Correct 3 ms 8796 KB Output is correct
13 Correct 3 ms 8796 KB Output is correct
14 Correct 4 ms 8796 KB Output is correct
15 Correct 3 ms 8788 KB Output is correct
16 Correct 3 ms 8796 KB Output is correct
17 Correct 3 ms 8796 KB Output is correct
18 Correct 4 ms 8796 KB Output is correct
19 Correct 3 ms 8796 KB Output is correct
20 Correct 4 ms 8796 KB Output is correct
21 Correct 3 ms 8796 KB Output is correct
22 Correct 4 ms 8796 KB Output is correct
23 Correct 3 ms 8796 KB Output is correct
24 Correct 3 ms 8796 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 8796 KB Output is correct
2 Incorrect 318 ms 34100 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 8792 KB Output is correct
2 Correct 275 ms 32976 KB Output is correct
3 Correct 271 ms 32960 KB Output is correct
4 Correct 278 ms 33024 KB Output is correct
5 Correct 278 ms 32924 KB Output is correct
6 Correct 276 ms 33080 KB Output is correct
7 Correct 269 ms 32848 KB Output is correct
8 Correct 273 ms 32832 KB Output is correct
9 Correct 276 ms 32960 KB Output is correct
10 Correct 275 ms 32852 KB Output is correct
11 Correct 279 ms 33212 KB Output is correct
12 Correct 270 ms 32824 KB Output is correct
13 Correct 268 ms 33132 KB Output is correct
14 Correct 279 ms 32780 KB Output is correct
15 Correct 268 ms 32964 KB Output is correct
16 Correct 277 ms 33112 KB Output is correct
17 Correct 272 ms 32824 KB Output is correct
18 Correct 274 ms 33104 KB Output is correct
19 Correct 280 ms 32948 KB Output is correct
20 Correct 279 ms 32948 KB Output is correct
21 Correct 271 ms 32848 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 8792 KB Output is correct
2 Incorrect 6 ms 8796 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 9048 KB Output is correct
2 Correct 4 ms 8796 KB Output is correct
3 Correct 3 ms 8796 KB Output is correct
4 Correct 4 ms 8792 KB Output is correct
5 Correct 4 ms 8796 KB Output is correct
6 Correct 3 ms 8792 KB Output is correct
7 Correct 3 ms 8796 KB Output is correct
8 Correct 3 ms 8792 KB Output is correct
9 Correct 4 ms 8792 KB Output is correct
10 Correct 3 ms 8796 KB Output is correct
11 Correct 4 ms 8796 KB Output is correct
12 Correct 3 ms 8796 KB Output is correct
13 Correct 3 ms 8796 KB Output is correct
14 Correct 4 ms 8796 KB Output is correct
15 Correct 3 ms 8788 KB Output is correct
16 Correct 3 ms 8796 KB Output is correct
17 Correct 3 ms 8796 KB Output is correct
18 Correct 4 ms 8796 KB Output is correct
19 Correct 3 ms 8796 KB Output is correct
20 Correct 4 ms 8796 KB Output is correct
21 Correct 3 ms 8796 KB Output is correct
22 Correct 4 ms 8796 KB Output is correct
23 Correct 3 ms 8796 KB Output is correct
24 Correct 3 ms 8796 KB Output is correct
25 Correct 3 ms 8792 KB Output is correct
26 Incorrect 6 ms 8796 KB Output isn't correct
27 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 8792 KB Output is correct
2 Correct 275 ms 32976 KB Output is correct
3 Correct 271 ms 32960 KB Output is correct
4 Correct 278 ms 33024 KB Output is correct
5 Correct 278 ms 32924 KB Output is correct
6 Correct 276 ms 33080 KB Output is correct
7 Correct 269 ms 32848 KB Output is correct
8 Correct 273 ms 32832 KB Output is correct
9 Correct 276 ms 32960 KB Output is correct
10 Correct 275 ms 32852 KB Output is correct
11 Correct 279 ms 33212 KB Output is correct
12 Correct 270 ms 32824 KB Output is correct
13 Correct 268 ms 33132 KB Output is correct
14 Correct 279 ms 32780 KB Output is correct
15 Correct 268 ms 32964 KB Output is correct
16 Correct 277 ms 33112 KB Output is correct
17 Correct 272 ms 32824 KB Output is correct
18 Correct 274 ms 33104 KB Output is correct
19 Correct 280 ms 32948 KB Output is correct
20 Correct 279 ms 32948 KB Output is correct
21 Correct 271 ms 32848 KB Output is correct
22 Correct 3 ms 8792 KB Output is correct
23 Incorrect 6 ms 8796 KB Output isn't correct
24 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 9048 KB Output is correct
2 Correct 4 ms 8796 KB Output is correct
3 Correct 3 ms 8796 KB Output is correct
4 Correct 4 ms 8792 KB Output is correct
5 Correct 4 ms 8796 KB Output is correct
6 Correct 3 ms 8792 KB Output is correct
7 Correct 3 ms 8796 KB Output is correct
8 Correct 3 ms 8792 KB Output is correct
9 Correct 4 ms 8792 KB Output is correct
10 Correct 3 ms 8796 KB Output is correct
11 Correct 4 ms 8796 KB Output is correct
12 Correct 3 ms 8796 KB Output is correct
13 Correct 3 ms 8796 KB Output is correct
14 Correct 4 ms 8796 KB Output is correct
15 Correct 3 ms 8788 KB Output is correct
16 Correct 3 ms 8796 KB Output is correct
17 Correct 3 ms 8796 KB Output is correct
18 Correct 4 ms 8796 KB Output is correct
19 Correct 3 ms 8796 KB Output is correct
20 Correct 4 ms 8796 KB Output is correct
21 Correct 3 ms 8796 KB Output is correct
22 Correct 4 ms 8796 KB Output is correct
23 Correct 3 ms 8796 KB Output is correct
24 Correct 3 ms 8796 KB Output is correct
25 Correct 4 ms 8796 KB Output is correct
26 Incorrect 318 ms 34100 KB Output isn't correct
27 Halted 0 ms 0 KB -