Submission #47389

# Submission time Handle Problem Language Result Execution time Memory
47389 2018-05-02T10:18:34 Z mirbek01 Construction of Highway (JOI18_construction) C++17
16 / 100
1000 ms 2804 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;
      }
      int cc = 0;
      for(int i = 1; i < n; i ++){
            int a, b;
            scanf("%d %d", &a, &b);
            int v = a, ans = 0;
            set <int> st;
            while(v){
                  update(c[v], 1);
                  ans += get(c[v] - 1);
                  st.insert(c[v]);
                  v = p[v];
            }

            cc += st.size();

            v = a;
            while(v){
                  update(c[v], -1);
                  c[v] = c[b];
                  v = p[v];
            }
            printf("%d\n", ans);
            p[b] = a;
      }

      int lg = ceil(log2(n));
      if(cc > n * max((lg - 2), 1)) assert(0);
}

Compilation message

construction.cpp: In function 'int main()':
construction.cpp:23:12: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
       scanf("%d", &n);
       ~~~~~^~~~~~~~~~
construction.cpp:26:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
             scanf("%d", &c[i]);
             ~~~~~^~~~~~~~~~~~~
construction.cpp:39:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
             scanf("%d %d", &a, &b);
             ~~~~~^~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 428 KB Output is correct
