답안 #232869

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
232869 2020-05-18T12:39:41 Z AlexLuchianov Mountains (NOI20_mountains) C++14
100 / 100
529 ms 29500 KB
#include <iostream>
#include <vector>
#include <algorithm>
#include <cassert>
#include <cmath>
#include <map>

using namespace std;

using ll = long long;

int const nmax = 300000;
ll v[1 + nmax];

map<ll,int> mp;

void normalize(int n){
  vector<ll> temp;
  for(int i = 1;i <= n; i++)
    temp.push_back(v[i]);
  sort(temp.begin(), temp.end());
  temp.erase(unique(temp.begin(), temp.end()), temp.end());
  for(int i = 0; i < temp.size(); i++)
    mp[temp[i]] = 1 + i;
  for(int i = 1;i <= n; i++)
    v[i] = mp[v[i]];
}

class FenwickTree{
private:
  vector<int> aib;
  int n;
public:
  FenwickTree(int n_){
    n = n_;
    aib.resize(1 + n);
  }
  void update(int pos, int val){
    for(int x = pos; x <= n; x += (x ^ (x & (x-1))))
      aib[x] += val;
  }
  int query(int pos){
    int result = 0;
    for(int x = pos; 0 < x; x = (x & (x - 1)))
      result += aib[x];
    return result;
  }
};

int main()
{
  ios::sync_with_stdio(0);
  cin.tie(0);

  int n;
  cin >> n;
  for(int i = 1;i <= n; i++)
    cin >> v[i];
  normalize(n);

  FenwickTree basic(n), part(n);
  for(int i = 1;i <= n; i++)
    basic.update(v[i], 1);

  ll result = 0;
  for(int i = 1; i <= n; i++){
    int x = part.query(v[i] - 1);
    result += 1LL * part.query(v[i] - 1) * (basic.query(v[i] - 1) - x);
    part.update(v[i], 1);
  }
  cout << result;
  return 0;
}

Compilation message

Mountains.cpp: In function 'void normalize(int)':
Mountains.cpp:23:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(int i = 0; i < temp.size(); i++)
                  ~~^~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 213 ms 29408 KB Output is correct
