Submission #47386

# Submission time Handle Problem Language Result Execution time Memory
47386 2018-05-02T09:59:01 Z mirbek01 Construction of Highway (JOI18_construction) C++17
7 / 100
222 ms 1196 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;
            set <int> st;
            while(v){
                  update(c[v], 1);
                  ans += get(c[v] - 1);
                  st.insert(c[v]);
                  v = p[v];
            }

            if(st.size() > 1000)
                  assert(0);

            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: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 248 KB Output is correct
2 Correct 2 ms 356 KB Output is correct
3 Correct 2 ms 432 KB Output is correct
4 Correct 2 ms 448 KB Output is correct
5 Correct 2 ms 448 KB Output is correct
6 Correct 2 ms 576 KB Output is correct
7 Correct 2 ms 576 KB Output is correct
8 Correct 4 ms 576 KB Output is correct
9 Correct 5 ms 576 KB Output is correct
10 Correct 4 ms 576 KB Output is correct
11 Correct 3 ms 576 KB Output is correct
12 Correct 3 ms 576 KB Output is correct
13 Correct 4 ms 576 KB Output is correct
14 Correct 3 ms 648 KB Output is correct
15 Correct 2 ms 648 KB Output is correct
16 Correct 3 ms 648 KB Output is correct
17 Correct 3 ms 748 KB Output is correct
18 Correct 3 ms 748 KB Output is correct
19 Correct 3 ms 748 KB Output is correct
20 Correct 3 ms 748 KB Output is correct
21 Correct 3 ms 748 KB Output is correct
22 Correct 2 ms 748 KB Output is correct
23 Correct 2 ms 748 KB Output is correct
24 Correct 3 ms 748 KB Output is correct
25 Correct 2 ms 748 KB Output is correct
26 Correct 5 ms 764 KB Output is correct
27 Correct 5 ms 764 KB Output is correct
28 Correct 4 ms 764 KB Output is correct
29 Correct 5 ms 764 KB Output is correct
30 Correct 2 ms 764 KB Output is correct
31 Correct 2 ms 764 KB Output is correct
32 Correct 3 ms 764 KB Output is correct
33 Correct 3 ms 764 KB Output is correct
34 Correct 2 ms 764 KB Output is correct
35 Correct 2 ms 764 KB Output is correct
36 Correct 3 ms 764 KB Output is correct
37 Correct 3 ms 764 KB Output is correct
38 Correct 3 ms 764 KB Output is correct
39 Correct 3 ms 764 KB Output is correct
40 Correct 3 ms 764 KB Output is correct
41 Correct 2 ms 764 KB Output is correct
42 Correct 4 ms 764 KB Output is correct
43 Correct 3 ms 764 KB Output is correct
44 Correct 3 ms 764 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 248 KB Output is correct
2 Correct 2 ms 356 KB Output is correct
3 Correct 2 ms 432 KB Output is correct
4 Correct 2 ms 448 KB Output is correct
5 Correct 2 ms 448 KB Output is correct
6 Correct 2 ms 576 KB Output is correct
7 Correct 2 ms 576 KB Output is correct
8 Correct 4 ms 576 KB Output is correct
9 Correct 5 ms 576 KB Output is correct
10 Correct 4 ms 576 KB Output is correct
11 Correct 3 ms 576 KB Output is correct
12 Correct 3 ms 576 KB Output is correct
13 Correct 4 ms 576 KB Output is correct
14 Correct 3 ms 648 KB Output is correct
15 Correct 2 ms 648 KB Output is correct
16 Correct 3 ms 648 KB Output is correct
17 Correct 3 ms 748 KB Output is correct
18 Correct 3 ms 748 KB Output is correct
19 Correct 3 ms 748 KB Output is correct
20 Correct 3 ms 748 KB Output is correct
21 Correct 3 ms 748 KB Output is correct
22 Correct 2 ms 748 KB Output is correct
23 Correct 2 ms 748 KB Output is correct
24 Correct 3 ms 748 KB Output is correct
25 Correct 2 ms 748 KB Output is correct
26 Correct 5 ms 764 KB Output is correct
27 Correct 5 ms 764 KB Output is correct
28 Correct 4 ms 764 KB Output is correct
29 Correct 5 ms 764 KB Output is correct
30 Correct 2 ms 764 KB Output is correct
31 Correct 2 ms 764 KB Output is correct
32 Correct 3 ms 764 KB Output is correct
33 Correct 3 ms 764 KB Output is correct
34 Correct 2 ms 764 KB Output is correct
35 Correct 2 ms 764 KB Output is correct
36 Correct 3 ms 764 KB Output is correct
37 Correct 3 ms 764 KB Output is correct
38 Correct 3 ms 764 KB Output is correct
39 Correct 3 ms 764 KB Output is correct
40 Correct 3 ms 764 KB Output is correct
41 Correct 2 ms 764 KB Output is correct
42 Correct 4 ms 764 KB Output is correct
43 Correct 3 ms 764 KB Output is correct
44 Correct 3 ms 764 KB Output is correct
45 Correct 4 ms 764 KB Output is correct
46 Correct 11 ms 764 KB Output is correct
47 Correct 11 ms 764 KB Output is correct
48 Correct 7 ms 764 KB Output is correct
49 Correct 200 ms 764 KB Output is correct
50 Correct 222 ms 764 KB Output is correct
51 Correct 203 ms 816 KB Output is correct
52 Runtime error 106 ms 1196 KB Execution killed with signal 11 (could be triggered by violating memory limits)
53 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 248 KB Output is correct
2 Correct 2 ms 356 KB Output is correct
3 Correct 2 ms 432 KB Output is correct
4 Correct 2 ms 448 KB Output is correct
5 Correct 2 ms 448 KB Output is correct
6 Correct 2 ms 576 KB Output is correct
7 Correct 2 ms 576 KB Output is correct
8 Correct 4 ms 576 KB Output is correct
9 Correct 5 ms 576 KB Output is correct
10 Correct 4 ms 576 KB Output is correct
11 Correct 3 ms 576 KB Output is correct
12 Correct 3 ms 576 KB Output is correct
13 Correct 4 ms 576 KB Output is correct
14 Correct 3 ms 648 KB Output is correct
15 Correct 2 ms 648 KB Output is correct
16 Correct 3 ms 648 KB Output is correct
17 Correct 3 ms 748 KB Output is correct
18 Correct 3 ms 748 KB Output is correct
19 Correct 3 ms 748 KB Output is correct
20 Correct 3 ms 748 KB Output is correct
21 Correct 3 ms 748 KB Output is correct
22 Correct 2 ms 748 KB Output is correct
23 Correct 2 ms 748 KB Output is correct
24 Correct 3 ms 748 KB Output is correct
25 Correct 2 ms 748 KB Output is correct
26 Correct 5 ms 764 KB Output is correct
27 Correct 5 ms 764 KB Output is correct
28 Correct 4 ms 764 KB Output is correct
29 Correct 5 ms 764 KB Output is correct
30 Correct 2 ms 764 KB Output is correct
31 Correct 2 ms 764 KB Output is correct
32 Correct 3 ms 764 KB Output is correct
33 Correct 3 ms 764 KB Output is correct
34 Correct 2 ms 764 KB Output is correct
35 Correct 2 ms 764 KB Output is correct
36 Correct 3 ms 764 KB Output is correct
37 Correct 3 ms 764 KB Output is correct
38 Correct 3 ms 764 KB Output is correct
39 Correct 3 ms 764 KB Output is correct
40 Correct 3 ms 764 KB Output is correct
41 Correct 2 ms 764 KB Output is correct
42 Correct 4 ms 764 KB Output is correct
43 Correct 3 ms 764 KB Output is correct
44 Correct 3 ms 764 KB Output is correct
45 Correct 4 ms 764 KB Output is correct
46 Correct 11 ms 764 KB Output is correct
47 Correct 11 ms 764 KB Output is correct
48 Correct 7 ms 764 KB Output is correct
49 Correct 200 ms 764 KB Output is correct
50 Correct 222 ms 764 KB Output is correct
51 Correct 203 ms 816 KB Output is correct
52 Runtime error 106 ms 1196 KB Execution killed with signal 11 (could be triggered by violating memory limits)
53 Halted 0 ms 0 KB -