Submission #538169

# Submission time Handle Problem Language Result Execution time Memory
538169 2022-03-16T07:16:38 Z ToroTN Mountains (NOI20_mountains) C++14
100 / 100
651 ms 53332 KB
#include<bits/stdc++.h>
using namespace std;
long long n,a[300005],kk=0,node,fen[300005],cnt,mount=0;
unordered_map<long long,long long> mp;
set<long long> s;
vector<long long> v[300005];
void up(long long u,long long val)
{
    while(u<=n)
    {
        fen[u]+=val;
        u+=(u&(-u));
    }
}
long long qq(long long u)
{
    cnt=0;
    while(u>0)
    {
        cnt+=fen[u];
        u-=(u&(-u));
    }
    return cnt;
}
long long query(long long l,long long r)
{
    return qq(r)-qq(l-1);
}
int main()
{
    scanf("%lld",&n);
    for(int i=1;i<=n;i++)
    {
        scanf("%lld",&a[i]);
        s.insert(a[i]);
    }
    for(auto it=s.begin();it!=s.end();it++)
    {
        if(mp[*it]==0)
        {
            ++kk;
            mp[*it]=kk;
        }
    }
    for(int i=1;i<=n;i++)
    {
        v[mp[a[i]]].push_back(i);
    }
    for(int i=1;i<=n;i++)
    {
        //printf("%d\n",i);
        for(int j=0;j<v[i].size();j++)
        {
            node=v[i][j];
            //printf("%lld ",node);
            mount+=query(1,node-1)*query(node+1,n);
        }
        //printf("\n");
        for(int j=0;j<v[i].size();j++)
        {
            node=v[i][j];
            up(node,1);
        }
    }
    printf("%lld\n",mount);
}

Compilation message

Mountains.cpp: In function 'int main()':
Mountains.cpp:52:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   52 |         for(int j=0;j<v[i].size();j++)
      |                     ~^~~~~~~~~~~~
Mountains.cpp:59:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   59 |         for(int j=0;j<v[i].size();j++)
      |                     ~^~~~~~~~~~~~
Mountains.cpp:31:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   31 |     scanf("%lld",&n);
      |     ~~~~~^~~~~~~~~~~
Mountains.cpp:34:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   34 |         scanf("%lld",&a[i]);
      |         ~~~~~^~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 4 ms 7252 KB Output is correct
