답안 #369989

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
369989 2021-02-22T20:48:38 Z ivan_tudor Mountains (NOI20_mountains) C++14
100 / 100
271 ms 11884 KB
#include<bits/stdc++.h>
using namespace std;
const int N = 3*1e5 + 5;
int aib[N];
void update(int poz,int val){
  for(int i= poz; i< N; i += i&(-i))
    aib[i] += val;
}
int query(int poz){
  int rsp =0 ;
  for(int i = poz; i>0; i-= i&(-i))
    rsp += aib[i];
  return rsp;
}
struct evenim{
  long long h;
  int poz;
  bool operator <(evenim other) const{
    return h < other.h;
  }
};
evenim v[N];
int main()
{
  int n;
  cin>>n;
  for(int i= 1; i<=n;i++){
    long long h;
    cin>>h;
    v[i] = {h, i};
  }
  sort(v+1, v+n+1);
  long long ans = 0;
  for(int i=1; i<=n;){
    int j = i;
    ans += 1LL * query(v[j].poz - 1) * (query(n) - query(v[j].poz));
    while(j + 1<=n && v[j + 1].h == v[i].h){
      j++;
      ans += 1LL * query(v[j].poz - 1) * (query(n) - query(v[j].poz));
    }
    for(int k = i; k<=j;k++){
      update(v[k].poz, 1);
    }
    i = j + 1;
  }
  cout<<ans;
  return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 236 ms 11884 KB Output is correct
3 Correct 235 ms 11868 KB Output is correct
4 Correct 233 ms 11756 KB Output is correct
5 Correct 236 ms 11884 KB Output is correct
6 Correct 234 ms 11756 KB Output is correct
7 Correct 239 ms 11756 KB Output is correct
8 Correct 233 ms 11756 KB Output is correct
9 Correct 235 ms 11756 KB Output is correct
10 Correct 238 ms 11756 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 77 ms 6764 KB Output is correct
2 Correct 78 ms 6764 KB Output is correct
3 Correct 78 ms 6764 KB Output is correct
4 Correct 77 ms 6764 KB Output is correct
5 Correct 77 ms 6892 KB Output is correct
6 Correct 78 ms 6892 KB Output is correct
7 Correct 81 ms 6760 KB Output is correct
8 Correct 73 ms 6764 KB Output is correct
9 Correct 76 ms 6892 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 77 ms 6764 KB Output is correct
2 Correct 78 ms 6764 KB Output is correct
3 Correct 78 ms 6764 KB Output is correct
4 Correct 77 ms 6764 KB Output is correct
5 Correct 77 ms 6892 KB Output is correct
6 Correct 78 ms 6892 KB Output is correct
7 Correct 81 ms 6760 KB Output is correct
8 Correct 73 ms 6764 KB Output is correct
9 Correct 76 ms 6892 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 93 ms 7088 KB Output is correct
12 Correct 92 ms 7020 KB Output is correct
13 Correct 93 ms 7020 KB Output is correct
14 Correct 96 ms 7020 KB Output is correct
15 Correct 93 ms 7020 KB Output is correct
16 Correct 92 ms 7020 KB Output is correct
17 Correct 93 ms 7020 KB Output is correct
18 Correct 83 ms 7148 KB Output is correct
19 Correct 83 ms 7020 KB Output is correct
20 Correct 1 ms 364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 0 ms 364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 0 ms 364 KB Output is correct
11 Correct 9 ms 492 KB Output is correct
12 Correct 9 ms 492 KB Output is correct
13 Correct 9 ms 492 KB Output is correct
14 Correct 9 ms 492 KB Output is correct
15 Correct 9 ms 492 KB Output is correct
16 Correct 8 ms 492 KB Output is correct
17 Correct 9 ms 620 KB Output is correct
18 Correct 9 ms 492 KB Output is correct
19 Correct 4 ms 492 KB Output is correct
20 Correct 1 ms 364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 77 ms 6764 KB Output is correct
2 Correct 78 ms 6764 KB Output is correct
3 Correct 78 ms 6764 KB Output is correct
4 Correct 77 ms 6764 KB Output is correct
5 Correct 77 ms 6892 KB Output is correct
6 Correct 78 ms 6892 KB Output is correct
7 Correct 81 ms 6760 KB Output is correct
8 Correct 73 ms 6764 KB Output is correct
9 Correct 76 ms 6892 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 93 ms 7088 KB Output is correct
12 Correct 92 ms 7020 KB Output is correct
13 Correct 93 ms 7020 KB Output is correct
14 Correct 96 ms 7020 KB Output is correct
15 Correct 93 ms 7020 KB Output is correct
16 Correct 92 ms 7020 KB Output is correct
17 Correct 93 ms 7020 KB Output is correct
18 Correct 83 ms 7148 KB Output is correct
19 Correct 83 ms 7020 KB Output is correct
20 Correct 1 ms 364 KB Output is correct
21 Correct 138 ms 7992 KB Output is correct
22 Correct 137 ms 7916 KB Output is correct
23 Correct 143 ms 8044 KB Output is correct
24 Correct 139 ms 7916 KB Output is correct
25 Correct 148 ms 7964 KB Output is correct
26 Correct 138 ms 7936 KB Output is correct
27 Correct 142 ms 8044 KB Output is correct
28 Correct 114 ms 7972 KB Output is correct
29 Correct 117 ms 7916 KB Output is correct
30 Correct 1 ms 364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 236 ms 11884 KB Output is correct
3 Correct 235 ms 11868 KB Output is correct
4 Correct 233 ms 11756 KB Output is correct
5 Correct 236 ms 11884 KB Output is correct
6 Correct 234 ms 11756 KB Output is correct
7 Correct 239 ms 11756 KB Output is correct
8 Correct 233 ms 11756 KB Output is correct
9 Correct 235 ms 11756 KB Output is correct
10 Correct 238 ms 11756 KB Output is correct
11 Correct 77 ms 6764 KB Output is correct
12 Correct 78 ms 6764 KB Output is correct
13 Correct 78 ms 6764 KB Output is correct
14 Correct 77 ms 6764 KB Output is correct
15 Correct 77 ms 6892 KB Output is correct
16 Correct 78 ms 6892 KB Output is correct
17 Correct 81 ms 6760 KB Output is correct
18 Correct 73 ms 6764 KB Output is correct
19 Correct 76 ms 6892 KB Output is correct
20 Correct 1 ms 364 KB Output is correct
21 Correct 93 ms 7088 KB Output is correct
22 Correct 92 ms 7020 KB Output is correct
23 Correct 93 ms 7020 KB Output is correct
24 Correct 96 ms 7020 KB Output is correct
25 Correct 93 ms 7020 KB Output is correct
26 Correct 92 ms 7020 KB Output is correct
27 Correct 93 ms 7020 KB Output is correct
28 Correct 83 ms 7148 KB Output is correct
29 Correct 83 ms 7020 KB Output is correct
30 Correct 1 ms 364 KB Output is correct
31 Correct 1 ms 364 KB Output is correct
32 Correct 1 ms 364 KB Output is correct
33 Correct 1 ms 364 KB Output is correct
34 Correct 1 ms 364 KB Output is correct
35 Correct 1 ms 364 KB Output is correct
36 Correct 1 ms 364 KB Output is correct
37 Correct 1 ms 364 KB Output is correct
38 Correct 1 ms 364 KB Output is correct
39 Correct 1 ms 364 KB Output is correct
40 Correct 0 ms 364 KB Output is correct
41 Correct 9 ms 492 KB Output is correct
42 Correct 9 ms 492 KB Output is correct
43 Correct 9 ms 492 KB Output is correct
44 Correct 9 ms 492 KB Output is correct
45 Correct 9 ms 492 KB Output is correct
46 Correct 8 ms 492 KB Output is correct
47 Correct 9 ms 620 KB Output is correct
48 Correct 9 ms 492 KB Output is correct
49 Correct 4 ms 492 KB Output is correct
50 Correct 1 ms 364 KB Output is correct
51 Correct 138 ms 7992 KB Output is correct
52 Correct 137 ms 7916 KB Output is correct
53 Correct 143 ms 8044 KB Output is correct
54 Correct 139 ms 7916 KB Output is correct
55 Correct 148 ms 7964 KB Output is correct
56 Correct 138 ms 7936 KB Output is correct
57 Correct 142 ms 8044 KB Output is correct
58 Correct 114 ms 7972 KB Output is correct
59 Correct 117 ms 7916 KB Output is correct
60 Correct 1 ms 364 KB Output is correct
61 Correct 267 ms 11756 KB Output is correct
62 Correct 263 ms 11884 KB Output is correct
63 Correct 258 ms 11756 KB Output is correct
64 Correct 256 ms 11756 KB Output is correct
65 Correct 256 ms 11756 KB Output is correct
66 Correct 259 ms 11884 KB Output is correct
67 Correct 271 ms 11772 KB Output is correct
68 Correct 259 ms 11756 KB Output is correct
69 Correct 143 ms 8044 KB Output is correct
70 Correct 1 ms 364 KB Output is correct