Interval merge---codeforces 558d:gess Your-out! Ii

Source: Internet
Author: User

D. Guess Your-out! Ii
problem ' s link:http://codeforces.com/problemset/problem/558/d

Mean:

A tree full of two forks, a leaf node in the tree is the exit, the purpose is to find this exit. Given the results of Q queries, each result tells us whether the leaf nodes covered in layer I (L,R) contain exits.

Analyse:

Basic idea: Multiple intervals to find the intersection.

Specific implementation:

For each inquiry, turn it into the bottom. And instead of asking for the L,r interval in the form of (leftmost, l-1) and (r+1, rightmost), it all becomes a description in the (l,r) interval.

Interval statistics:

Sorts the set of start and end points of the left and right intervals. Then find the interval of the answer, if the interval length = 1, the answer is the only one; length >1, the answer is not unique; length = 0, no solution.

Trick: it explodes int.

Time Complexity:o (n)

Source Code:

/** This code was made by crazyacking* verdict:accepted* submission date:2015-07-16-11.55* time:0ms* MEMORY:137KB*/#include<queue>#include<cstdio>#include<Set>#include<string>#include<stack>#include<cmath>#include<climits>#include<map>#include<cstdlib>#include<iostream>#include<vector>#include<algorithm>#include<cstring>#defineLL Long Long#defineULL unsigned long Longusing namespacestd; LL l[Wuyi], r[Wuyi];intMain () {Ios_base::sync_with_stdio (false ); Cin.tie (0 ); l[1] =1, r[1] =1;  for(inti =2; I <= -; ++i) L[i] = l[i-1] <<1, r[i] = (L[i] <<1) -1; inth, Q; CIN>> h >>Q; if(q = =0 )      {            if(H = =1) puts ("1" ); ElsePuts"Data not sufficient!" ); return 0; } Map<ll,int>MP;  for(inti =0; i < Q; ++i) {LL level, left, right, type, gap; CIN>> level >> left >> right >>type; Gap= h-Level ;  while(GAP) {gap--; Left<<=1; Right= ((right +1) <<1) -1; }            if(type) {Mp[left]++; Mp[right+1]--; }            Else{Mp[l[h]]++; Mp[left]--; Mp[right+1]++; MP[R[H]+1]--; }} LL ans, sum=0, Ans_gap =0, Mid_pre =-1; Map<ll,int:: Iterator it =Mp.begin ();  for(; it! = Mp.end (); + +it) {Sum+ = (it->second); if(Mid_pre! =-1) {Ans_gap+ = (it->first)-Mid_pre; Ans=Mid_pre; }            if(sum = = q) mid_pre = (it->First ); ElseMid_pre =-1; }      if(Ans_gap = =1) cout << ans <<Endl; Else if(Ans_gap >1) puts ("Data not sufficient!\n" ); ElsePuts"Game cheated!\n" ); return 0;}/**/

Interval merge---codeforces 558d:gess Your-out! Ii

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.