Difference of Strings

All submissions for this problem are available.
Sheldon has developed a new method of comparing two strings by taking their difference . The Difference of two strings $A$ and $B$ is defined as $\sum_{i=0}^{ min(  A , B  ) 1 }$ $ A_i B_i $ . (x denotes absolute value of x) . You are given $N$ strings and $Q$ queries. In each query you are given two integers $L$,$R$ and query string $Qs$. You have to find the sum of the difference of the query string with all the input strings in the range [$ L$,$R$ ]. ###Input:  The first line contains two space separated integers $N$ and $Q$.  Next N lines contains M S where M is the length of the string $S$.  Next Q lines contains two space separated integers L,R and a query string $Qs$. ###Output: For each query print the required answer. ###Constraints  $1 \leq N \leq 2000$  $1 \leq Q \leq 100000$  $1 \leq M \leq 400$  $1 \leq L,R \leq N$  $1 \leq Qs \leq 400$ ###Sample Input: 2 2 2 db 1 c 1 2 bc 2 2 bc ###Sample Output: 4 1 ###EXPLANATION: For first query "bc" $$ "db"  = 3 "bc" $$ "c"  = 1 so 1+3=4.Author:  aditya10_ 
Tags  aditya10_ 
Date Added:  4012019 
Time Limit:  2 sec 
Source Limit:  50000 Bytes 
Languages:  C, CPP14, JAVA, PYTH, PYTH 3.6, PYPY, CS2, PAS fpc, PAS gpc, RUBY, PHP, GO, NODEJS, HASK, rust, SCALA, swift, D, PERL, FORT, WSPC, ADA, CAML, ICK, BF, ASM, CLPS, PRLG, ICON, SCM qobi, PIKE, ST, NICE, LUA, BASH, NEM, LISP sbcl, LISP clisp, SCM guile, JS, ERL, TCL, kotlin, PERL6, TEXT, SCM chicken, PYP3, CLOJ, COB, FS 
Comments
 Please login at the top to post a comment.
SUCCESSFUL SUBMISSIONS
Fetching successful submissions