Submission #317932

# Submission time Handle Problem Language Result Execution time Memory
317932 2020-10-30T21:26:41 Z NintsiChkhaidze Construction of Highway (JOI18_construction) C++14
16 / 100
2000 ms 4856 KB
#include <bits/stdc++.h>
#define s second
#define f first
#define pb push_back
#define mod 1000000007
#define N 100005
#define ll long long
using namespace std;
int a[100005],fen[100005],p[100005];
pair<int,int> d[100005];
vector <int> v;
int get(int ind){
    int sum=0;
    while (ind > 0){
        sum+=fen[ind];
        ind-=(ind&(-ind));
    }
    return sum;
}
void upd(int ind,int val){
    while(ind < N){
        fen[ind]+=val;
        ind+=(ind&(-ind));
    }
}
int main(){
    int n;
    cin>>n;
    
    for (int i=1;i<=n;i++){
        int a;
        cin>>a;
        d[i].f = a,d[i].s = i;
    }
    sort(d+1,d+n+1);
    a[d[1].s] = 1;
    for (int i=2;i<=n;i++){
        if (d[i].f == d[i - 1].f) a[d[i].s] = a[d[i-1].s];
        else a[d[i].s] = a[d[i-1].s] + 1;
    }
    for (int i=1;i<n;i++){
        int x,y,X;
        cin>>x>>y;
        X = x;
        v.clear();
        while (p[x] >= 1)
            v.pb(x),x=p[x];
        
        v.pb(1);
        int ans=0;
        for (int j=v.size()-1;j>=0;j--){
            int x = get(n) - get(a[v[j]]);
            ans+=x;
            upd(a[v[j]],1);
        }
        for (int j=0;j<v.size();j++){
            upd(a[v[j]],-1);
            a[v[j]] = a[y];
        }
        p[y] = X;
        cout<<ans<<"\n";
    }
}

Compilation message

