[Bzoj5179] [Jsoi2011] Task scheduling (left-leaning tree)

Source: Internet
Author: User

5179: [Jsoi2011] Task scheduling

Time Limit:10 Sec Memory limit:128 MB
Submit:5 Solved:4
[Submit] [Status] [Discuss]

Description

A supercomputer has a total of n CPUs. Now this supercomputer has a m mission to do, but it also has to take into account that it can't overheat the CPU. Fortunately, the supercomputer has already arranged the task, and all that is needed is for you to simulate its working process according to the ordered instructions. At first, none of the n CPUs were assigned any tasks. After that, you will be given the following classes of instructions (the CPU is numbered from 1 to n integers, the task is numbered from 1 to m) and the instruction format function add n k w assigns the K task (weighted to W) to n number cpudec N K w to reduce the weight of the K task by W (known K Task is assigned to n CPU) TRANS n1 n2 The task assigned to the N1 CPU is all transferred to the N2 number cpumin n Output the weight of the task with the least weight assigned to the N CPU task N W will be assigned to n The weight of the task with the least weight in the CPU task plus W, if the task with the smallest weight is not unique, the weight value is not changed and a line of "ERROR" is output

Input

Contains n+1 rows. The 1th line contains three positive integers n, M, K, respectively, representing the number of CPUs, the number of tasks, and the number of instructions. Line 2nd to n+1, each line containing an instruction. n≤500, m≤300000, k≤300000. guarantees that the weight of the task is within the range of a 32-bit signed integer. Ensure that a task is assigned only once (that is, at most one time). Ensure that W is a non-negative integer in the ADD, DEC, and work instructions. Ensure that the two parameters of the TRANS directive are not the same.

Output

Several rows, including the output of the Min statement and the "ERROR" output, one row for each output

Sample Input

2 3  -ADD1 2  -ADD1 1  -MIN1 Work1  -TRANS1 2MIN2ADD1 3  theTRANS2 1MIN1DEC1 3  $MIN1DEC1 1 205 Work1  the

Sample Output

 -  - -upERROR

Analysis: Naked can be stacked with the problem, with left-leaning tree can be confused

Code:

# include <iostream># include<cstdio># include<algorithm>using namespacestd;Const intN = 3e5 + A;intd[ +],n,m,k;structnode{intW,d,lc,rc,fa;} T[n];intMergeintXinty) {    if(!x)returny; if(!y)returnx; if(T[x].w >t[y].w) Swap (x, y); T[x].rc=merge (T[x].rc,y); T[T[X].RC].FA=x; if(T[t[x].rc].d >t[t[x].lc].d) Swap (T[X].RC,T[X].LC); T[X].D= T[t[x].rc].d +1; returnx;}voidEraseintXintYintz) {    intU = Merge (t[y].lc,t[y].rc), G =T[y].fa; if(D[x] = = y) d[x] =u; if(t[g].lc = = y) t[g].lc =u; Else if(t[g].rc = = y) t[g].rc =u; T[U].FA= G;T[Y].LC = T[y].rc = T[y].fa = T[Y].D =0; T[Y].W+=Z; D[X]=merge (d[x],y);}intMain () {scanf (" %d%d%d", &n,&m,&k);Charch[5];intx, Y, Z  while(k--) {scanf ("%s", CH); if(ch[0] =='A') {scanf (" %d%d%d",&x,&y,&z); T[Y].W=Z; D[X]=merge (D[x],y); }    if(ch[0] =='D') {scanf (" %d%d%d",&x,&y,&z); Erase (x, Y,-z); }    if(ch[0] =='T') {scanf ("%d%d",&x,&y); D[y]=merge (D[x],d[y]); D[X]=0; }    if(ch[0] =='M') {scanf ("%d",&x); printf ("%d\n", T[D[X]].W); }    if(ch[0] =='W') {scanf ("%d%d",&x,&y); BOOLFlag =true;intL = T[d[x]].lc,r =t[d[x]].rc; if(l && T[L].W = = T[D[X]].W) flag =false; if(r && t[r].w = = T[D[X]].W) flag =false; if(flag) erase (x,d[x],y); ElsePuts"ERROR"); }   }}

[Bzoj5179] [Jsoi2011] Task scheduling (left-leaning tree)

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.