"bzoj3207" the mocking plan of the flower god ⅰhash+stl-map+ the MO team algorithm

Source: Internet
Author: User

Title Description

Background 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 spoken to xxx yet? "" "..." "and that's what you're talking about?" Hey, you're not stupid! "" ... "the DJ was very silent about the situation, and the DJ was very embarrassed when it happened. 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".

Input

1th 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;

Output

For every taunt to make a reply will be embarrassed output ' Yes ' otherwise output ' No '

Sample input

8 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 output

No
Yes
Yes
Yes
No

Main topic

Given a sequence of length n and m queries, each query needs to determine whether the given sequence of length k has occurred within the [L,r] range of the original sequence, or output " No", otherwise output "Yes".

Exercises

hash+stl-map+-Mo Team algorithm

Since the length of the inquiry sequence is given and does not exceed 20, we can pre-preprocess all successive sub-sequences with K in the original sequence and store them in a hash method, which is discretized with the map.

For each query to hash it out, if it does not appear in the original sequence of the direct answer is 0, otherwise with the MO team algorithm to run a bit better.

Note that each hash value corresponds to the discretization of the value to be preprocessed first, with the bucket maintenance occurrences, rather than with map<unsigned long long, int> CNT to store occurrences, otherwise it will tle.

The time complexity is probably $o ((n+m) (k+\log N) +m\sqrt N) $.

#include <cstdio> #include <cmath> #include <algorithm> #include <map> #define N 100010using namespace Std;typedef unsigned long long ull;const ull base = 1000003;struct Data{int L, R, BL, Id;ull x;}  Q[n];map<ull, int> ref;ull a[n], Val[n];int pos[n], cnt[n], Ans[n];bool CMP (data A, data b) {return A.BL = = B.bl ? A.R < B.R:A.BL < B.BL;} int main () {int n, m, K, I, J, si, LP = 1, RP = 0;ull t;scanf ("%d%d%d", &n, &m, &k), si = (int) sqrt (  n); for (i = 1; I <= n; i + +) scanf ("%llu", &a[i]), for (i = 1; I <= n-k + 1; i + +) {for (j = 1; j <= K; J + +) Val[i] = val[i] * base + a[i + j-1];if (Ref.find (val[i]) = = Ref.end ()) ref[val[i] [i;pos[i] = Ref[val[i]];}  for (i = 1; I <= m; i + +) {scanf ("%d%d", &AMP;Q[I].L, &AMP;Q[I].R), Q[I].BL = (q[i].l-1)/si, Q[I].R-= K-1, Q[i].id = I;for (j = 1; j <= K; j + +) scanf ("%llu", &t), q[i].x = q[i].x * base + t;} Sort (q + 1, q + M + 1, CMP); for (i = 1; I <= m; i + +) {if (Ref.find (q[i].x) = = Ref.end ()) Continue;while (RP < Q[I].R) RP + +, CNT[POS[RP]] + +, while (LP > Q[I].L) LP --, CNT[POS[LP]] + +, while (Rp > Q[I].R) CNT[POS[RP]]--, RP –; while (LP < Q[I].L) CNT[POS[LP]]--, LP + +; ans[q[ I].id] = cnt[ref[q[i].x]];} for (i = 1; I <= m; i + +) printf ("%s\n", Ans[i]? "No": "Yes"); return 0;}

"bzoj3207" the mocking plan of the flower god ⅰhash+stl-map+ the MO team algorithm

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.