construction.cpp: In function 'int main()':
construction.cpp:56:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   56 |         for (int j=0;j<v.size();j++){
      |                      ~^~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 512 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
5 Correct 3 ms 384 KB Output is correct
6 Correct 3 ms 384 KB Output is correct
7 Correct 3 ms 384 KB Output is correct
8 Correct 10 ms 384 KB Output is correct
9 Correct 10 ms 384 KB Output is correct
10 Correct 10 ms 384 KB Output is correct
11 Correct 6 ms 384 KB Output is correct
12 Correct 7 ms 384 KB Output is correct
13 Correct 6 ms 384 KB Output is correct
14 Correct 6 ms 384 KB Output is correct
15 Correct 3 ms 384 KB Output is correct
16 Correct 3 ms 384 KB Output is correct
17 Correct 3 ms 384 KB Output is correct
18 Correct 3 ms 384 KB Output is correct
19 Correct 6 ms 384 KB Output is correct
20 Correct 6 ms 384 KB Output is correct
21 Correct 6 ms 384 KB Output is correct
22 Correct 2 ms 384 KB Output is correct
23 Correct 3 ms 384 KB Output is correct
24 Correct 3 ms 384 KB Output is correct
25 Correct 3 ms 384 KB Output is correct
26 Correct 11 ms 384 KB Output is correct
27 Correct 6 ms 384 KB Output is correct
28 Correct 7 ms 384 KB Output is correct
29 Correct 6 ms 384 KB Output is correct
30 Correct 3 ms 512 KB Output is correct
31 Correct 3 ms 384 KB Output is correct
32 Correct 8 ms 384 KB Output is correct
33 Correct 4 ms 384 KB Output is correct
34 Correct 4 ms 384 KB Output is correct
35 Correct 3 ms 384 KB Output is correct
36 Correct 5 ms 384 KB Output is correct
37 Correct 4 ms 384 KB Output is correct
38 Correct 3 ms 384 KB Output is correct
39 Correct 4 ms 384 KB Output is correct
40 Correct 4 ms 384 KB Output is correct
41 Correct 4 ms 384 KB Output is correct
42 Correct 4 ms 384 KB Output is correct
43 Correct 4 ms 384 KB Output is correct
44 Correct 3 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 512 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
5 Correct 3 ms 384 KB Output is correct
6 Correct 3 ms 384 KB Output is correct
7 Correct 3 ms 384 KB Output is correct
8 Correct 10 ms 384 KB Output is correct
9 Correct 10 ms 384 KB Output is correct
10 Correct 10 ms 384 KB Output is correct
11 Correct 6 ms 384 KB Output is correct
12 Correct 7 ms 384 KB Output is correct
13 Correct 6 ms 384 KB Output is correct
14 Correct 6 ms 384 KB Output is correct
15 Correct 3 ms 384 KB Output is correct
16 Correct 3 ms 384 KB Output is correct
17 Correct 3 ms 384 KB Output is correct
18 Correct 3 ms 384 KB Output is correct
19 Correct 6 ms 384 KB Output is correct
20 Correct 6 ms 384 KB Output is correct
21 Correct 6 ms 384 KB Output is correct
22 Correct 2 ms 384 KB Output is correct
23 Correct 3 ms 384 KB Output is correct
24 Correct 3 ms 384 KB Output is correct
25 Correct 3 ms 384 KB Output is correct
26 Correct 11 ms 384 KB Output is correct
27 Correct 6 ms 384 KB Output is correct
28 Correct 7 ms 384 KB Output is correct
29 Correct 6 ms 384 KB Output is correct
30 Correct 3 ms 512 KB Output is correct
31 Correct 3 ms 384 KB Output is correct
32 Correct 8 ms 384 KB Output is correct
33 Correct 4 ms 384 KB Output is correct
34 Correct 4 ms 384 KB Output is correct
35 Correct 3 ms 384 KB Output is correct
36 Correct 5 ms 384 KB Output is correct
37 Correct 4 ms 384 KB Output is correct
38 Correct 3 ms 384 KB Output is correct
39 Correct 4 ms 384 KB Output is correct
40 Correct 4 ms 384 KB Output is correct
41 Correct 4 ms 384 KB Output is correct
42 Correct 4 ms 384 KB Output is correct
43 Correct 4 ms 384 KB Output is correct
44 Correct 3 ms 384 KB Output is correct
45 Correct 5 ms 384 KB Output is correct
46 Correct 21 ms 560 KB Output is correct
47 Correct 20 ms 512 KB Output is correct
48 Correct 19 ms 512 KB Output is correct
49 Correct 477 ms 632 KB Output is correct
50 Correct 491 ms 512 KB Output is correct
51 Correct 477 ms 512 KB Output is correct
52 Correct 244 ms 512 KB Output is correct
53 Correct 249 ms 512 KB Output is correct
54 Correct 269 ms 512 KB Output is correct
55 Correct 249 ms 632 KB Output is correct
56 Correct 248 ms 632 KB Output is correct
57 Correct 19 ms 512 KB Output is correct
58 Correct 20 ms 512 KB Output is correct
59 Correct 20 ms 512 KB Output is correct
60 Correct 20 ms 512 KB Output is correct
61 Correct 249 ms 560 KB Output is correct
62 Correct 244 ms 512 KB Output is correct
63 Correct 247 ms 632 KB Output is correct
64 Correct 18 ms 512 KB Output is correct
65 Correct 17 ms 512 KB Output is correct
66 Correct 18 ms 512 KB Output is correct
67 Correct 18 ms 512 KB Output is correct
68 Correct 582 ms 512 KB Output is correct
69 Correct 244 ms 512 KB Output is correct
70 Correct 300 ms 540 KB Output is correct
71 Correct 300 ms 512 KB Output is correct
72 Correct 18 ms 512 KB Output is correct
73 Correct 18 ms 512 KB Output is correct
74 Correct 306 ms 632 KB Output is correct
75 Correct 132 ms 512 KB Output is correct
76 Correct 95 ms 512 KB Output is correct
77 Correct 77 ms 640 KB Output is correct
78 Correct 159 ms 632 KB Output is correct
79 Correct 110 ms 632 KB Output is correct
80 Correct 88 ms 512 KB Output is correct
81 Correct 137 ms 512 KB Output is correct
82 Correct 98 ms 512 KB Output is correct
83 Correct 75 ms 512 KB Output is correct
84 Correct 164 ms 512 KB Output is correct
85 Correct 109 ms 512 KB Output is correct
86 Correct 89 ms 632 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 512 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
5 Correct 3 ms 384 KB Output is correct
6 Correct 3 ms 384 KB Output is correct
7 Correct 3 ms 384 KB Output is correct
8 Correct 10 ms 384 KB Output is correct
9 Correct 10 ms 384 KB Output is correct
10 Correct 10 ms 384 KB Output is correct
11 Correct 6 ms 384 KB Output is correct
12 Correct 7 ms 384 KB Output is correct
13 Correct 6 ms 384 KB Output is correct
14 Correct 6 ms 384 KB Output is correct
15 Correct 3 ms 384 KB Output is correct
16 Correct 3 ms 384 KB Output is correct
17 Correct 3 ms 384 KB Output is correct
18 Correct 3 ms 384 KB Output is correct
19 Correct 6 ms 384 KB Output is correct
20 Correct 6 ms 384 KB Output is correct
21 Correct 6 ms 384 KB Output is correct
22 Correct 2 ms 384 KB Output is correct
23 Correct 3 ms 384 KB Output is correct
24 Correct 3 ms 384 KB Output is correct
25 Correct 3 ms 384 KB Output is correct
26 Correct 11 ms 384 KB Output is correct
27 Correct 6 ms 384 KB Output is correct
28 Correct 7 ms 384 KB Output is correct
29 Correct 6 ms 384 KB Output is correct
30 Correct 3 ms 512 KB Output is correct
31 Correct 3 ms 384 KB Output is correct
32 Correct 8 ms 384 KB Output is correct
33 Correct 4 ms 384 KB Output is correct
34 Correct 4 ms 384 KB Output is correct
35 Correct 3 ms 384 KB Output is correct
36 Correct 5 ms 384 KB Output is correct
37 Correct 4 ms 384 KB Output is correct
38 Correct 3 ms 384 KB Output is correct
39 Correct 4 ms 384 KB Output is correct
40 Correct 4 ms 384 KB Output is correct
41 Correct 4 ms 384 KB Output is correct
42 Correct 4 ms 384 KB Output is correct
43 Correct 4 ms 384 KB Output is correct
44 Correct 3 ms 384 KB Output is correct
45 Correct 5 ms 384 KB Output is correct
46 Correct 21 ms 560 KB Output is correct
47 Correct 20 ms 512 KB Output is correct
48 Correct 19 ms 512 KB Output is correct
49 Correct 477 ms 632 KB Output is correct
50 Correct 491 ms 512 KB Output is correct
51 Correct 477 ms 512 KB Output is correct
52 Correct 244 ms 512 KB Output is correct
53 Correct 249 ms 512 KB Output is correct
54 Correct 269 ms 512 KB Output is correct
55 Correct 249 ms 632 KB Output is correct
56 Correct 248 ms 632 KB Output is correct
57 Correct 19 ms 512 KB Output is correct
58 Correct 20 ms 512 KB Output is correct
59 Correct 20 ms 512 KB Output is correct
60 Correct 20 ms 512 KB Output is correct
61 Correct 249 ms 560 KB Output is correct
62 Correct 244 ms 512 KB Output is correct
63 Correct 247 ms 632 KB Output is correct
64 Correct 18 ms 512 KB Output is correct
65 Correct 17 ms 512 KB Output is correct
66 Correct 18 ms 512 KB Output is correct
67 Correct 18 ms 512 KB Output is correct
68 Correct 582 ms 512 KB Output is correct
69 Correct 244 ms 512 KB Output is correct
70 Correct 300 ms 540 KB Output is correct
71 Correct 300 ms 512 KB Output is correct
72 Correct 18 ms 512 KB Output is correct
73 Correct 18 ms 512 KB Output is correct
74 Correct 306 ms 632 KB Output is correct
75 Correct 132 ms 512 KB Output is correct
76 Correct 95 ms 512 KB Output is correct
77 Correct 77 ms 640 KB Output is correct
78 Correct 159 ms 632 KB Output is correct
79 Correct 110 ms 632 KB Output is correct
80 Correct 88 ms 512 KB Output is correct
81 Correct 137 ms 512 KB Output is correct
82 Correct 98 ms 512 KB Output is correct
83 Correct 75 ms 512 KB Output is correct
84 Correct 164 ms 512 KB Output is correct
85 Correct 109 ms 512 KB Output is correct
86 Correct 89 ms 632 KB Output is correct
87 Correct 49 ms 768 KB Output is correct
88 Correct 152 ms 1656 KB Output is correct
89 Correct 538 ms 4728 KB Output is correct
90 Correct 531 ms 4732 KB Output is correct
91 Correct 537 ms 4856 KB Output is correct
92 Execution timed out 2074 ms 3984 KB Time limit exceeded
93 Halted 0 ms 0 KB -