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 }
复制代码

 

posted @   std&ice  阅读(79)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· C#/.NET/.NET Core优秀项目和框架2025年2月简报
· Manus爆火,是硬核还是营销?
· 终于写完轮子一部分:tcp代理 了,记录一下
· 【杭电多校比赛记录】2025“钉耙编程”中国大学生算法设计春季联赛(1)
点击右上角即可分享
微信分享提示