2 Correct 285 ms 53220 KB Output is correct
3 Correct 342 ms 53136 KB Output is correct
4 Correct 289 ms 53152 KB Output is correct
5 Correct 325 ms 53200 KB Output is correct
6 Correct 294 ms 53160 KB Output is correct
7 Correct 362 ms 53124 KB Output is correct
8 Correct 284 ms 53120 KB Output is correct
9 Correct 178 ms 36648 KB Output is correct
10 Correct 167 ms 36768 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 49 ms 15104 KB Output is correct
2 Correct 51 ms 15164 KB Output is correct
3 Correct 57 ms 15196 KB Output is correct
4 Correct 69 ms 15060 KB Output is correct
5 Correct 51 ms 15024 KB Output is correct
6 Correct 47 ms 15200 KB Output is correct
7 Correct 46 ms 15140 KB Output is correct
8 Correct 44 ms 15092 KB Output is correct
9 Correct 46 ms 15084 KB Output is correct
10 Correct 4 ms 7252 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 49 ms 15104 KB Output is correct
2 Correct 51 ms 15164 KB Output is correct
3 Correct 57 ms 15196 KB Output is correct
4 Correct 69 ms 15060 KB Output is correct
5 Correct 51 ms 15024 KB Output is correct
6 Correct 47 ms 15200 KB Output is correct
7 Correct 46 ms 15140 KB Output is correct
8 Correct 44 ms 15092 KB Output is correct
9 Correct 46 ms 15084 KB Output is correct
10 Correct 4 ms 7252 KB Output is correct
11 Correct 68 ms 16164 KB Output is correct
12 Correct 68 ms 16188 KB Output is correct
13 Correct 60 ms 16332 KB Output is correct
14 Correct 57 ms 16168 KB Output is correct
15 Correct 59 ms 16208 KB Output is correct
16 Correct 68 ms 16204 KB Output is correct
17 Correct 80 ms 16260 KB Output is correct
18 Correct 49 ms 15564 KB Output is correct
19 Correct 48 ms 15548 KB Output is correct
20 Correct 4 ms 7252 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 7380 KB Output is correct
2 Correct 4 ms 7380 KB Output is correct
3 Correct 6 ms 7380 KB Output is correct
4 Correct 6 ms 7380 KB Output is correct
5 Correct 5 ms 7380 KB Output is correct
6 Correct 5 ms 7352 KB Output is correct
7 Correct 5 ms 7380 KB Output is correct
8 Correct 4 ms 7380 KB Output is correct
9 Correct 4 ms 7380 KB Output is correct
10 Correct 4 ms 7352 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 7380 KB Output is correct
2 Correct 4 ms 7380 KB Output is correct
3 Correct 6 ms 7380 KB Output is correct
4 Correct 6 ms 7380 KB Output is correct
5 Correct 5 ms 7380 KB Output is correct
6 Correct 5 ms 7352 KB Output is correct
7 Correct 5 ms 7380 KB Output is correct
8 Correct 4 ms 7380 KB Output is correct
9 Correct 4 ms 7380 KB Output is correct
10 Correct 4 ms 7352 KB Output is correct
11 Correct 14 ms 8772 KB Output is correct
12 Correct 14 ms 8788 KB Output is correct
13 Correct 12 ms 8784 KB Output is correct
14 Correct 13 ms 8784 KB Output is correct
15 Correct 15 ms 8820 KB Output is correct
16 Correct 14 ms 8776 KB Output is correct
17 Correct 13 ms 8848 KB Output is correct
18 Correct 10 ms 8148 KB Output is correct
19 Correct 7 ms 7636 KB Output is correct
20 Correct 4 ms 7252 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 49 ms 15104 KB Output is correct
2 Correct 51 ms 15164 KB Output is correct
3 Correct 57 ms 15196 KB Output is correct
4 Correct 69 ms 15060 KB Output is correct
5 Correct 51 ms 15024 KB Output is correct
6 Correct 47 ms 15200 KB Output is correct
7 Correct 46 ms 15140 KB Output is correct
8 Correct 44 ms 15092 KB Output is correct
9 Correct 46 ms 15084 KB Output is correct
10 Correct 4 ms 7252 KB Output is correct
11 Correct 68 ms 16164 KB Output is correct
12 Correct 68 ms 16188 KB Output is correct
13 Correct 60 ms 16332 KB Output is correct
14 Correct 57 ms 16168 KB Output is correct
15 Correct 59 ms 16208 KB Output is correct
16 Correct 68 ms 16204 KB Output is correct
17 Correct 80 ms 16260 KB Output is correct
18 Correct 49 ms 15564 KB Output is correct
19 Correct 48 ms 15548 KB Output is correct
20 Correct 4 ms 7252 KB Output is correct
21 Correct 202 ms 27380 KB Output is correct
22 Correct 287 ms 27476 KB Output is correct
23 Correct 206 ms 27388 KB Output is correct
24 Correct 223 ms 27480 KB Output is correct
25 Correct 309 ms 27400 KB Output is correct
26 Correct 218 ms 27492 KB Output is correct
27 Correct 270 ms 27496 KB Output is correct
28 Correct 120 ms 26912 KB Output is correct
29 Correct 116 ms 26956 KB Output is correct
30 Correct 4 ms 7252 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 7252 KB Output is correct
2 Correct 285 ms 53220 KB Output is correct
3 Correct 342 ms 53136 KB Output is correct
4 Correct 289 ms 53152 KB Output is correct
5 Correct 325 ms 53200 KB Output is correct
6 Correct 294 ms 53160 KB Output is correct
7 Correct 362 ms 53124 KB Output is correct
8 Correct 284 ms 53120 KB Output is correct
9 Correct 178 ms 36648 KB Output is correct
10 Correct 167 ms 36768 KB Output is correct
11 Correct 49 ms 15104 KB Output is correct
12 Correct 51 ms 15164 KB Output is correct
13 Correct 57 ms 15196 KB Output is correct
14 Correct 69 ms 15060 KB Output is correct
15 Correct 51 ms 15024 KB Output is correct
16 Correct 47 ms 15200 KB Output is correct
17 Correct 46 ms 15140 KB Output is correct
18 Correct 44 ms 15092 KB Output is correct
19 Correct 46 ms 15084 KB Output is correct
20 Correct 4 ms 7252 KB Output is correct
21 Correct 68 ms 16164 KB Output is correct
22 Correct 68 ms 16188 KB Output is correct
23 Correct 60 ms 16332 KB Output is correct
24 Correct 57 ms 16168 KB Output is correct
25 Correct 59 ms 16208 KB Output is correct
26 Correct 68 ms 16204 KB Output is correct
27 Correct 80 ms 16260 KB Output is correct
28 Correct 49 ms 15564 KB Output is correct
29 Correct 48 ms 15548 KB Output is correct
30 Correct 4 ms 7252 KB Output is correct
31 Correct 4 ms 7380 KB Output is correct
32 Correct 4 ms 7380 KB Output is correct
33 Correct 6 ms 7380 KB Output is correct
34 Correct 6 ms 7380 KB Output is correct
35 Correct 5 ms 7380 KB Output is correct
36 Correct 5 ms 7352 KB Output is correct
37 Correct 5 ms 7380 KB Output is correct
38 Correct 4 ms 7380 KB Output is correct
39 Correct 4 ms 7380 KB Output is correct
40 Correct 4 ms 7352 KB Output is correct
41 Correct 14 ms 8772 KB Output is correct
42 Correct 14 ms 8788 KB Output is correct
43 Correct 12 ms 8784 KB Output is correct
44 Correct 13 ms 8784 KB Output is correct
45 Correct 15 ms 8820 KB Output is correct
46 Correct 14 ms 8776 KB Output is correct
47 Correct 13 ms 8848 KB Output is correct
48 Correct 10 ms 8148 KB Output is correct
49 Correct 7 ms 7636 KB Output is correct
50 Correct 4 ms 7252 KB Output is correct
51 Correct 202 ms 27380 KB Output is correct
52 Correct 287 ms 27476 KB Output is correct
53 Correct 206 ms 27388 KB Output is correct
54 Correct 223 ms 27480 KB Output is correct
55 Correct 309 ms 27400 KB Output is correct
56 Correct 218 ms 27492 KB Output is correct
57 Correct 270 ms 27496 KB Output is correct
58 Correct 120 ms 26912 KB Output is correct
59 Correct 116 ms 26956 KB Output is correct
60 Correct 4 ms 7252 KB Output is correct
61 Correct 600 ms 53204 KB Output is correct
62 Correct 651 ms 53260 KB Output is correct
63 Correct 602 ms 53084 KB Output is correct
64 Correct 569 ms 53216 KB Output is correct
65 Correct 634 ms 53300 KB Output is correct
66 Correct 608 ms 53332 KB Output is correct
67 Correct 589 ms 53108 KB Output is correct
68 Correct 379 ms 36596 KB Output is correct
69 Correct 301 ms 30672 KB Output is correct
70 Correct 4 ms 7360 KB Output is correct