답안 #61999

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
61999 2018-07-27T08:24:21 Z gusfring Construction of Highway (JOI18_construction) C++14
16 / 100
2000 ms 13820 KB
# include <bits/stdc++.h>

using namespace std;

const int N = 1e5 + 2;

int n, c[N], p[N], fen[N];
vector <int> vec;

void update(int pos, int val){
  for(; pos <= n; pos |= pos + 1) fen[pos] += val;
}

int get(int pos){
  int res = 0;
  for(; pos > 0; pos = (pos & (pos + 1)) - 1)
        res += fen[pos];
  return res;
}

int main(){
  scanf("%d", &n);
  for(int i = 1; i <= n; i ++){
    scanf("%d", &c[i]);
    vec.emplace_back(c[i]);
  }
  sort(vec.begin(), vec.end());
  vec.resize(unique(vec.begin(), vec.end()) - vec.begin());
  for(int i = 1; i <= n; i ++){
    c[i] = lower_bound(vec.begin(), vec.end(), c[i]) - vec.begin() + 1;
  }
  for(int i = 1; i < n; i ++){
    int a, b;
    scanf("%d %d", &a, &b);
    int v = a, ans = 0;
    while(v){
      update(c[v], 1);
      ans += get(c[v] - 1);
      v = p[v];
    }
    v = a;
    while(v){
      update(c[v], -1);
      c[v] = c[b];
      v = p[v];
    }
    printf("%d\n", ans);
    p[b] = a;
  }
}

Compilation message

construction.cpp: In function 'int main()':
construction.cpp:22:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d", &n);
   ~~~~~^~~~~~~~~~
construction.cpp:24:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d", &c[i]);
     ~~~~~^~~~~~~~~~~~~
construction.cpp:34:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d %d", &a, &b);
     ~~~~~^~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 3 ms 376 KB Output is correct
