Hdu4907task schedule (query set)

Source: Internet
Author: User

Question: hdu4907task schedule (query set)


You can view the meaning in Chinese.


Solution: query the set.


Code:

#include <cstdio>#include <cstring>#include <algorithm>#include <functional>using namespace std;const int N = 2e5 + 5;int num[N];int p[N];int n, m;void init () {sort (num, num + n, greater<int>());for (int i = 1; i < N; i++)p[i] = i;}int getParent (int q) {return q == p[q] ? q : p[q] = getParent(p[q]);}int main () {int T;scanf ("%d", &T);while (T--) {scanf ("%d%d", &n, &m);for (int i = n - 1; i >= 0; i--) scanf ("%d", &num[i]);init ();for (int i = 0; i < n; i++) p[num[i]] = getParent(num[i] + 1); int q;for (int i = 0; i < m; i++) {scanf ("%d", &q);printf ("%d\n", p[q]);}//printf ("%d\n", N);}return 0;}


Hdu4907task schedule (query set)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.