关于堆的判断
作者:
etener
,
2024-02-22 10:59:46
,
所有人可见
,
阅读 67
判断
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
int in[N], pre[N];
int n, m;
int h[N];
int cnt = 0;
void down (int u)
{ int size1=n;
int t = u;
if (2 * u <= size1 && h[2 * u] < h[t]) t = 2 * u;
if (2 * u + 1 <= size1 && h[2 * u + 1] < h[t]) t = 2 * u + 1;
if (u != t)
{
swap (h[u], h[t]);
down (t);
}
}
void up(int u)
{
while(u/2 && h[u/2]>h[u])
{
swap(h(u/2),h(u));
u/=2;
}
}
int main ()
{
cin >> n >> m;
for (int i = 1; i <= n; i ++)
{
int x; cin >> x;
h[++ cnt] = x;
up (i);
}
map<int, int> mp;
for (int i = 1; i <= n; i ++) mp[h[i]] = i;
while (m --)
{
int x; cin >> x;
string s; cin >> s;
if (s == "is")
{
string s2; cin >> s2;
if (s2 == "the")
{
string s3; cin >> s3;
if (s3 == "root")
{
if (mp[x] == 1)
cout << "T" << "\n";
else
cout << "F" << "\n";
}
else
{
string s4; int x2;
cin >> s4 >> x2;
if (mp[x] == mp[x2] / 2)
cout << "T" << "\n";
else
cout << "F" << "\n";
}
}
else
{
string s3, s4; int x2;
cin >> s3 >> s4 >> x2;
if (mp[x] / 2 == mp[x2])
cout << "T" << "\n";
else
cout << "F" << "\n";
}
}
else
{
int x2;
string s2, s3;
cin >> x2 >> s2 >> s3;
if (mp[x] / 2 == mp[x2] / 2)
cout << "T" << "\n";
else
cout << "F" << "\n";
}
}
}
没有用到down