3 Correct 2 ms 424 KB Output is correct
4 Correct 2 ms 504 KB Output is correct
5 Correct 4 ms 564 KB Output is correct
6 Correct 5 ms 652 KB Output is correct
7 Correct 4 ms 664 KB Output is correct
8 Correct 7 ms 684 KB Output is correct
9 Correct 8 ms 688 KB Output is correct
10 Correct 6 ms 700 KB Output is correct
11 Correct 5 ms 712 KB Output is correct
12 Correct 5 ms 724 KB Output is correct
13 Correct 6 ms 736 KB Output is correct
14 Correct 5 ms 752 KB Output is correct
15 Correct 3 ms 760 KB Output is correct
16 Correct 4 ms 768 KB Output is correct
17 Correct 2 ms 780 KB Output is correct
18 Correct 4 ms 792 KB Output is correct
19 Correct 6 ms 804 KB Output is correct
20 Correct 5 ms 816 KB Output is correct
21 Correct 6 ms 828 KB Output is correct
22 Correct 3 ms 840 KB Output is correct
23 Correct 5 ms 848 KB Output is correct
24 Correct 1 ms 856 KB Output is correct
25 Correct 4 ms 864 KB Output is correct
26 Correct 7 ms 864 KB Output is correct
27 Correct 5 ms 864 KB Output is correct
28 Correct 5 ms 888 KB Output is correct
29 Correct 5 ms 896 KB Output is correct
30 Correct 4 ms 904 KB Output is correct
31 Correct 4 ms 912 KB Output is correct
32 Correct 5 ms 1048 KB Output is correct
33 Correct 6 ms 1048 KB Output is correct
34 Correct 5 ms 1048 KB Output is correct
35 Correct 3 ms 1048 KB Output is correct
36 Correct 5 ms 1048 KB Output is correct
37 Correct 4 ms 1048 KB Output is correct
38 Correct 5 ms 1048 KB Output is correct
39 Correct 5 ms 1048 KB Output is correct
40 Correct 5 ms 1048 KB Output is correct
41 Correct 4 ms 1048 KB Output is correct
42 Correct 5 ms 1048 KB Output is correct
43 Correct 5 ms 1048 KB Output is correct
44 Correct 4 ms 1048 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 3 ms 376 KB Output is correct
3 Correct 2 ms 424 KB Output is correct
4 Correct 2 ms 504 KB Output is correct
5 Correct 4 ms 564 KB Output is correct
6 Correct 5 ms 652 KB Output is correct
7 Correct 4 ms 664 KB Output is correct
8 Correct 7 ms 684 KB Output is correct
9 Correct 8 ms 688 KB Output is correct
10 Correct 6 ms 700 KB Output is correct
11 Correct 5 ms 712 KB Output is correct
12 Correct 5 ms 724 KB Output is correct
13 Correct 6 ms 736 KB Output is correct
14 Correct 5 ms 752 KB Output is correct
15 Correct 3 ms 760 KB Output is correct
16 Correct 4 ms 768 KB Output is correct
17 Correct 2 ms 780 KB Output is correct
18 Correct 4 ms 792 KB Output is correct
19 Correct 6 ms 804 KB Output is correct
20 Correct 5 ms 816 KB Output is correct
21 Correct 6 ms 828 KB Output is correct
22 Correct 3 ms 840 KB Output is correct
23 Correct 5 ms 848 KB Output is correct
24 Correct 1 ms 856 KB Output is correct
25 Correct 4 ms 864 KB Output is correct
26 Correct 7 ms 864 KB Output is correct
27 Correct 5 ms 864 KB Output is correct
28 Correct 5 ms 888 KB Output is correct
29 Correct 5 ms 896 KB Output is correct
30 Correct 4 ms 904 KB Output is correct
31 Correct 4 ms 912 KB Output is correct
32 Correct 5 ms 1048 KB Output is correct
33 Correct 6 ms 1048 KB Output is correct
34 Correct 5 ms 1048 KB Output is correct
35 Correct 3 ms 1048 KB Output is correct
36 Correct 5 ms 1048 KB Output is correct
37 Correct 4 ms 1048 KB Output is correct
38 Correct 5 ms 1048 KB Output is correct
39 Correct 5 ms 1048 KB Output is correct
40 Correct 5 ms 1048 KB Output is correct
41 Correct 4 ms 1048 KB Output is correct
42 Correct 5 ms 1048 KB Output is correct
43 Correct 5 ms 1048 KB Output is correct
44 Correct 4 ms 1048 KB Output is correct
45 Correct 5 ms 1048 KB Output is correct
46 Correct 10 ms 1172 KB Output is correct
47 Correct 10 ms 1280 KB Output is correct
48 Correct 8 ms 1344 KB Output is correct
49 Correct 317 ms 1432 KB Output is correct
50 Correct 259 ms 1504 KB Output is correct
51 Correct 278 ms 1704 KB Output is correct
52 Correct 122 ms 1704 KB Output is correct
53 Correct 108 ms 1740 KB Output is correct
54 Correct 118 ms 2036 KB Output is correct
55 Correct 114 ms 2036 KB Output is correct
56 Correct 121 ms 2188 KB Output is correct
57 Correct 8 ms 2188 KB Output is correct
58 Correct 11 ms 2188 KB Output is correct
59 Correct 10 ms 2268 KB Output is correct
60 Correct 10 ms 2268 KB Output is correct
61 Correct 146 ms 2328 KB Output is correct
62 Correct 141 ms 2404 KB Output is correct
63 Correct 134 ms 2504 KB Output is correct
64 Correct 8 ms 2504 KB Output is correct
65 Correct 9 ms 2604 KB Output is correct
66 Correct 9 ms 2652 KB Output is correct
67 Correct 11 ms 2704 KB Output is correct
68 Correct 339 ms 2760 KB Output is correct
69 Correct 129 ms 2808 KB Output is correct
70 Correct 204 ms 2976 KB Output is correct
71 Correct 176 ms 2976 KB Output is correct
72 Correct 9 ms 2976 KB Output is correct
73 Correct 10 ms 2976 KB Output is correct
74 Correct 142 ms 3176 KB Output is correct
75 Correct 67 ms 3248 KB Output is correct
76 Correct 55 ms 3248 KB Output is correct
77 Correct 43 ms 3248 KB Output is correct
78 Correct 83 ms 3304 KB Output is correct
79 Correct 65 ms 3304 KB Output is correct
80 Correct 52 ms 3304 KB Output is correct
81 Correct 75 ms 3580 KB Output is correct
82 Correct 52 ms 3580 KB Output is correct
83 Correct 58 ms 3580 KB Output is correct
84 Correct 75 ms 3760 KB Output is correct
85 Correct 62 ms 3760 KB Output is correct
86 Correct 45 ms 3760 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 3 ms 376 KB Output is correct
3 Correct 2 ms 424 KB Output is correct
4 Correct 2 ms 504 KB Output is correct
5 Correct 4 ms 564 KB Output is correct
6 Correct 5 ms 652 KB Output is correct
7 Correct 4 ms 664 KB Output is correct
8 Correct 7 ms 684 KB Output is correct
9 Correct 8 ms 688 KB Output is correct
10 Correct 6 ms 700 KB Output is correct
11 Correct 5 ms 712 KB Output is correct
12 Correct 5 ms 724 KB Output is correct
13 Correct 6 ms 736 KB Output is correct
14 Correct 5 ms 752 KB Output is correct
15 Correct 3 ms 760 KB Output is correct
16 Correct 4 ms 768 KB Output is correct
17 Correct 2 ms 780 KB Output is correct
18 Correct 4 ms 792 KB Output is correct
19 Correct 6 ms 804 KB Output is correct
20 Correct 5 ms 816 KB Output is correct
21 Correct 6 ms 828 KB Output is correct
22 Correct 3 ms 840 KB Output is correct
23 Correct 5 ms 848 KB Output is correct
24 Correct 1 ms 856 KB Output is correct
25 Correct 4 ms 864 KB Output is correct
26 Correct 7 ms 864 KB Output is correct
27 Correct 5 ms 864 KB Output is correct
28 Correct 5 ms 888 KB Output is correct
29 Correct 5 ms 896 KB Output is correct
30 Correct 4 ms 904 KB Output is correct
31 Correct 4 ms 912 KB Output is correct
32 Correct 5 ms 1048 KB Output is correct
33 Correct 6 ms 1048 KB Output is correct
34 Correct 5 ms 1048 KB Output is correct
35 Correct 3 ms 1048 KB Output is correct
36 Correct 5 ms 1048 KB Output is correct
37 Correct 4 ms 1048 KB Output is correct
38 Correct 5 ms 1048 KB Output is correct
39 Correct 5 ms 1048 KB Output is correct
40 Correct 5 ms 1048 KB Output is correct
41 Correct 4 ms 1048 KB Output is correct
42 Correct 5 ms 1048 KB Output is correct
43 Correct 5 ms 1048 KB Output is correct
44 Correct 4 ms 1048 KB Output is correct
45 Correct 5 ms 1048 KB Output is correct
46 Correct 10 ms 1172 KB Output is correct
47 Correct 10 ms 1280 KB Output is correct
48 Correct 8 ms 1344 KB Output is correct
49 Correct 317 ms 1432 KB Output is correct
50 Correct 259 ms 1504 KB Output is correct
51 Correct 278 ms 1704 KB Output is correct
52 Correct 122 ms 1704 KB Output is correct
53 Correct 108 ms 1740 KB Output is correct
54 Correct 118 ms 2036 KB Output is correct
55 Correct 114 ms 2036 KB Output is correct
56 Correct 121 ms 2188 KB Output is correct
57 Correct 8 ms 2188 KB Output is correct
58 Correct 11 ms 2188 KB Output is correct
59 Correct 10 ms 2268 KB Output is correct
60 Correct 10 ms 2268 KB Output is correct
61 Correct 146 ms 2328 KB Output is correct
62 Correct 141 ms 2404 KB Output is correct
63 Correct 134 ms 2504 KB Output is correct
64 Correct 8 ms 2504 KB Output is correct
65 Correct 9 ms 2604 KB Output is correct
66 Correct 9 ms 2652 KB Output is correct
67 Correct 11 ms 2704 KB Output is correct
68 Correct 339 ms 2760 KB Output is correct
69 Correct 129 ms 2808 KB Output is correct
70 Correct 204 ms 2976 KB Output is correct
71 Correct 176 ms 2976 KB Output is correct
72 Correct 9 ms 2976 KB Output is correct
73 Correct 10 ms 2976 KB Output is correct
74 Correct 142 ms 3176 KB Output is correct
75 Correct 67 ms 3248 KB Output is correct
76 Correct 55 ms 3248 KB Output is correct
77 Correct 43 ms 3248 KB Output is correct
78 Correct 83 ms 3304 KB Output is correct
79 Correct 65 ms 3304 KB Output is correct
80 Correct 52 ms 3304 KB Output is correct
81 Correct 75 ms 3580 KB Output is correct
82 Correct 52 ms 3580 KB Output is correct
83 Correct 58 ms 3580 KB Output is correct
84 Correct 75 ms 3760 KB Output is correct
85 Correct 62 ms 3760 KB Output is correct
86 Correct 45 ms 3760 KB Output is correct
87 Correct 19 ms 4040 KB Output is correct
88 Correct 69 ms 5048 KB Output is correct
89 Correct 313 ms 8544 KB Output is correct
90 Correct 284 ms 10792 KB Output is correct
91 Correct 253 ms 12908 KB Output is correct
92 Execution timed out 2028 ms 13820 KB Time limit exceeded
93 Halted 0 ms 0 KB -