Hdu 5249 interval K-Large (learning the pointers of the tree-like array)

Source: Internet
Author: User

KpiTime limit:2000/1000 MS (java/others) Memory limit:32768/32768 K (java/others)
Total submission (s): 205 Accepted Submission (s): 70


Problem description After you work, KPIs are all you have. I have developed a service that has gained a lot of popularity. Billions of of requests are pushed to a large pipeline and the service pulls requests from the pipe header at the same time. Let's define each request to have an important value. My KPI is calculated by the intermediate value of the important value requested within the current pipeline. Now I'm going to give you a service record, and sometimes I want to know the important worth of requests in the current pipeline.
Input has about 100 sets of data.

The first row of each group of data has one n(1≤n≤10000) , representing the number of service records.

Next, there are n rows, each of which has 3 forms.
"In X": represents an important value of x(0≤x ≤ 9 ) The request was pushed into the pipeline.
"Out": the request to pull the pipe header on behalf of the service.
"Query: On behalf of I want to know the middle value of the request important value in the current pipeline. That is to say, if there are M requests in the current pipeline, I would like to know, ascending sort after the first F LooR(m/2)+ 1 th Important value of the request.

To make the problem simple, all x is different, and if there are no values in the pipeline, there will be no "out" and "query" operations.

Output for each set of data, first a row

Case #i:
Then each time "query", output the middle value of important values in the current pipeline.

Sample Input
6in 874queryoutin 24622in 12194query

Sample Output
Case #1:87424622

SOURCE2015 year Baidu Star Program Design Competition-Preliminary (1)
Recommendhujie | We have carefully selected several similar problems for you:5251 5250 5248 5247 5246

The chairman of the tree can do whatever it is doing. Listen to other people say that the tree array can also be done, so learning the next, really magical


#include <cstdio> #include <cstring> #include <iostream> #include <algorithm>using namespace std;const int MAXN = 1e4 + 10;int c[maxn],tot;void Modify (int x,int d) {for (int i = x; i <= tot; i + = I&-i) C[i] + = D;} int findk (int k,int limt) {int ans = 0,CNT = 0;for (int i = LIMT; I >= 0; i--) {ans + = (1<<i); if (Ans > tot | | cn T + C[ans] >= k) ans-= (1<<i), else cnt + = C[ans];} return ans + 1;} Char q[maxn];int date[maxn],sorted[maxn];int Main (int argc, char const *argv[]) {int n;int cas = 1;while (scanf ("%d", &n = = 1) {printf ("Case #%d:\n", cas++), int cur = 1;for (int i = 1; I <= n; i++) {char cmd[10];scanf ("%s", cmd); Q[i] = cmd[0];if (q[i]== ' i ') {scanf ("%d", date + cur); sorted[cur] = Date[cur];++cur;}} tot = Cur;memset (c,0,sizeof (c[0)) *tot); sort (sorted+1,sorted+cur); int QL = 0,QR = 0;for (int i = 1; I <= n; i++) {if (Q[i] = = ' I ') {++qr;int pos = Lower_bound (SORTED+1,SORTED+CUR,DATE[QR])-sorted; Modify (pos,1);} else if (q[i] = = ' O ') {++ql;int pos =Lower_bound (SORTED+1,SORTED+CUR,DATE[QL])-sorted; Modify (pos,-1);} else {int k = (qr-ql + 2) >> 1;printf ("%d\n", Sorted[findk (k,18)]);}}} return 0;}


Hdu 5249 interval K-Large (learning the pointers of the tree-like array)

Related Article

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.