Find my Family(set)

Find my Family

The first line contains ​, the number of photos you have to process.You are looking for a particular family photo with you and your favorite relatives Alice and Bob. Each family photo contains a line-up of n people. On the photo you’re looking for, you remember that Alice, who is taller than you, was somewhere on your left from the perspective of the photographer. Also, Bob who is taller than both you and Alice, was standing somewhere on your right.
在这里插入图片描述
Since you have a large number of family photos, you want to use your computer to assist in finding the photo. Many of the photos are quite blurry, so facial recognition has proven ineffective. Luckily, the Batch Apex Photo Classifier, which detects each person in a photo and outputs the sequence of their (distinct) heights in pixels, has produced excellent results. Given this sequence of heights for k photos, determine which of these photos could potentially be the photo you’re looking for.

input

The first line contains 1 \le k \le 10001≤k≤1000, the number of photos you have to process.
Then follow two lines for each photo.
The first line contains a single integer 3 \le n \le 3\times10^53≤n≤3×10
5
, the number of people on this photo.

The second line contains n distinct integers 1 \le h_1, h_2, …, h_n \le 10^91≤h
1

,h
2

,…,h
n

≤10
9
, the heights of the people in the photo, from left to right.

It is guaranteed that the total number of people in all photos is at most 3\times10^53×10
5
.

output

On the first line, output the number of photos k that need further investigation.

Then print k lines each containing a single integer 1 \le a_i \le n1≤a
i

≤n, the sorted indices of the photos you need to look at.

样例输入1

1
3
2 1 3

样例输出1

1
1

样例输入2

4
4
140 157 160 193
5
15 24 38 9 30
6
36 12 24 29 23 15
6
170 230 320 180 250 210

样例输出2

2
2
4

题意

找 k 组照片,每组照片中找出存在中间的身高比左边的身高小,右边的身高比左边的身高大,输出满足的照片数量及索引。

#include <bits/stdc++.h>

using namespace std;
const int N = 3e5 + 7;
int k, n, Max;
// a[N]输入的数,max_right[N] 当确定自己的位置时,右侧身高最高的高度
int a[N], max_right[N];
vector<int> ans;

int main() {
    scanf("%d", &k);
    for (int i = 1; i <= k; i++) {
        scanf("%d", &n);
        for (int j = 1; j <= n; j++) {
            scanf("%d", a + j);
        }
        for (int j = n; j > 0; j--) {
            if (a[j] > Max) {
                max_right[j] = a[j], Max = a[j];
            } else {
                max_right[j] = Max;
            }
        }
        set<int> st;
        Max = 0;
        for (int j = 1; j <= n; j++) {
            if (!st.size() || a[j] == max_right[j]) {
                st.insert(a[j]);
                continue;
            }
            auto pos = st.upper_bound(a[j]);
            if (pos != st.end()) {
                if (*pos < max_right[j]) {
                    ans.push_back(i);
                    break;
                }
            }
            st.insert(a[j]);
        }
    }
    printf("%d\n", ans.size());
    for (int i = 0; i < ans.size(); i++) {
        printf("%d\n", ans[i]);
    }
    return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值