Submission #728702

# Submission time Handle Problem Language Result Execution time Memory
728702 2023-04-22T21:37:47 Z MilosMilutinovic Mountains (NOI20_mountains) C++14
100 / 100
183 ms 12476 KB
#include <bits/stdc++.h>
using namespace std;

int n,fenv[300005],L[300005];
long long h[300005];

void compress()
{
    vector<long long> xs;
    for(int i=1;i<=n;i++) xs.push_back(h[i]);
    sort(xs.begin(),xs.end());
    xs.erase(unique(xs.begin(),xs.end()),xs.end());
    for(int i=1;i<=n;i++) h[i]=(int)(lower_bound(xs.begin(),xs.end(),h[i])-xs.begin())+1;
}

void update(int x)
{
    for(int i=x;i<=300000;i+=i&-i) fenv[i]+=1;
}
int query(int x)
{
    int res=0;
    for(int i=x;i>=1;i-=i&-i) res+=fenv[i];
    return res;
}

signed main()
{
    scanf("%d",&n);
    for(int i=1;i<=n;i++) scanf("%lld",&h[i]);
    compress();
    for(int i=1;i<=n;i++) L[i]=query(h[i]-1),update(h[i]);
    for(int i=0;i<=300000;i++) fenv[i]=0;
    long long ans=0;
    for(int i=n;i>=1;i--) ans+=1ll*L[i]*query(h[i]-1),update(h[i]);
    printf("%lld",ans);
}

Compilation message

Mountains.cpp: In function 'int main()':
Mountains.cpp:29:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   29 |     scanf("%d",&n);
      |     ~~~~~^~~~~~~~~
Mountains.cpp:30:32: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   30 |     for(int i=1;i<=n;i++) scanf("%lld",&h[i]);
      |                           ~~~~~^~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1400 KB Output is correct
