Ecnuoj 2149 Gorgeous queues

Source: Internet
Author: User

Gorgeous queue

Time limit:3000ms Memory limit:65536kb
Total submit:531 accepted:68

Description

Every year, there are many new students come to our school, recently, the leadership of our school to test the ability of new students, came up with a way to test:
The leaders define a queue, the elements in the queue are stored sequentially, and the leaders define several operations of the queue:
A) Insert X to add an element x to the end of the queue
b) Delete, delete the first element before the queue
c) minelement Delete the smallest element in the queue
HINT:
Element x for 1.insert (0<=x<=1000000)
2. The elements in the queue are unique and duplicate elements are not present
3. Number of operations for each set of test data (0<=op<=50000)

Input

First a positive integer n, which represents the number of operations:
Next from 2 to N+1 line:
Each line begins with a string s, with 3 kinds of strings: insert, delete, or minelement
For insert next there is an integer x, which represents the element that inserts the queue
For delete, remove the elements of the first team
For Minelement, returns the smallest element in the queue and removes the element from the queue

Output

For each operation, output a different answer:

For INSERT, the total number of elements in the output queue n
For delete, delete the first element of the team and output the first element of the team X
For minelement, the smallest element in the output queue X. and remove this element from the queue

Sample Input

6
Insert 1
Insert 2
Insert 3
Insert 4
Delete
Minelement

Sample Output

1
2
3
4
1
2

Source

Gorgeous queue

Problem Solving: No other method was found, forced on the line tree.

1#include <bits/stdc++.h>2 using namespacestd;3 Const intMAXN =200010;4 Const intINF =0x3f3f3f3f;5 structNode {6     intLT,RT,MINV;7} tree[maxn<<2];8 intret;9 voidBuildintLtintRtintv) {Tentree[v].lt =lt; OneTree[v].rt =RT; ATREE[V].MINV =INF; -     if(LT = = RT)return; -     intMid = (lt + rt) >>1; theBuild (lt,mid,v<<1); -Build (mid+1,rt,v<<1|1); - } - voidUpdateintLtintRtintVintval) { +     if(LT <= tree[v].lt && RT >=tree[v].rt) { -RET =TREE[V].MINV; +TREE[V].MINV =Val; A         return ; at     } -     if(LT <= tree[v<<1].RT) Update (lt,rt,v<<1, Val); -     if(Rt >= tree[v<<1|1].lt) Update (lt,rt,v<<1|1, Val); -TREE[V].MINV = min (tree[v<<1].minv,tree[v<<1|1].MINV); - } - intHeadintv) { in     if(tree[v].lt = =tree[v].rt) { -         returntree[v].lt; to     } +     if(tree[v<<1].MINV < INF)returnHead (v<<1); -     if(tree[v<<1|1].MINV < INF)returnHead (v<<1|1); the } * intTailintv) { $     if(tree[v].lt = = tree[v].rt)returntree[v].lt;Panax Notoginseng     if(tree[v<<1|1].MINV < INF)returnTail (v<<1|1); -     if(tree[v<<1].MINV < INF)returnTail (v<<1); the } + intThemin (intv) { A     if(tree[v].lt = = tree[v].rt)returntree[v].lt; the     if(tree[v<<1].MINV < tree[v<<1|1].MINV)returnThemin (v<<1); +     if(tree[v<<1|1].MINV < tree[v<<1].MINV)returnThemin (v<<1|1); - } $ intMain () { $     intM,val,siz =0, H; -     Charop[ -]; -scanf"%d",&m); theBuild0,200000,1); -      while(m--) {Wuyiscanf"%s", op); the         if(op[0] =='I') { -scanf"%d",&val); Wu             if(Siz = =0) { -Update100000,100000,1, Val); About}Else { $h = Tail (1); -Update (H +1, H +1,1, Val); -             } -siz++; Aprintf"%d\n", siz); +}Else if(op[0] =='D') { theH = Head (1); -Update (H,H,1, INF); $printf"%d\n", ret); thesiz--; the}Else if(op[0] =='M') { theH = themin (1); theUpdate (H,H,1, INF); -printf"%d\n", ret); insiz--; the         } the     } About     return 0; the}
View Code

Ecnuoj 2149 Gorgeous queues

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.