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 [外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-bfPefZRB-1584776958559)(https://res.jisuanke.com/img/upload/137a30b1a0fba58fec561a0c1e680a948e00a6bc.png)]

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≤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≤n≤3×10^5 , the number of people on this photo.

The second line contains n distinct integers 1≤h1,h2,…,hn≤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×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≤ai≤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
#include <bits/stdc++.h>

using namespace std;
const int N = 3e5 + 10;
int a[N], T, n, cnt;
multiset<int> s1, s2;
vector<int> ans;

int main() {
    cin >> T;
    for (int t = 1; t <= T; t++) {
        s1.clear(), s2.clear();
        scanf("%d", &n);
        for (int i = 1; i <= n; i++)scanf("%d", &a[i]);
        s1.insert(a[1]);
        for (int i = 3; i <= n; i++)s2.insert(a[i]);
        for (int i = 2; i <= n - 1; i++) {
            auto it = s1.upper_bound(a[i]);
            if (it != s1.end() && *it < *(--s2.end())) {
                ans.push_back(t), cnt++;
                break;
            }
            s1.insert(a[i]), s2.erase(s2.find(a[i + 1]));
        }
    }
    printf("%d\n", cnt);
    for (auto it:ans)printf("%d\n", it);
    return 0;
}
发布了331 篇原创文章 · 获赞 28 · 访问量 1万+

猜你喜欢

转载自blog.csdn.net/qq_45323960/article/details/105011243
my
今日推荐