4 Correct 2 ms 504 KB Output is correct
5 Correct 3 ms 544 KB Output is correct
6 Correct 2 ms 656 KB Output is correct
7 Correct 3 ms 656 KB Output is correct
8 Correct 4 ms 656 KB Output is correct
9 Correct 4 ms 656 KB Output is correct
10 Correct 4 ms 656 KB Output is correct
11 Correct 5 ms 656 KB Output is correct
12 Correct 3 ms 656 KB Output is correct
13 Correct 3 ms 656 KB Output is correct
14 Correct 3 ms 656 KB Output is correct
15 Correct 3 ms 656 KB Output is correct
16 Correct 2 ms 656 KB Output is correct
17 Correct 3 ms 656 KB Output is correct
18 Correct 3 ms 656 KB Output is correct
19 Correct 3 ms 656 KB Output is correct
20 Correct 4 ms 656 KB Output is correct
21 Correct 4 ms 656 KB Output is correct
22 Correct 2 ms 656 KB Output is correct
23 Correct 3 ms 656 KB Output is correct
24 Correct 2 ms 656 KB Output is correct
25 Correct 2 ms 656 KB Output is correct
26 Correct 5 ms 656 KB Output is correct
27 Correct 3 ms 748 KB Output is correct
28 Correct 5 ms 748 KB Output is correct
29 Correct 3 ms 748 KB Output is correct
30 Correct 2 ms 748 KB Output is correct
31 Correct 2 ms 748 KB Output is correct
32 Correct 4 ms 748 KB Output is correct
33 Correct 3 ms 748 KB Output is correct
34 Correct 3 ms 748 KB Output is correct
35 Correct 2 ms 748 KB Output is correct
36 Correct 3 ms 748 KB Output is correct
37 Correct 3 ms 748 KB Output is correct
38 Correct 2 ms 748 KB Output is correct
39 Correct 3 ms 748 KB Output is correct
40 Correct 3 ms 748 KB Output is correct
41 Correct 3 ms 748 KB Output is correct
42 Correct 4 ms 748 KB Output is correct
43 Correct 2 ms 748 KB Output is correct
44 Correct 2 ms 748 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 428 KB Output is correct
4 Correct 2 ms 504 KB Output is correct
5 Correct 3 ms 544 KB Output is correct
6 Correct 2 ms 656 KB Output is correct
7 Correct 3 ms 656 KB Output is correct
8 Correct 4 ms 656 KB Output is correct
9 Correct 4 ms 656 KB Output is correct
10 Correct 4 ms 656 KB Output is correct
11 Correct 5 ms 656 KB Output is correct
12 Correct 3 ms 656 KB Output is correct
13 Correct 3 ms 656 KB Output is correct
14 Correct 3 ms 656 KB Output is correct
15 Correct 3 ms 656 KB Output is correct
16 Correct 2 ms 656 KB Output is correct
17 Correct 3 ms 656 KB Output is correct
18 Correct 3 ms 656 KB Output is correct
19 Correct 3 ms 656 KB Output is correct
20 Correct 4 ms 656 KB Output is correct
21 Correct 4 ms 656 KB Output is correct
22 Correct 2 ms 656 KB Output is correct
23 Correct 3 ms 656 KB Output is correct
24 Correct 2 ms 656 KB Output is correct
25 Correct 2 ms 656 KB Output is correct
26 Correct 5 ms 656 KB Output is correct
27 Correct 3 ms 748 KB Output is correct
28 Correct 5 ms 748 KB Output is correct
29 Correct 3 ms 748 KB Output is correct
30 Correct 2 ms 748 KB Output is correct
31 Correct 2 ms 748 KB Output is correct
32 Correct 4 ms 748 KB Output is correct
33 Correct 3 ms 748 KB Output is correct
34 Correct 3 ms 748 KB Output is correct
35 Correct 2 ms 748 KB Output is correct
36 Correct 3 ms 748 KB Output is correct
37 Correct 3 ms 748 KB Output is correct
38 Correct 2 ms 748 KB Output is correct
39 Correct 3 ms 748 KB Output is correct
40 Correct 3 ms 748 KB Output is correct
41 Correct 3 ms 748 KB Output is correct
42 Correct 4 ms 748 KB Output is correct
43 Correct 2 ms 748 KB Output is correct
44 Correct 2 ms 748 KB Output is correct
45 Correct 3 ms 748 KB Output is correct
46 Correct 11 ms 748 KB Output is correct
47 Correct 10 ms 768 KB Output is correct
48 Correct 8 ms 768 KB Output is correct
49 Correct 209 ms 816 KB Output is correct
50 Correct 195 ms 876 KB Output is correct
51 Correct 348 ms 876 KB Output is correct
52 Correct 145 ms 876 KB Output is correct
53 Correct 104 ms 876 KB Output is correct
54 Correct 102 ms 888 KB Output is correct
55 Correct 100 ms 888 KB Output is correct
56 Correct 102 ms 888 KB Output is correct
57 Correct 13 ms 888 KB Output is correct
58 Correct 13 ms 888 KB Output is correct
59 Correct 10 ms 888 KB Output is correct
60 Correct 10 ms 888 KB Output is correct
61 Correct 107 ms 888 KB Output is correct
62 Correct 112 ms 888 KB Output is correct
63 Correct 100 ms 888 KB Output is correct
64 Correct 6 ms 888 KB Output is correct
65 Correct 6 ms 888 KB Output is correct
66 Correct 7 ms 888 KB Output is correct
67 Correct 7 ms 888 KB Output is correct
68 Correct 235 ms 888 KB Output is correct
69 Correct 99 ms 888 KB Output is correct
70 Correct 120 ms 888 KB Output is correct
71 Correct 124 ms 904 KB Output is correct
72 Correct 8 ms 904 KB Output is correct
73 Correct 9 ms 904 KB Output is correct
74 Correct 121 ms 904 KB Output is correct
75 Correct 53 ms 904 KB Output is correct
76 Correct 39 ms 904 KB Output is correct
77 Correct 36 ms 904 KB Output is correct
78 Correct 66 ms 904 KB Output is correct
79 Correct 45 ms 904 KB Output is correct
80 Correct 34 ms 904 KB Output is correct
81 Correct 60 ms 904 KB Output is correct
82 Correct 38 ms 904 KB Output is correct
83 Correct 29 ms 904 KB Output is correct
84 Correct 64 ms 904 KB Output is correct
85 Correct 45 ms 904 KB Output is correct
86 Correct 34 ms 904 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 428 KB Output is correct
4 Correct 2 ms 504 KB Output is correct
5 Correct 3 ms 544 KB Output is correct
6 Correct 2 ms 656 KB Output is correct
7 Correct 3 ms 656 KB Output is correct
8 Correct 4 ms 656 KB Output is correct
9 Correct 4 ms 656 KB Output is correct
10 Correct 4 ms 656 KB Output is correct
11 Correct 5 ms 656 KB Output is correct
12 Correct 3 ms 656 KB Output is correct
13 Correct 3 ms 656 KB Output is correct
14 Correct 3 ms 656 KB Output is correct
15 Correct 3 ms 656 KB Output is correct
16 Correct 2 ms 656 KB Output is correct
17 Correct 3 ms 656 KB Output is correct
18 Correct 3 ms 656 KB Output is correct
19 Correct 3 ms 656 KB Output is correct
20 Correct 4 ms 656 KB Output is correct
21 Correct 4 ms 656 KB Output is correct
22 Correct 2 ms 656 KB Output is correct
23 Correct 3 ms 656 KB Output is correct
24 Correct 2 ms 656 KB Output is correct
25 Correct 2 ms 656 KB Output is correct
26 Correct 5 ms 656 KB Output is correct
27 Correct 3 ms 748 KB Output is correct
28 Correct 5 ms 748 KB Output is correct
29 Correct 3 ms 748 KB Output is correct
30 Correct 2 ms 748 KB Output is correct
31 Correct 2 ms 748 KB Output is correct
32 Correct 4 ms 748 KB Output is correct
33 Correct 3 ms 748 KB Output is correct
34 Correct 3 ms 748 KB Output is correct
35 Correct 2 ms 748 KB Output is correct
36 Correct 3 ms 748 KB Output is correct
37 Correct 3 ms 748 KB Output is correct
38 Correct 2 ms 748 KB Output is correct
39 Correct 3 ms 748 KB Output is correct
40 Correct 3 ms 748 KB Output is correct
41 Correct 3 ms 748 KB Output is correct
42 Correct 4 ms 748 KB Output is correct
43 Correct 2 ms 748 KB Output is correct
44 Correct 2 ms 748 KB Output is correct
45 Correct 3 ms 748 KB Output is correct
46 Correct 11 ms 748 KB Output is correct
47 Correct 10 ms 768 KB Output is correct
48 Correct 8 ms 768 KB Output is correct
49 Correct 209 ms 816 KB Output is correct
50 Correct 195 ms 876 KB Output is correct
51 Correct 348 ms 876 KB Output is correct
52 Correct 145 ms 876 KB Output is correct
53 Correct 104 ms 876 KB Output is correct
54 Correct 102 ms 888 KB Output is correct
55 Correct 100 ms 888 KB Output is correct
56 Correct 102 ms 888 KB Output is correct
57 Correct 13 ms 888 KB Output is correct
58 Correct 13 ms 888 KB Output is correct
59 Correct 10 ms 888 KB Output is correct
60 Correct 10 ms 888 KB Output is correct
61 Correct 107 ms 888 KB Output is correct
62 Correct 112 ms 888 KB Output is correct
63 Correct 100 ms 888 KB Output is correct
64 Correct 6 ms 888 KB Output is correct
65 Correct 6 ms 888 KB Output is correct
66 Correct 7 ms 888 KB Output is correct
67 Correct 7 ms 888 KB Output is correct
68 Correct 235 ms 888 KB Output is correct
69 Correct 99 ms 888 KB Output is correct
70 Correct 120 ms 888 KB Output is correct
71 Correct 124 ms 904 KB Output is correct
72 Correct 8 ms 904 KB Output is correct
73 Correct 9 ms 904 KB Output is correct
74 Correct 121 ms 904 KB Output is correct
75 Correct 53 ms 904 KB Output is correct
76 Correct 39 ms 904 KB Output is correct
77 Correct 36 ms 904 KB Output is correct
78 Correct 66 ms 904 KB Output is correct
79 Correct 45 ms 904 KB Output is correct
80 Correct 34 ms 904 KB Output is correct
81 Correct 60 ms 904 KB Output is correct
82 Correct 38 ms 904 KB Output is correct
83 Correct 29 ms 904 KB Output is correct
84 Correct 64 ms 904 KB Output is correct
85 Correct 45 ms 904 KB Output is correct
86 Correct 34 ms 904 KB Output is correct
87 Correct 19 ms 904 KB Output is correct
88 Correct 58 ms 1468 KB Output is correct
89 Correct 245 ms 2748 KB Output is correct
90 Correct 253 ms 2804 KB Output is correct
91 Correct 239 ms 2804 KB Output is correct
92 Execution timed out 1084 ms 2804 KB Time limit exceeded
93 Halted 0 ms 0 KB -