Submission #645903

# Submission time Handle Problem Language Result Execution time Memory
645903 2022-09-28T09:06:40 Z JJAnawat Mountains (NOI20_mountains) C++14
100 / 100
279 ms 27400 KB
#include<bits/stdc++.h>

using namespace std;

const int MXN=3e5+5;
long long n;
long long ar[MXN],pre[MXN],pos[MXN];
vector<long long> v;
unordered_map<long long,int> ump;
long long fw[2][MXN];

void upd(int o,int x){
    for(;x<MXN;x+=x&-x)
        fw[o][x]++;
}

long long qr(int o,int x){
    long long sum=0;
    for(;x>0;x-=x&-x)
        sum+=fw[o][x];
    return sum;
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    cin >> n;
    for(int i=1;i<=n;i++){
        cin >> ar[i];
        v.push_back(ar[i]);
    }
    sort(v.begin(),v.end());
    v.resize(unique(v.begin(),v.end())-v.begin());
    for(int i=1;i<=v.size();i++){
        ump[v[i-1]]=i;
    }
    for(int i=1;i<=n;i++){
        ar[i]=ump[ar[i]];
        pre[i]=qr(0,ar[i]-1);
        upd(0,ar[i]);
    }
    for(int i=n;i>=1;i--){
        pos[i]=qr(1,ar[i]-1);
        upd(1,ar[i]);
    }

    long long ans=0;
    for(int i=1;i<=n;i++){
        ans+=(pre[i]*pos[i]);
    }
    cout << ans;
}

Compilation message

