HDU 5089 Assignment (rmq + binary or monotonic Queue)

Source: Internet
Author: User

HDU 5089 Assignment (rmq + binary or monotonic Queue)

 

Assignment Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Total Submission (s): 557 Accepted Submission (s): 280



Problem Description Tom owns a company and he is the boss. there are n staffs which are numbered from 1 to n in this company, and every staff has a ability. now, Tom is going to assign a special task to some staffs who were in the same group. in a group, the difference of the ability of any two staff is less than k, and their numbers are continuous. tom want to know the number of groups like this.
Input In the first line a number T indicates the number of test cases. Then for each case the first line contain 2 numbers n, k (1 <= n <= 100000, 0 Output For each test, output the number of groups.
Sample Input
24 23 1 2 410 50 3 4 5 2 1 6 7 8 9

Sample Output
528HintFirst Sample, the satisfied groups include:[1,1]、[2,2]、[3,3]、[4,4] 、[2,3]  

Author FZUACM
Source 2015 Multi-University Training Contest 1
Recommend We have carefully selected several similar problems for you: 5299 5298 5297 5296 5295

 

 

 

Rmq + binary

 

#include
  
   #include
   
    #include
    
     #include#include
     
      #include
      
       #include
       
        #include
        
         #include
         
          #include
          #define L(x) (x<<1)#define R(x) (x<<1|1)#define MID(x,y) ((x+y)>>1)#define eps 1e-8typedef __int64 ll;const int mod=1e9+7;using namespace std;#define N 100007int a[N],n;int dpmin[N][25],dpmax[N][25];int k;inline bool judge(int le,int ri){ int kk=log2((ri-le+1)*1.0); int mi=min(dpmin[le][kk],dpmin[ri-(1<
           
            >1; if(judge(i,mid)) { p=mid; le=mid+1; } else ri=mid-1; } ans+=p-i+1; } printf(%I64d,ans); } return 0;}
           
         
        
       
      
     
    
   
  

 

 

Monotonous queue
#include
  
   #include
   
    #include
    
     #include#include
     
      #include
      
       #include
       
        #include
        
         #include
         
          #include
          #define L(x) (x<<1)#define R(x) (x<<1|1)#define MID(x,y) ((x+y)>>1)#define eps 1e-8using namespace std;const int mod=1e9+7;#define INF 0x3f3f3f3fconst int N=100005;int mique[N],maque[N],mihead,mahead,mitail,matail;int n,a[N],k;int pre,now;__int64 ans;inline void miinque(int i){ while(mihead
           
            =1) ans-=(__int64)(prelen+1)*(prelen)/2; pre=n-1; } printf(%I64d,ans+n); } return 0;}
           
         
        
       
      
     
    
   
  


 

 

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.