Submission #113999

# Submission time Handle Problem Language Result Execution time Memory
113999 2019-05-29T14:01:49 Z shayan_p Construction of Highway (JOI18_construction) C++14
16 / 100
2000 ms 2296 KB
// High above the clouds there is a rainbow...

#include<bits/stdc++.h>

#define F first
#define S second
#define PB push_back
#define sz(s) int((s).size())
#define bit(n,k) (((n)>>(k))&1)

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

const int maxn=1e5+10,mod=1e9+7;
const ll inf=1e18;

int a[maxn],fn[maxn],par[maxn];

void add(int pos,int x){
    for(pos=pos+3;pos<maxn;pos+=(pos & -pos))
	fn[pos]+=x;
}
int ask(int pos){
    int ans=0;
    for(pos=pos+3;pos>0;pos-=(pos & -pos))
	ans+=fn[pos];
    return ans;
}

int arr[maxn],C;

int main(){
    ios_base::sync_with_stdio(false);cin.tie(0);
    int n;cin>>n;
    for(int i=0;i<n;i++){
	cin>>a[i];
	arr[i]=a[i];
    }
    sort(arr,arr+n);
    C=unique(arr,arr+n)-arr;
    for(int i=0;i<n;i++){
	a[i]=lower_bound(arr,arr+C,a[i])-arr;
    }
	
    par[0]=-1;
    for(int i=0;i<n-1;i++){
	int A,B;cin>>A>>B;
	par[--B]=--A;
	ll ans=0;
	int x=A;
	while(x>=0){
	    ans+=ask(a[x]-1);
	    add(a[x],1);
	    x=par[x];
	}
	x=A;
	while(x>=0){
	    add(a[x],-1);
	    a[x]=a[B];
	    x=par[x];
	}
	cout<<ans<<"\n";
    }
    return 0;
}
// Deathly mistakes:
//  * Read the problem curfully.
//  * Check maxn.
//  * Overflows.
# Verdict Execution time Memory Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
5 Correct 2 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 7 ms 384 KB Output is correct
9 Correct 7 ms 384 KB Output is correct
10 Correct 7 ms 384 KB Output is correct
11 Correct 5 ms 384 KB Output is correct
12 Correct 5 ms 384 KB Output is correct
13 Correct 4 ms 384 KB Output is correct
14 Correct 4 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 2 ms 384 KB Output is correct
18 Correct 3 ms 384 KB Output is correct
19 Correct 5 ms 384 KB Output is correct
20 Correct 4 ms 384 KB Output is correct
21 Correct 4 ms 384 KB Output is correct
22 Correct 2 ms 384 KB Output is correct
23 Correct 2 ms 384 KB Output is correct
24 Correct 2 ms 384 KB Output is correct
25 Correct 2 ms 384 KB Output is correct
26 Correct 8 ms 356 KB Output is correct
27 Correct 4 ms 384 KB Output is correct
28 Correct 5 ms 384 KB Output is correct
29 Correct 4 ms 384 KB Output is correct
30 Correct 2 ms 384 KB Output is correct
31 Correct 2 ms 384 KB Output is correct
32 Correct 5 ms 384 KB Output is correct
33 Correct 3 ms 384 KB Output is correct
34 Correct 3 ms 384 KB Output is correct
35 Correct 3 ms 384 KB Output is correct
36 Correct 3 ms 384 KB Output is correct
37 Correct 3 ms 356 KB Output is correct
38 Correct 3 ms 384 KB Output is correct
39 Correct 4 ms 384 KB Output is correct
40 Correct 3 ms 384 KB Output is correct
41 Correct 3 ms 384 KB Output is correct
42 Correct 4 ms 384 KB Output is correct
43 Correct 3 ms 384 KB Output is correct
44 Correct 3 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
5 Correct 2 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 7 ms 384 KB Output is correct
9 Correct 7 ms 384 KB Output is correct
10 Correct 7 ms 384 KB Output is correct
11 Correct 5 ms 384 KB Output is correct
12 Correct 5 ms 384 KB Output is correct
13 Correct 4 ms 384 KB Output is correct
14 Correct 4 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 2 ms 384 KB Output is correct
18 Correct 3 ms 384 KB Output is correct
19 Correct 5 ms 384 KB Output is correct
20 Correct 4 ms 384 KB Output is correct
21 Correct 4 ms 384 KB Output is correct
22 Correct 2 ms 384 KB Output is correct
23 Correct 2 ms 384 KB Output is correct
24 Correct 2 ms 384 KB Output is correct
25 Correct 2 ms 384 KB Output is correct
26 Correct 8 ms 356 KB Output is correct
27 Correct 4 ms 384 KB Output is correct
28 Correct 5 ms 384 KB Output is correct
29 Correct 4 ms 384 KB Output is correct
30 Correct 2 ms 384 KB Output is correct
31 Correct 2 ms 384 KB Output is correct
32 Correct 5 ms 384 KB Output is correct
33 Correct 3 ms 384 KB Output is correct
34 Correct 3 ms 384 KB Output is correct
35 Correct 3 ms 384 KB Output is correct
36 Correct 3 ms 384 KB Output is correct
37 Correct 3 ms 356 KB Output is correct
38 Correct 3 ms 384 KB Output is correct
39 Correct 4 ms 384 KB Output is correct
40 Correct 3 ms 384 KB Output is correct
41 Correct 3 ms 384 KB Output is correct
42 Correct 4 ms 384 KB Output is correct
43 Correct 3 ms 384 KB Output is correct
44 Correct 3 ms 384 KB Output is correct
45 Correct 3 ms 384 KB Output is correct
46 Correct 6 ms 512 KB Output is correct
47 Correct 6 ms 512 KB Output is correct
48 Correct 6 ms 512 KB Output is correct
49 Correct 287 ms 504 KB Output is correct
50 Correct 284 ms 476 KB Output is correct
51 Correct 290 ms 512 KB Output is correct
52 Correct 144 ms 636 KB Output is correct
53 Correct 151 ms 520 KB Output is correct
54 Correct 161 ms 636 KB Output is correct
55 Correct 151 ms 376 KB Output is correct
56 Correct 150 ms 384 KB Output is correct
57 Correct 6 ms 384 KB Output is correct
58 Correct 6 ms 384 KB Output is correct
59 Correct 6 ms 384 KB Output is correct
60 Correct 6 ms 384 KB Output is correct
61 Correct 150 ms 504 KB Output is correct
62 Correct 151 ms 384 KB Output is correct
63 Correct 152 ms 504 KB Output is correct
64 Correct 5 ms 384 KB Output is correct
65 Correct 5 ms 384 KB Output is correct
66 Correct 6 ms 428 KB Output is correct
67 Correct 6 ms 384 KB Output is correct
68 Correct 350 ms 384 KB Output is correct
69 Correct 147 ms 384 KB Output is correct
70 Correct 175 ms 508 KB Output is correct
71 Correct 175 ms 512 KB Output is correct
72 Correct 6 ms 484 KB Output is correct
73 Correct 6 ms 384 KB Output is correct
74 Correct 177 ms 632 KB Output is correct
75 Correct 75 ms 516 KB Output is correct
76 Correct 49 ms 384 KB Output is correct
77 Correct 41 ms 384 KB Output is correct
78 Correct 91 ms 384 KB Output is correct
79 Correct 60 ms 512 KB Output is correct
80 Correct 46 ms 512 KB Output is correct
81 Correct 75 ms 512 KB Output is correct
82 Correct 52 ms 512 KB Output is correct
83 Correct 39 ms 384 KB Output is correct
84 Correct 95 ms 632 KB Output is correct
85 Correct 60 ms 384 KB Output is correct
86 Correct 47 ms 508 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
5 Correct 2 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 7 ms 384 KB Output is correct
9 Correct 7 ms 384 KB Output is correct
10 Correct 7 ms 384 KB Output is correct
11 Correct 5 ms 384 KB Output is correct
12 Correct 5 ms 384 KB Output is correct
13 Correct 4 ms 384 KB Output is correct
14 Correct 4 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 2 ms 384 KB Output is correct
18 Correct 3 ms 384 KB Output is correct
19 Correct 5 ms 384 KB Output is correct
20 Correct 4 ms 384 KB Output is correct
21 Correct 4 ms 384 KB Output is correct
22 Correct 2 ms 384 KB Output is correct
23 Correct 2 ms 384 KB Output is correct
24 Correct 2 ms 384 KB Output is correct
25 Correct 2 ms 384 KB Output is correct
26 Correct 8 ms 356 KB Output is correct
27 Correct 4 ms 384 KB Output is correct
28 Correct 5 ms 384 KB Output is correct
29 Correct 4 ms 384 KB Output is correct
30 Correct 2 ms 384 KB Output is correct
31 Correct 2 ms 384 KB Output is correct
32 Correct 5 ms 384 KB Output is correct
33 Correct 3 ms 384 KB Output is correct
34 Correct 3 ms 384 KB Output is correct
35 Correct 3 ms 384 KB Output is correct
36 Correct 3 ms 384 KB Output is correct
37 Correct 3 ms 356 KB Output is correct
38 Correct 3 ms 384 KB Output is correct
39 Correct 4 ms 384 KB Output is correct
40 Correct 3 ms 384 KB Output is correct
41 Correct 3 ms 384 KB Output is correct
42 Correct 4 ms 384 KB Output is correct
43 Correct 3 ms 384 KB Output is correct
44 Correct 3 ms 384 KB Output is correct
45 Correct 3 ms 384 KB Output is correct
46 Correct 6 ms 512 KB Output is correct
47 Correct 6 ms 512 KB Output is correct
48 Correct 6 ms 512 KB Output is correct
49 Correct 287 ms 504 KB Output is correct
50 Correct 284 ms 476 KB Output is correct
51 Correct 290 ms 512 KB Output is correct
52 Correct 144 ms 636 KB Output is correct
53 Correct 151 ms 520 KB Output is correct
54 Correct 161 ms 636 KB Output is correct
55 Correct 151 ms 376 KB Output is correct
56 Correct 150 ms 384 KB Output is correct
57 Correct 6 ms 384 KB Output is correct
58 Correct 6 ms 384 KB Output is correct
59 Correct 6 ms 384 KB Output is correct
60 Correct 6 ms 384 KB Output is correct
61 Correct 150 ms 504 KB Output is correct
62 Correct 151 ms 384 KB Output is correct
63 Correct 152 ms 504 KB Output is correct
64 Correct 5 ms 384 KB Output is correct
65 Correct 5 ms 384 KB Output is correct
66 Correct 6 ms 428 KB Output is correct
67 Correct 6 ms 384 KB Output is correct
68 Correct 350 ms 384 KB Output is correct
69 Correct 147 ms 384 KB Output is correct
70 Correct 175 ms 508 KB Output is correct
71 Correct 175 ms 512 KB Output is correct
72 Correct 6 ms 484 KB Output is correct
73 Correct 6 ms 384 KB Output is correct
74 Correct 177 ms 632 KB Output is correct
75 Correct 75 ms 516 KB Output is correct
76 Correct 49 ms 384 KB Output is correct
77 Correct 41 ms 384 KB Output is correct
78 Correct 91 ms 384 KB Output is correct
79 Correct 60 ms 512 KB Output is correct
80 Correct 46 ms 512 KB Output is correct
81 Correct 75 ms 512 KB Output is correct
82 Correct 52 ms 512 KB Output is correct
83 Correct 39 ms 384 KB Output is correct
84 Correct 95 ms 632 KB Output is correct
85 Correct 60 ms 384 KB Output is correct
86 Correct 47 ms 508 KB Output is correct
87 Correct 12 ms 640 KB Output is correct
88 Correct 34 ms 1088 KB Output is correct
89 Correct 136 ms 2296 KB Output is correct
90 Correct 137 ms 2244 KB Output is correct
91 Correct 137 ms 2168 KB Output is correct
92 Execution timed out 2019 ms 1980 KB Time limit exceeded
93 Halted 0 ms 0 KB -