3 Correct 212 ms 29380 KB Output is correct
4 Correct 214 ms 29496 KB Output is correct
5 Correct 214 ms 29412 KB Output is correct
6 Correct 221 ms 29436 KB Output is correct
7 Correct 212 ms 29408 KB Output is correct
8 Correct 212 ms 29412 KB Output is correct
9 Correct 168 ms 20332 KB Output is correct
10 Correct 173 ms 20448 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 65 ms 7540 KB Output is correct
2 Correct 60 ms 7540 KB Output is correct
3 Correct 62 ms 7540 KB Output is correct
4 Correct 60 ms 7540 KB Output is correct
5 Correct 60 ms 7540 KB Output is correct
6 Correct 61 ms 7532 KB Output is correct
7 Correct 60 ms 7540 KB Output is correct
8 Correct 56 ms 7540 KB Output is correct
9 Correct 56 ms 7540 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 65 ms 7540 KB Output is correct
2 Correct 60 ms 7540 KB Output is correct
3 Correct 62 ms 7540 KB Output is correct
4 Correct 60 ms 7540 KB Output is correct
5 Correct 60 ms 7540 KB Output is correct
6 Correct 61 ms 7532 KB Output is correct
7 Correct 60 ms 7540 KB Output is correct
8 Correct 56 ms 7540 KB Output is correct
9 Correct 56 ms 7540 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
11 Correct 85 ms 7788 KB Output is correct
12 Correct 79 ms 7796 KB Output is correct
13 Correct 84 ms 7796 KB Output is correct
14 Correct 78 ms 7788 KB Output is correct
15 Correct 81 ms 7788 KB Output is correct
16 Correct 79 ms 7820 KB Output is correct
17 Correct 81 ms 7788 KB Output is correct
18 Correct 57 ms 7796 KB Output is correct
19 Correct 58 ms 7796 KB Output is correct
20 Correct 5 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 6 ms 512 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 5 ms 384 KB Output is correct
9 Correct 5 ms 384 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 6 ms 512 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 5 ms 384 KB Output is correct
9 Correct 5 ms 384 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
11 Correct 11 ms 1280 KB Output is correct
12 Correct 11 ms 1280 KB Output is correct
13 Correct 11 ms 1280 KB Output is correct
14 Correct 11 ms 1280 KB Output is correct
15 Correct 12 ms 1280 KB Output is correct
16 Correct 11 ms 1280 KB Output is correct
17 Correct 11 ms 1408 KB Output is correct
18 Correct 10 ms 1024 KB Output is correct
19 Correct 7 ms 640 KB Output is correct
20 Correct 5 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 65 ms 7540 KB Output is correct
2 Correct 60 ms 7540 KB Output is correct
3 Correct 62 ms 7540 KB Output is correct
4 Correct 60 ms 7540 KB Output is correct
5 Correct 60 ms 7540 KB Output is correct
6 Correct 61 ms 7532 KB Output is correct
7 Correct 60 ms 7540 KB Output is correct
8 Correct 56 ms 7540 KB Output is correct
9 Correct 56 ms 7540 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
11 Correct 85 ms 7788 KB Output is correct
12 Correct 79 ms 7796 KB Output is correct
13 Correct 84 ms 7796 KB Output is correct
14 Correct 78 ms 7788 KB Output is correct
15 Correct 81 ms 7788 KB Output is correct
16 Correct 79 ms 7820 KB Output is correct
17 Correct 81 ms 7788 KB Output is correct
18 Correct 57 ms 7796 KB Output is correct
19 Correct 58 ms 7796 KB Output is correct
20 Correct 5 ms 384 KB Output is correct
21 Correct 253 ms 12836 KB Output is correct
22 Correct 235 ms 12768 KB Output is correct
23 Correct 225 ms 12768 KB Output is correct
24 Correct 244 ms 12860 KB Output is correct
25 Correct 252 ms 12768 KB Output is correct
26 Correct 238 ms 12768 KB Output is correct
27 Correct 287 ms 12984 KB Output is correct
28 Correct 114 ms 12880 KB Output is correct
29 Correct 113 ms 12728 KB Output is correct
30 Correct 5 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 213 ms 29408 KB Output is correct
3 Correct 212 ms 29380 KB Output is correct
4 Correct 214 ms 29496 KB Output is correct
5 Correct 214 ms 29412 KB Output is correct
6 Correct 221 ms 29436 KB Output is correct
7 Correct 212 ms 29408 KB Output is correct
8 Correct 212 ms 29412 KB Output is correct
9 Correct 168 ms 20332 KB Output is correct
10 Correct 173 ms 20448 KB Output is correct
11 Correct 65 ms 7540 KB Output is correct
12 Correct 60 ms 7540 KB Output is correct
13 Correct 62 ms 7540 KB Output is correct
14 Correct 60 ms 7540 KB Output is correct
15 Correct 60 ms 7540 KB Output is correct
16 Correct 61 ms 7532 KB Output is correct
17 Correct 60 ms 7540 KB Output is correct
18 Correct 56 ms 7540 KB Output is correct
19 Correct 56 ms 7540 KB Output is correct
20 Correct 5 ms 384 KB Output is correct
21 Correct 85 ms 7788 KB Output is correct
22 Correct 79 ms 7796 KB Output is correct
23 Correct 84 ms 7796 KB Output is correct
24 Correct 78 ms 7788 KB Output is correct
25 Correct 81 ms 7788 KB Output is correct
26 Correct 79 ms 7820 KB Output is correct
27 Correct 81 ms 7788 KB Output is correct
28 Correct 57 ms 7796 KB Output is correct
29 Correct 58 ms 7796 KB Output is correct
30 Correct 5 ms 384 KB Output is correct
31 Correct 5 ms 384 KB Output is correct
32 Correct 6 ms 512 KB Output is correct
33 Correct 5 ms 384 KB Output is correct
34 Correct 5 ms 384 KB Output is correct
35 Correct 5 ms 384 KB Output is correct
36 Correct 5 ms 384 KB Output is correct
37 Correct 5 ms 384 KB Output is correct
38 Correct 5 ms 384 KB Output is correct
39 Correct 5 ms 384 KB Output is correct
40 Correct 5 ms 384 KB Output is correct
41 Correct 11 ms 1280 KB Output is correct
42 Correct 11 ms 1280 KB Output is correct
43 Correct 11 ms 1280 KB Output is correct
44 Correct 11 ms 1280 KB Output is correct
45 Correct 12 ms 1280 KB Output is correct
46 Correct 11 ms 1280 KB Output is correct
47 Correct 11 ms 1408 KB Output is correct
48 Correct 10 ms 1024 KB Output is correct
49 Correct 7 ms 640 KB Output is correct
50 Correct 5 ms 384 KB Output is correct
51 Correct 253 ms 12836 KB Output is correct
52 Correct 235 ms 12768 KB Output is correct
53 Correct 225 ms 12768 KB Output is correct
54 Correct 244 ms 12860 KB Output is correct
55 Correct 252 ms 12768 KB Output is correct
56 Correct 238 ms 12768 KB Output is correct
57 Correct 287 ms 12984 KB Output is correct
58 Correct 114 ms 12880 KB Output is correct
59 Correct 113 ms 12728 KB Output is correct
60 Correct 5 ms 384 KB Output is correct
61 Correct 501 ms 29492 KB Output is correct
62 Correct 495 ms 29496 KB Output is correct
63 Correct 510 ms 29496 KB Output is correct
64 Correct 514 ms 29408 KB Output is correct
65 Correct 520 ms 29408 KB Output is correct
66 Correct 524 ms 29496 KB Output is correct
67 Correct 529 ms 29500 KB Output is correct
68 Correct 400 ms 20324 KB Output is correct
69 Correct 357 ms 15032 KB Output is correct
70 Correct 5 ms 384 KB Output is correct