[BZOJ3207] Flower God's taunt Plan Ⅰ (Chairman tree)

Source: Internet
Author: User

DescriptionBackground flower God is God, a big hobby is to taunt Big J, for example: "Hey you silly not silly!" "HQZ: Big Stupid J" "" This problem has been J excrement!! "J how this program runs so fast!" J's going to hit the counter!  ”  ...... Describe the day the DJ is giving us all the Konjac konjac topic, the flower God on the side to do the bored, ran to the side with our Konjac Konjac together listen.  The following is a partial excerpt: 1. "J What are you talking about!" "I'm talking about xxx!. "Ah you silly not silly!" So troublesome, direct xxx and XXX will be good!  ”  “......” 2. "J Have you told me about XXX?"  ”  “......” "That's not what you're talking about?" Hey, you're not stupid!  ”  “......”  DJ is very silent on this situation, and often this happens, the DJ is very awkward.  After the Konjac Konjac study, DJ before the lecture there will be a length of n program, we can think of it as a sequence; Similarly, the flower God will have a taunt before the lecture, there are M, each time in the X to Y to start the taunt, in order to reduce the difficulty, the length of each taunt program is certain, for K.  The flower God taunt DJ makes the DJ awkward in need of conditions: in X~y time the DJ did not talk about the flower God's taunt scheme, that is, J's lecture plan x~y no flower God's taunt scheme "so that the flower God will taunt J will not say." After the public Konjac Konjac efforts, before a lecture to get the flowers God taunt each of the programs, DJ learned this news after Joy Unceasingly, DJ want to know whether every taunt of flower God will let DJ embarrassed "say no words to".Input1th Row 3 Number n,m,k, 2nd row n number, meaning above, 3rd line to 3+m-1 line, each line k+2 number, first two number is X, y, then K number, meaning as above;OutputFor every taunt to make a reply will be embarrassed output ' Yes ' otherwise output ' No 'Sample Input8 5 3
1 2 3 4 5 6 7 8
2 5 2) 3 4
1 8 3) 2 1
5 7 4) 5 6
2 5 1) 2 3
1 7 3) 4 5
Sample OutputNo
Yes
Yes
Yes
No
HINTAll data in the problem is not more than 2*10^9; guaranteed scheme sequence of each digital <=n 2~5 2 3 4 of the scheme, output no, that the DJ will not be embarrassed 1~8 No 3 2 1 scheme, output Yes, indicating that the DJ will be embarrassed 5~7 No 4 5 6 scheme, output Yes, indicating that the DJ will be embarrassed 2~5 No 1 2 3 scheme, output Yes, indicating that the DJ will be embarrassed 1~7 3 4 5 scheme, output No, that the DJ will not be embarrassed 1<=n<=100000; 1<=m<=100000; y-x+1<=n; k<=y-x+1&k<=20; x<=y;Source

Original Memphis

Solution

CTSC on the first time to write the chairman of the tree, unexpectedly,, and then on Hing (S) Fen (B) to find the chairman of the tree to consolidate the problem. Some people say: do not write in the exam you will not be the algorithm, perhaps the pull [beep-] it.

First, all the strings of K-long hash, you can use the line tree to query whether a number in the interval has occurred. But this requires $n$ tree, and each tree $3n$ a knot ... Mle*tle and so on.

The HJT chairman of the Nest made out a data structure that makes space-time complexity all $o (NLOGN) $ (applause where)

Well, it's about two pointers, one representing the old tree and one representing the new tree. The node of a tree indicates how many numbers are in a certain section of the weight range. Each tree represents $[1, and all the numbers in the i]$ range

Since there is only one leaf node difference between the two adjacent trees, starting from the root, a son copies the corresponding node of the old number, the other son opens a new point, and then handles the node recursively. Because each achievement increases the number of nodes in a chain by $ (LOGN) $, the time and Space complexity is $o (NLOGN) $

Query answer is to $[1, r]$ answer minus $[1, l-1]$ answer, each search to the leaf knot end, time complexity $o (MLOGN) $

The problem is done.

(I don't know what I'm talking about)

1#include <bits/stdc++.h>2 using namespacestd;3typedefLong Longll;4 structHjtree5 {6     intL, R, sum;7}a[2000005];8 intd[100005], ql[100005], qr[100005], Ctot, root[100005], Ptot;9ll sh[200005], cd[200005];Ten   One voidUpdateintO1,int&o2,intLintRintID) A { -     intMid = (L + r) >>1; -     if(!O2) O2 = + +Ptot; theA[o2].sum = A[o1].sum +1; -     if(L = = r)return; -     if(ID <= mid) A[O2].R =A[O1].R, Update (A[O1].L, A[O2].L, L, Mid, id); -     ElseA[O2].L = A[O1].L, update (A[O1].R, A[O2].R, Mid +1, R, id); + } -   + intQueryintO1,intO2,intLintRintID) A { at     intMid = (L + r) >>1; -     if(L = = r)returnA[o2].sum-a[o1].sum; -     if(ID <= mid)returnquery (A[O1].L, A[O2].L, L, Mid, id); -     returnQuery (A[O1].R, A[O2].R, Mid +1, R, id); - } -   in intMain () - { to     intN, M, K, TMP; +scanf"%d%d%d", &n, &m, &k); -      for(inti =1; I <= N; i++) thescanf"%d", D +i); *      for(inti =1; I <= N-k +1; i++) $          for(intj =0; J < K; J + +)Panax NotoginsengSh[i] = sh[i] *998244353+ D[i +j]; -      for(inti =1; I <= N-k +1; i++) theCd[i] =Sh[i]; +      for(inti =1; I <= m; i++) A     { thescanf"%d%d", QL + i, QR +i); +          for(intj =1; J <= K; J + +) -         { $scanf"%d", &tmp); $Sh[n-k +1+ i] = sh[n-k +1+ i] *998244353+tmp; -         } -Cd[n-k +1+ i] = sh[n-k +1+i]; the     } -Sort (CD +1, CD + n-k + M +2);Wuyi      for(inti =1; I <= n-k + M +1; i++) theSh[i] = lower_bound (CD +1, CD + n-k + M +2, Sh[i])-cd; -      for(inti =1; I <= N-k +1; i++) WuUpdate (Root[i-1], Root[i],1,200000, (int) sh[i]); -      for(inti =1; I <= m; i++) AboutPuts (query (root[ql[i)-1], Root[qr[i]-K +1],1,200000, (int) Sh[n-k +1+ i])?"No":"Yes"); $     return 0; -}
View Code

[BZOJ3207] Flower God's taunt Plan Ⅰ (Chairman 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.