2 Correct 94 ms 12376 KB Output is correct
3 Correct 87 ms 12324 KB Output is correct
4 Correct 92 ms 12416 KB Output is correct
5 Correct 86 ms 12436 KB Output is correct
6 Correct 92 ms 12452 KB Output is correct
7 Correct 91 ms 12348 KB Output is correct
8 Correct 91 ms 12400 KB Output is correct
9 Correct 89 ms 12388 KB Output is correct
10 Correct 91 ms 12476 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 55 ms 7468 KB Output is correct
2 Correct 57 ms 7388 KB Output is correct
3 Correct 69 ms 7464 KB Output is correct
4 Correct 56 ms 7368 KB Output is correct
5 Correct 64 ms 7416 KB Output is correct
6 Correct 54 ms 7488 KB Output is correct
7 Correct 55 ms 7484 KB Output is correct
8 Correct 69 ms 7468 KB Output is correct
9 Correct 53 ms 7424 KB Output is correct
10 Correct 1 ms 1468 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 55 ms 7468 KB Output is correct
2 Correct 57 ms 7388 KB Output is correct
3 Correct 69 ms 7464 KB Output is correct
4 Correct 56 ms 7368 KB Output is correct
5 Correct 64 ms 7416 KB Output is correct
6 Correct 54 ms 7488 KB Output is correct
7 Correct 55 ms 7484 KB Output is correct
8 Correct 69 ms 7468 KB Output is correct
9 Correct 53 ms 7424 KB Output is correct
10 Correct 1 ms 1468 KB Output is correct
11 Correct 72 ms 7712 KB Output is correct
12 Correct 68 ms 7648 KB Output is correct
13 Correct 68 ms 7648 KB Output is correct
14 Correct 71 ms 7748 KB Output is correct
15 Correct 81 ms 7716 KB Output is correct
16 Correct 71 ms 7740 KB Output is correct
17 Correct 66 ms 7672 KB Output is correct
18 Correct 51 ms 7656 KB Output is correct
19 Correct 50 ms 7744 KB Output is correct
20 Correct 1 ms 1492 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1492 KB Output is correct
2 Correct 2 ms 1492 KB Output is correct
3 Correct 1 ms 1492 KB Output is correct
4 Correct 1 ms 1492 KB Output is correct
5 Correct 1 ms 1536 KB Output is correct
6 Correct 1 ms 1492 KB Output is correct
7 Correct 2 ms 1428 KB Output is correct
8 Correct 2 ms 1492 KB Output is correct
9 Correct 1 ms 1492 KB Output is correct
10 Correct 1 ms 1492 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1492 KB Output is correct
2 Correct 2 ms 1492 KB Output is correct
3 Correct 1 ms 1492 KB Output is correct
4 Correct 1 ms 1492 KB Output is correct
5 Correct 1 ms 1536 KB Output is correct
6 Correct 1 ms 1492 KB Output is correct
7 Correct 2 ms 1428 KB Output is correct
8 Correct 2 ms 1492 KB Output is correct
9 Correct 1 ms 1492 KB Output is correct
10 Correct 1 ms 1492 KB Output is correct
11 Correct 5 ms 1924 KB Output is correct
12 Correct 6 ms 1904 KB Output is correct
13 Correct 7 ms 1924 KB Output is correct
14 Correct 5 ms 1924 KB Output is correct
15 Correct 5 ms 1904 KB Output is correct
16 Correct 4 ms 1924 KB Output is correct
17 Correct 5 ms 1924 KB Output is correct
18 Correct 5 ms 1924 KB Output is correct
19 Correct 3 ms 1668 KB Output is correct
20 Correct 1 ms 1492 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 55 ms 7468 KB Output is correct
2 Correct 57 ms 7388 KB Output is correct
3 Correct 69 ms 7464 KB Output is correct
4 Correct 56 ms 7368 KB Output is correct
5 Correct 64 ms 7416 KB Output is correct
6 Correct 54 ms 7488 KB Output is correct
7 Correct 55 ms 7484 KB Output is correct
8 Correct 69 ms 7468 KB Output is correct
9 Correct 53 ms 7424 KB Output is correct
10 Correct 1 ms 1468 KB Output is correct
11 Correct 72 ms 7712 KB Output is correct
12 Correct 68 ms 7648 KB Output is correct
13 Correct 68 ms 7648 KB Output is correct
14 Correct 71 ms 7748 KB Output is correct
15 Correct 81 ms 7716 KB Output is correct
16 Correct 71 ms 7740 KB Output is correct
17 Correct 66 ms 7672 KB Output is correct
18 Correct 51 ms 7656 KB Output is correct
19 Correct 50 ms 7744 KB Output is correct
20 Correct 1 ms 1492 KB Output is correct
21 Correct 109 ms 8620 KB Output is correct
22 Correct 112 ms 8616 KB Output is correct
23 Correct 112 ms 8508 KB Output is correct
24 Correct 110 ms 8580 KB Output is correct
25 Correct 141 ms 8500 KB Output is correct
26 Correct 107 ms 8536 KB Output is correct
27 Correct 107 ms 8528 KB Output is correct
28 Correct 65 ms 8600 KB Output is correct
29 Correct 68 ms 8532 KB Output is correct
30 Correct 1 ms 1492 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1400 KB Output is correct
2 Correct 94 ms 12376 KB Output is correct
3 Correct 87 ms 12324 KB Output is correct
4 Correct 92 ms 12416 KB Output is correct
5 Correct 86 ms 12436 KB Output is correct
6 Correct 92 ms 12452 KB Output is correct
7 Correct 91 ms 12348 KB Output is correct
8 Correct 91 ms 12400 KB Output is correct
9 Correct 89 ms 12388 KB Output is correct
10 Correct 91 ms 12476 KB Output is correct
11 Correct 55 ms 7468 KB Output is correct
12 Correct 57 ms 7388 KB Output is correct
13 Correct 69 ms 7464 KB Output is correct
14 Correct 56 ms 7368 KB Output is correct
15 Correct 64 ms 7416 KB Output is correct
16 Correct 54 ms 7488 KB Output is correct
17 Correct 55 ms 7484 KB Output is correct
18 Correct 69 ms 7468 KB Output is correct
19 Correct 53 ms 7424 KB Output is correct
20 Correct 1 ms 1468 KB Output is correct
21 Correct 72 ms 7712 KB Output is correct
22 Correct 68 ms 7648 KB Output is correct
23 Correct 68 ms 7648 KB Output is correct
24 Correct 71 ms 7748 KB Output is correct
25 Correct 81 ms 7716 KB Output is correct
26 Correct 71 ms 7740 KB Output is correct
27 Correct 66 ms 7672 KB Output is correct
28 Correct 51 ms 7656 KB Output is correct
29 Correct 50 ms 7744 KB Output is correct
30 Correct 1 ms 1492 KB Output is correct
31 Correct 1 ms 1492 KB Output is correct
32 Correct 2 ms 1492 KB Output is correct
33 Correct 1 ms 1492 KB Output is correct
34 Correct 1 ms 1492 KB Output is correct
35 Correct 1 ms 1536 KB Output is correct
36 Correct 1 ms 1492 KB Output is correct
37 Correct 2 ms 1428 KB Output is correct
38 Correct 2 ms 1492 KB Output is correct
39 Correct 1 ms 1492 KB Output is correct
40 Correct 1 ms 1492 KB Output is correct
41 Correct 5 ms 1924 KB Output is correct
42 Correct 6 ms 1904 KB Output is correct
43 Correct 7 ms 1924 KB Output is correct
44 Correct 5 ms 1924 KB Output is correct
45 Correct 5 ms 1904 KB Output is correct
46 Correct 4 ms 1924 KB Output is correct
47 Correct 5 ms 1924 KB Output is correct
48 Correct 5 ms 1924 KB Output is correct
49 Correct 3 ms 1668 KB Output is correct
50 Correct 1 ms 1492 KB Output is correct
51 Correct 109 ms 8620 KB Output is correct
52 Correct 112 ms 8616 KB Output is correct
53 Correct 112 ms 8508 KB Output is correct
54 Correct 110 ms 8580 KB Output is correct
55 Correct 141 ms 8500 KB Output is correct
56 Correct 107 ms 8536 KB Output is correct
57 Correct 107 ms 8528 KB Output is correct
58 Correct 65 ms 8600 KB Output is correct
59 Correct 68 ms 8532 KB Output is correct
60 Correct 1 ms 1492 KB Output is correct
61 Correct 144 ms 12400 KB Output is correct
62 Correct 144 ms 12424 KB Output is correct
63 Correct 140 ms 12440 KB Output is correct
64 Correct 140 ms 12320 KB Output is correct
65 Correct 141 ms 12352 KB Output is correct
66 Correct 183 ms 12352 KB Output is correct
67 Correct 144 ms 12420 KB Output is correct
68 Correct 134 ms 12440 KB Output is correct
69 Correct 114 ms 8660 KB Output is correct
70 Correct 1 ms 1492 KB Output is correct