Mountains.cpp: In function 'int main()':
Mountains.cpp:35:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   35 |     for(int i=1;i<=v.size();i++){
      |                 ~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 176 ms 27348 KB Output is correct
3 Correct 187 ms 27400 KB Output is correct
4 Correct 174 ms 27260 KB Output is correct
5 Correct 177 ms 27336 KB Output is correct
6 Correct 183 ms 27320 KB Output is correct
7 Correct 169 ms 27268 KB Output is correct
8 Correct 192 ms 27320 KB Output is correct
9 Correct 99 ms 19168 KB Output is correct
10 Correct 94 ms 19184 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 57 ms 10332 KB Output is correct
2 Correct 53 ms 10496 KB Output is correct
3 Correct 55 ms 10444 KB Output is correct
4 Correct 52 ms 10476 KB Output is correct
5 Correct 52 ms 10424 KB Output is correct
6 Correct 51 ms 10504 KB Output is correct
7 Correct 53 ms 10452 KB Output is correct
8 Correct 57 ms 10512 KB Output is correct
9 Correct 49 ms 10460 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 57 ms 10332 KB Output is correct
2 Correct 53 ms 10496 KB Output is correct
3 Correct 55 ms 10444 KB Output is correct
4 Correct 52 ms 10476 KB Output is correct
5 Correct 52 ms 10424 KB Output is correct
6 Correct 51 ms 10504 KB Output is correct
7 Correct 53 ms 10452 KB Output is correct
8 Correct 57 ms 10512 KB Output is correct
9 Correct 49 ms 10460 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 54 ms 10552 KB Output is correct
12 Correct 60 ms 10664 KB Output is correct
13 Correct 57 ms 10512 KB Output is correct
14 Correct 54 ms 10536 KB Output is correct
15 Correct 60 ms 10552 KB Output is correct
16 Correct 56 ms 10552 KB Output is correct
17 Correct 61 ms 10504 KB Output is correct
18 Correct 49 ms 10572 KB Output is correct
19 Correct 48 ms 10664 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 468 KB Output is correct
2 Correct 1 ms 468 KB Output is correct
3 Correct 1 ms 468 KB Output is correct
4 Correct 1 ms 468 KB Output is correct
5 Correct 1 ms 468 KB Output is correct
6 Correct 1 ms 468 KB Output is correct
7 Correct 1 ms 468 KB Output is correct
8 Correct 1 ms 468 KB Output is correct
9 Correct 1 ms 468 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 468 KB Output is correct
2 Correct 1 ms 468 KB Output is correct
3 Correct 1 ms 468 KB Output is correct
4 Correct 1 ms 468 KB Output is correct
5 Correct 1 ms 468 KB Output is correct
6 Correct 1 ms 468 KB Output is correct
7 Correct 1 ms 468 KB Output is correct
8 Correct 1 ms 468 KB Output is correct
9 Correct 1 ms 468 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 7 ms 1464 KB Output is correct
12 Correct 5 ms 1456 KB Output is correct
13 Correct 5 ms 1364 KB Output is correct
14 Correct 5 ms 1460 KB Output is correct
15 Correct 5 ms 1460 KB Output is correct
16 Correct 6 ms 1364 KB Output is correct
17 Correct 6 ms 1376 KB Output is correct
18 Correct 4 ms 1108 KB Output is correct
19 Correct 3 ms 852 KB Output is correct
20 Correct 1 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 57 ms 10332 KB Output is correct
2 Correct 53 ms 10496 KB Output is correct
3 Correct 55 ms 10444 KB Output is correct
4 Correct 52 ms 10476 KB Output is correct
5 Correct 52 ms 10424 KB Output is correct
6 Correct 51 ms 10504 KB Output is correct
7 Correct 53 ms 10452 KB Output is correct
8 Correct 57 ms 10512 KB Output is correct
9 Correct 49 ms 10460 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 54 ms 10552 KB Output is correct
12 Correct 60 ms 10664 KB Output is correct
13 Correct 57 ms 10512 KB Output is correct
14 Correct 54 ms 10536 KB Output is correct
15 Correct 60 ms 10552 KB Output is correct
16 Correct 56 ms 10552 KB Output is correct
17 Correct 61 ms 10504 KB Output is correct
18 Correct 49 ms 10572 KB Output is correct
19 Correct 48 ms 10664 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 110 ms 16564 KB Output is correct
22 Correct 96 ms 16556 KB Output is correct
23 Correct 95 ms 16504 KB Output is correct
24 Correct 122 ms 16480 KB Output is correct
25 Correct 103 ms 16524 KB Output is correct
26 Correct 128 ms 16508 KB Output is correct
27 Correct 108 ms 16560 KB Output is correct
28 Correct 64 ms 16564 KB Output is correct
29 Correct 67 ms 16504 KB Output is correct
30 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 176 ms 27348 KB Output is correct
3 Correct 187 ms 27400 KB Output is correct
4 Correct 174 ms 27260 KB Output is correct
5 Correct 177 ms 27336 KB Output is correct
6 Correct 183 ms 27320 KB Output is correct
7 Correct 169 ms 27268 KB Output is correct
8 Correct 192 ms 27320 KB Output is correct
9 Correct 99 ms 19168 KB Output is correct
10 Correct 94 ms 19184 KB Output is correct
11 Correct 57 ms 10332 KB Output is correct
12 Correct 53 ms 10496 KB Output is correct
13 Correct 55 ms 10444 KB Output is correct
14 Correct 52 ms 10476 KB Output is correct
15 Correct 52 ms 10424 KB Output is correct
16 Correct 51 ms 10504 KB Output is correct
17 Correct 53 ms 10452 KB Output is correct
18 Correct 57 ms 10512 KB Output is correct
19 Correct 49 ms 10460 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 54 ms 10552 KB Output is correct
22 Correct 60 ms 10664 KB Output is correct
23 Correct 57 ms 10512 KB Output is correct
24 Correct 54 ms 10536 KB Output is correct
25 Correct 60 ms 10552 KB Output is correct
26 Correct 56 ms 10552 KB Output is correct
27 Correct 61 ms 10504 KB Output is correct
28 Correct 49 ms 10572 KB Output is correct
29 Correct 48 ms 10664 KB Output is correct
30 Correct 1 ms 340 KB Output is correct
31 Correct 1 ms 468 KB Output is correct
32 Correct 1 ms 468 KB Output is correct
33 Correct 1 ms 468 KB Output is correct
34 Correct 1 ms 468 KB Output is correct
35 Correct 1 ms 468 KB Output is correct
36 Correct 1 ms 468 KB Output is correct
37 Correct 1 ms 468 KB Output is correct
38 Correct 1 ms 468 KB Output is correct
39 Correct 1 ms 468 KB Output is correct
40 Correct 1 ms 332 KB Output is correct
41 Correct 7 ms 1464 KB Output is correct
42 Correct 5 ms 1456 KB Output is correct
43 Correct 5 ms 1364 KB Output is correct
44 Correct 5 ms 1460 KB Output is correct
45 Correct 5 ms 1460 KB Output is correct
46 Correct 6 ms 1364 KB Output is correct
47 Correct 6 ms 1376 KB Output is correct
48 Correct 4 ms 1108 KB Output is correct
49 Correct 3 ms 852 KB Output is correct
50 Correct 1 ms 332 KB Output is correct
51 Correct 110 ms 16564 KB Output is correct
52 Correct 96 ms 16556 KB Output is correct
53 Correct 95 ms 16504 KB Output is correct
54 Correct 122 ms 16480 KB Output is correct
55 Correct 103 ms 16524 KB Output is correct
56 Correct 128 ms 16508 KB Output is correct
57 Correct 108 ms 16560 KB Output is correct
58 Correct 64 ms 16564 KB Output is correct
59 Correct 67 ms 16504 KB Output is correct
60 Correct 1 ms 340 KB Output is correct
61 Correct 254 ms 27092 KB Output is correct
62 Correct 243 ms 27192 KB Output is correct
63 Correct 247 ms 27188 KB Output is correct
64 Correct 255 ms 27148 KB Output is correct
65 Correct 270 ms 27180 KB Output is correct
66 Correct 273 ms 27120 KB Output is correct
67 Correct 279 ms 27104 KB Output is correct
68 Correct 174 ms 19124 KB Output is correct
69 Correct 124 ms 17836 KB Output is correct
70 Correct 1 ms 340 KB Output is correct