Submission #267040

# Submission time Handle Problem Language Result Execution time Memory
267040 2020-08-15T17:51:23 Z kimbj0709 Mountains (NOI20_mountains) C++14
100 / 100
182 ms 14172 KB
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define maxn 300050
vector<int> fenwick(maxn,0);
void add(int b,int c){
  int temp = b+1;
  while(temp<=fenwick.size()){
    fenwick[temp] += c;
    temp += temp & (-temp);
  }
}
int getsum(int a,int b){
  int temp = b+1;
  int total = 0;
  while(temp!=0){
    total += fenwick[temp];
    temp -= temp & (-temp);
  }
  int idk = a;
  while(idk!=0){
    total -= fenwick[idk];
    idk -= idk & (-idk);
  }
  return total;
}
int32_t main() {
  ios::sync_with_stdio(0);
  cin.tie(0);cout.tie(0);
  int no_of_input;
  int input;
  vector<int> vect1;
  vector<int> vect2;
  cin >> no_of_input;
  for(int i=0;i<no_of_input;i++){
    cin >> input;
    vect1.push_back(input);
    vect2.push_back(input);
  }
  sort(vect2.begin(),vect2.end());
  for(int i=0;i<no_of_input;i++){
    int k = lower_bound(vect2.begin(),vect2.end(),vect1[i])-vect2.begin();
    vect1[i] = k+1;
  }
  for(int i=0;i<vect1.size();i++){
    vect2[i] = getsum(0,vect1[i]-1);
    add(vect1[i],1);
  }
  for(int i=0;i<fenwick.size();i++){
    fenwick[i] = 0;
  }
  int ans = 0;
  for(int i=vect1.size()-1;i>=0;i--){
    ans += vect2[i]*getsum(0,vect1[i]-1);
    add(vect1[i],1);
  }
  cout << ans;

}

Compilation message

