P4715 淘汰赛
一道水题,直接线段树水过去。
1 #include <bits/stdc++.h> 2 3 using namespace std; 4 5 const int N = 100010; 6 int n, a[N]; 7 8 struct node 9 { 10 int l, r, num, id; 11 }; 12 13 struct segment 14 { 15 node t[N << 2]; 16 17 void push_up(int root) 18 { 19 int ch = root << 1; 20 if(t[ch].num > t[ch + 1].num) t[root].id = t[ch].id; 21 else t[root].id = t[ch + 1].id; 22 t[root].num = max(t[ch].num, t[ch + 1].num); 23 } 24 25 void build(int root, int l, int r) 26 { 27 t[root].l = l; 28 t[root].r = r; 29 if(l != r) 30 { 31 int mid = (l + r) >> 1; 32 int ch = root << 1; 33 build(ch, l, mid); 34 build(ch + 1, mid + 1, r); 35 push_up(root); 36 } 37 else 38 { 39 t[root].id = l; 40 t[root].num = a[l]; 41 } 42 } 43 } st; 44 45 signed main() 46 { 47 scanf("%d", &n); 48 n = pow(2, n); 49 for(int i = 1; i <= n; ++i) scanf("%d", &a[i]); 50 51 st.build(1, 1, n); 52 53 54 if(st.t[2].num < st.t[1].num) printf("%d\n", st.t[2].id); 55 if(st.t[3].num < st.t[1].num) printf("%d\n", st.t[3].id); 56 57 58 return 0; 59 }

浙公网安备 33010602011771号