Bzoj 4341 [CF253 Printer] Problem Solving report

Source: Internet
Author: User

At first glance the problem seems to be a two-point priority to engage in ...

Can you actually do that?

I'm not going to ...

So I began to talk about my mess algorithm:

First of all, we must prioritize the tasks by priority.

Maintain a moment of work with a line-of-business line-up tree.

Then insert the task in turn, remember as I, in particular, the right end of the two points, and then make the entire range into a "work" state.

Before I was inserted, it was also necessary to check if the right end of the mysterious task in the current situation was the one required in the title.

If it is, and the priority of i-1 and I is not adjacent or I is the highest priority, then the priority for that mystery task is the priority of I +1.

Then insert this mystery task and consider task I.

After writing this, I found out. A point to run around 2.5s.

In fact, in the back, more than 10^9 time is 1, then 0.

So here we just need to maintain this point of demarcation.

The upper bound of the segment tree is changed from 10^15 to 10^9, one times faster than the original.

So we can AC.

1#include <cstdio>2#include <algorithm>3 using namespacestd;4typedefLong LongLL;5 Const intN =50000+5;6 Const intM =15000000+5;7 Const intT =1000000000;8  9 intN, Root, tot, ans_p;TenLL end, Tend =T, Owari, ans[n]; One   A structSegment_tree - { -     intL, R, sum; the }h[m]; -   - structTask - { +     ints, T, p, id; -Task (int_s =0,int_t =0,int_p =0,int_id =0) {s = _s, t = _t, p = _p, id =_id;} +     BOOL operator< (ConstTask a)Const A     { at         returnp >A.P; -     } - }p[n]; -   -InlinevoidModify (int&x,intLintRintSintt) - { in     if(!x) x = + +tot; -     if(L = = s && r = = t) h[x].sum = r-l +1; to     if(H[x].sum = = R-l +1)return ; +LL mid = L + R >>1; -     if(T <=mid) Modify (H[X].L, L, Mid, S, T); the         Else if(S > Mid) Modify (H[X].R, Mid +1, R, S, T); *         ElseModify (H[X].L, L, Mid, S, mid), Modify (H[X].R, Mid +1, R, Mid +1, T); $H[x].sum = H[h[x].l].sum +h[h[x].r].sum;Panax Notoginseng } -   theInline LL Query (intXintLintRintSintt) + { A     if(!x)return 0; the     if(H[x].sum = = R-l +1)returnT-S +1; +     if(L = = s && r = = t)returnh[x].sum; -LL mid = L + R >>1; $     if(T <= mid)returnQuery (H[X].L, L, Mid, S, T); $         Else if(S > Mid)returnQuery (H[X].R, Mid +1, R, S, T); -         Else returnQuery (H[X].L, L, Mid, S, mid) + query (H[X].R, Mid +1, R, Mid +1, T); - } the   - inline LL Calc (Task x)Wuyi { the     intNeed =x.t; -     intblank = T-x.s +1-Query (1,0, T, X.s, T); Wu     if(Blank < need)returnNeed-blank +Tend; -     intL = x.s, r =T; About      while(L <R) $     { -         intMID = L + R >>1; -blank = Mid-x.s +1-Query (1,0, T, X.s, mid); -         if(Blank < need) L = mid +1; A             ElseR =mid; +     } the     returnl; - } $   the intMain () the { thescanf"%d", &n); the      for(inti =1; I <= N; i + +) -     { in         ints, T, p; thescanf"%d%d%d", &s, &t, &p); the         if(p = =-1) p =0; AboutP[i] =Task (S, T, P, i); the     } theSort (P +1, P + n +1); thescanf"%lld", &end); +Ans[p[n].id] =end; -      for(inti =1; I <= N; i + +) the     {Bayi         if(ans_p)Gotodeal; theOwari =Calc (P[n]); the         if(Owari +1= = End && (i = =1|| P[I].P! = p[i-1].P-1)) -         { -ans_p = P[I].P +1; theModify (Root,0, T, P[n].s, Owari < T?owari:t); theTend = Tend > Owari?Tend:owari; the         } the           - deal:; the         if(i = = N)Continue ; theOwari =Calc (P[i]); theModify (Root,0, T, P[i].s, Owari < T?owari:t);94Tend = Tend > Owari?Tend:owari; theAns[p[i].id] = Owari +1; the     } theprintf"%d\n", ans_p);98      for(inti =1; I <= N; i + +) Aboutprintf"%lld%c", ans[i], i = = n?'\ n':' '); -      101     return 0;102}
4341_gromah

Bzoj 4341 [CF253 Printer] Problem Solving report

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.