Mountains.cpp: In function 'void add(long long int, long long int)':
Mountains.cpp:8:13: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    8 |   while(temp<=fenwick.size()){
      |         ~~~~^~~~~~~~~~~~~~~~
Mountains.cpp: In function 'int32_t main()':
Mountains.cpp:45:16: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   45 |   for(int i=0;i<vect1.size();i++){
      |               ~^~~~~~~~~~~~~
Mountains.cpp:49:16: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   49 |   for(int i=0;i<fenwick.size();i++){
      |               ~^~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2688 KB Output is correct
2 Correct 110 ms 14044 KB Output is correct
3 Correct 126 ms 14044 KB Output is correct
4 Correct 111 ms 14044 KB Output is correct
5 Correct 109 ms 14044 KB Output is correct
6 Correct 115 ms 14044 KB Output is correct
7 Correct 131 ms 14040 KB Output is correct
8 Correct 109 ms 14048 KB Output is correct
9 Correct 109 ms 14172 KB Output is correct
10 Correct 111 ms 14160 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 71 ms 9700 KB Output is correct
2 Correct 71 ms 9692 KB Output is correct
3 Correct 75 ms 9832 KB Output is correct
4 Correct 72 ms 9692 KB Output is correct
5 Correct 84 ms 9692 KB Output is correct
6 Correct 72 ms 9820 KB Output is correct
7 Correct 72 ms 9700 KB Output is correct
8 Correct 67 ms 9704 KB Output is correct
9 Correct 66 ms 9700 KB Output is correct
10 Correct 2 ms 2688 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 71 ms 9700 KB Output is correct
2 Correct 71 ms 9692 KB Output is correct
3 Correct 75 ms 9832 KB Output is correct
4 Correct 72 ms 9692 KB Output is correct
5 Correct 84 ms 9692 KB Output is correct
6 Correct 72 ms 9820 KB Output is correct
7 Correct 72 ms 9700 KB Output is correct
8 Correct 67 ms 9704 KB Output is correct
9 Correct 66 ms 9700 KB Output is correct
10 Correct 2 ms 2688 KB Output is correct
11 Correct 108 ms 9980 KB Output is correct
12 Correct 106 ms 9948 KB Output is correct
13 Correct 105 ms 9956 KB Output is correct
14 Correct 110 ms 9948 KB Output is correct
15 Correct 106 ms 9956 KB Output is correct
16 Correct 113 ms 10088 KB Output is correct
17 Correct 109 ms 9948 KB Output is correct
18 Correct 67 ms 10076 KB Output is correct
19 Correct 59 ms 9948 KB Output is correct
20 Correct 3 ms 2688 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2688 KB Output is correct
2 Correct 2 ms 2688 KB Output is correct
3 Correct 3 ms 2688 KB Output is correct
4 Correct 2 ms 2688 KB Output is correct
5 Correct 3 ms 2688 KB Output is correct
6 Correct 2 ms 2688 KB Output is correct
7 Correct 2 ms 2688 KB Output is correct
8 Correct 3 ms 2688 KB Output is correct
9 Correct 2 ms 2688 KB Output is correct
10 Correct 3 ms 2688 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2688 KB Output is correct
2 Correct 2 ms 2688 KB Output is correct
3 Correct 3 ms 2688 KB Output is correct
4 Correct 2 ms 2688 KB Output is correct
5 Correct 3 ms 2688 KB Output is correct
6 Correct 2 ms 2688 KB Output is correct
7 Correct 2 ms 2688 KB Output is correct
8 Correct 3 ms 2688 KB Output is correct
9 Correct 2 ms 2688 KB Output is correct
10 Correct 3 ms 2688 KB Output is correct
11 Correct 8 ms 3200 KB Output is correct
12 Correct 8 ms 3200 KB Output is correct
13 Correct 7 ms 3200 KB Output is correct
14 Correct 8 ms 3200 KB Output is correct
15 Correct 8 ms 3200 KB Output is correct
16 Correct 8 ms 3144 KB Output is correct
17 Correct 7 ms 3200 KB Output is correct
18 Correct 7 ms 3200 KB Output is correct
19 Correct 5 ms 3072 KB Output is correct
20 Correct 2 ms 2688 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 71 ms 9700 KB Output is correct
2 Correct 71 ms 9692 KB Output is correct
3 Correct 75 ms 9832 KB Output is correct
4 Correct 72 ms 9692 KB Output is correct
5 Correct 84 ms 9692 KB Output is correct
6 Correct 72 ms 9820 KB Output is correct
7 Correct 72 ms 9700 KB Output is correct
8 Correct 67 ms 9704 KB Output is correct
9 Correct 66 ms 9700 KB Output is correct
10 Correct 2 ms 2688 KB Output is correct
11 Correct 108 ms 9980 KB Output is correct
12 Correct 106 ms 9948 KB Output is correct
13 Correct 105 ms 9956 KB Output is correct
14 Correct 110 ms 9948 KB Output is correct
15 Correct 106 ms 9956 KB Output is correct
16 Correct 113 ms 10088 KB Output is correct
17 Correct 109 ms 9948 KB Output is correct
18 Correct 67 ms 10076 KB Output is correct
19 Correct 59 ms 9948 KB Output is correct
20 Correct 3 ms 2688 KB Output is correct
21 Correct 169 ms 10716 KB Output is correct
22 Correct 145 ms 10716 KB Output is correct
23 Correct 146 ms 10716 KB Output is correct
24 Correct 142 ms 10724 KB Output is correct
25 Correct 148 ms 10716 KB Output is correct
26 Correct 142 ms 10716 KB Output is correct
27 Correct 155 ms 10716 KB Output is correct
28 Correct 77 ms 10716 KB Output is correct
29 Correct 78 ms 10724 KB Output is correct
30 Correct 2 ms 2688 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2688 KB Output is correct
2 Correct 110 ms 14044 KB Output is correct
3 Correct 126 ms 14044 KB Output is correct
4 Correct 111 ms 14044 KB Output is correct
5 Correct 109 ms 14044 KB Output is correct
6 Correct 115 ms 14044 KB Output is correct
7 Correct 131 ms 14040 KB Output is correct
8 Correct 109 ms 14048 KB Output is correct
9 Correct 109 ms 14172 KB Output is correct
10 Correct 111 ms 14160 KB Output is correct
11 Correct 71 ms 9700 KB Output is correct
12 Correct 71 ms 9692 KB Output is correct
13 Correct 75 ms 9832 KB Output is correct
14 Correct 72 ms 9692 KB Output is correct
15 Correct 84 ms 9692 KB Output is correct
16 Correct 72 ms 9820 KB Output is correct
17 Correct 72 ms 9700 KB Output is correct
18 Correct 67 ms 9704 KB Output is correct
19 Correct 66 ms 9700 KB Output is correct
20 Correct 2 ms 2688 KB Output is correct
21 Correct 108 ms 9980 KB Output is correct
22 Correct 106 ms 9948 KB Output is correct
23 Correct 105 ms 9956 KB Output is correct
24 Correct 110 ms 9948 KB Output is correct
25 Correct 106 ms 9956 KB Output is correct
26 Correct 113 ms 10088 KB Output is correct
27 Correct 109 ms 9948 KB Output is correct
28 Correct 67 ms 10076 KB Output is correct
29 Correct 59 ms 9948 KB Output is correct
30 Correct 3 ms 2688 KB Output is correct
31 Correct 2 ms 2688 KB Output is correct
32 Correct 2 ms 2688 KB Output is correct
33 Correct 3 ms 2688 KB Output is correct
34 Correct 2 ms 2688 KB Output is correct
35 Correct 3 ms 2688 KB Output is correct
36 Correct 2 ms 2688 KB Output is correct
37 Correct 2 ms 2688 KB Output is correct
38 Correct 3 ms 2688 KB Output is correct
39 Correct 2 ms 2688 KB Output is correct
40 Correct 3 ms 2688 KB Output is correct
41 Correct 8 ms 3200 KB Output is correct
42 Correct 8 ms 3200 KB Output is correct
43 Correct 7 ms 3200 KB Output is correct
44 Correct 8 ms 3200 KB Output is correct
45 Correct 8 ms 3200 KB Output is correct
46 Correct 8 ms 3144 KB Output is correct
47 Correct 7 ms 3200 KB Output is correct
48 Correct 7 ms 3200 KB Output is correct
49 Correct 5 ms 3072 KB Output is correct
50 Correct 2 ms 2688 KB Output is correct
51 Correct 169 ms 10716 KB Output is correct
52 Correct 145 ms 10716 KB Output is correct
53 Correct 146 ms 10716 KB Output is correct
54 Correct 142 ms 10724 KB Output is correct
55 Correct 148 ms 10716 KB Output is correct
56 Correct 142 ms 10716 KB Output is correct
57 Correct 155 ms 10716 KB Output is correct
58 Correct 77 ms 10716 KB Output is correct
59 Correct 78 ms 10724 KB Output is correct
60 Correct 2 ms 2688 KB Output is correct
61 Correct 176 ms 14132 KB Output is correct
62 Correct 171 ms 14148 KB Output is correct
63 Correct 174 ms 14040 KB Output is correct
64 Correct 171 ms 14044 KB Output is correct
65 Correct 182 ms 14044 KB Output is correct
66 Correct 177 ms 14044 KB Output is correct
67 Correct 180 ms 14044 KB Output is correct
68 Correct 176 ms 14172 KB Output is correct
69 Correct 147 ms 10844 KB Output is correct
70 Correct 2 ms 2688 KB Output is correct