HDU 5204 Rikka with sequence (Bestcoder Round #37)

Source: Internet
Author: User

Rikka with sequenceTime limit:2000/1000 MS (java/others) Memory Limit: 65536/65536 K (java/others)
Total submission (s): 378 Accepted Submission (s): 75


Problem Descriptionas We know, Rikka is poor at math. Yuta is worrying on this situation, so he gives Rikka some math tasks to practice. There is one of the them:


Yuta has a sequence. Because the sequence is very self-willed (renxing) in first the sequence is empty. And then Yuta does n operations on the sequence, each operation is either of these:


1.ADD a number w into each gap of the sequence. For example if w=3 and the sequence before is "2 4", it'll be changed to "3 2 3 4 3".
**after the first operation of the first type, there is only one number in the sequence**


2.Query the kth small number in the subsequence [L,r]. For example if k=2, l=2, r=4 and the sequence are "3 2 3 4 2", the answer would be 3.


Yuta wants Rikka to tell him the answer of each query.


It is too difficult for Rikka. Can you help her?
Inputthe First line contains one number n(n≤100000) . Each of the following n Lines describes an operation:if it is "1 W" it'll be the first type. Otherwise if it is "2 L R K", it'll be the the second type. (1≤W≤ ten 9 ,L≤R≤ ten )
R won't is larger than the length of the sequence

Outputfor each query operation, output one number–the answer.
Sample Input
61 31 12 2 3 21 22 3 5 22 1 4 4

Sample Output
323

official:
The question looks like a very powerful one. Actually, it's a flood problem. For an inquiry, consider this inquiry before the first
      
          i   
  
 
      
 Modify operation, the first position in the sequence is
     
      
           2i? 1  
 

      
     。 And then, within the scope of the inquiry, only
      
          -   
  
 
      
 The number, the violent dafa is good, the complexity of time
      
          o(nlOgR) 
  
 
      
 ,
      
          R   
  
 
      
 is the maximum subscript for the inquiry.
PS: Self-simulation will find that the number I want to insert, the number of inserts in the entire interval is 2^ (i-1), and in [1,r] also meet, the number of the number of inserts after a number must be twice times the number of previous inserts, or twice times +1, know this after, [l,r]=[1,r]-[1 , L-1], so sum[i]+=v* (x+1)/2; in [1,r] v is 1, in [1,l-1] v is-1, the Order of I at this time is the opposite of the insertion order.
Code:
#include <iostream> #include <cstdio> #include <cstring> #include <algorithm>using namespace    std;const int maxn=110000;int a[maxn],b[maxn];long long sum[maxn];int len=69;void digt (Long long x,int v) {int i=0;        while (x) {sum[i]+=v* (x+1)/2;        X=X/2;    i++; }}bool cmp (int x,int y) {return a[len-x]<a[len-y];}    int main () {int t,op;    scanf ("%d", &t);    Long Long L,r,k,ans;        while (t--) {scanf ("%d", &op);        if (op==1) {scanf ("%d", &a[++len]);            } else {scanf ("%i64d%i64d%i64d", &l,&r,&k);            for (int i=0;i<=100;i++) sum[i]=0;            Digt (r,1);            Digt (l-1,-1);            for (int i=0;i<=69;i++) b[i]=i;            Sort (b,b+70,cmp);            ans=0;                for (int i=0;i<70;i++) {//cout<<i<< "" <<sum[b[i]]<<endl; if (ans+sum[b[i]]> =k) {printf ("%d\n", A[len-b[i]]);                Break                } else {ans+=sum[b[i]]; }}}} return 0;}





HDU 5204 Rikka with sequence (Bestcoder Round #37)

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.