# help in https://www.codechef.com/problems/CLONEME

i have solved this using persistent segment trees and my complexity is : Q(log N)^2 but it still gives TLE!!
i have tried fast IO but it does not work…can someone help me with this…

without fast IO : https://www.codechef.com/viewsolution/15168520

with fast IO : https://www.codechef.com/viewsolution/15168577

logic : my main logic is that the first position where the prefix sum(and sum of squares) and the suffix sum(and sum of squares) differs …if they are same (i handle the case when the two ranges are exactly same) then and only then there is only one mismatch(as the prefix sum may collide so, i take sum of squares also)…now, i have build persistent segment tree based on the position of that element in base (my base is the numbers from 1 to 100001) and in the tree i stored the sum of values, sum of square of values, and the number of elements till…and then do two binary searches (in the code foo() function) one to find the first position of difference of prefix sums and other to find the same for suffix and then just checking for their equality.

Can you please give your logic as well. the code is too long to deduce logic from. Thanks @vijju123 if you still have any problem then please post it
{"ft_lang_label":"__label__en","ft_lang_prob":0.88012856,"math_prob":0.9350345,"size":1061,"snap":"2021-31-2021-39","text_gpt3_token_len":244,"char_repetition_ratio":0.119205296,"word_repetition_ratio":0.0,"special_character_ratio":0.24222432,"punctuation_ratio":0.07798165,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.974067,"pos_list":[0,1,2,3,4,5,6],"im_url_duplicate_count":[null,null,null,null,null,null,null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2021-07-24T02:23:47Z\",\"WARC-Record-ID\":\"<urn:uuid:1253e98f-389c-4efe-81db-976b32b68bfa>\",\"Content-Length\":\"19501\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:9883a1dc-c3ff-4e80-b943-335747ef3dfd>\",\"WARC-Concurrent-To\":\"<urn:uuid:1251663c-eaf4-4d3d-9369-1cdd85b6a04e>\",\"WARC-IP-Address\":\"54.166.204.247\",\"WARC-Target-URI\":\"https://discusstest.codechef.com/t/help-in-https-www-codechef-com-problems-cloneme/16547\",\"WARC-Payload-Digest\":\"sha1:CI2VFKFFDNJBTZ7CX25A7DNFI532PJGP\",\"WARC-Block-Digest\":\"sha1:ZHI7K3HVASEME35SWPQQPMASRYQRV72M\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2021/CC-MAIN-2021-31/CC-MAIN-2021-31_segments_1627046150067.87_warc_CC-MAIN-20210724001211-20210724031211-00026.warc.gz\"}"}