You are not logged in. Please login at to post your questions!


Help me in the "AND Square Subsegments" problem (codechef long challenge).

By reading the editorial i wrote my code using segment tree with lazy propagation but on submitting i am getting AC on 2 test cases and TLE on remaining :( I am getting TLE even in the first subtask.

I checked my code by taking test cases of order n=10^3 , q=10^3 and in all those test cases my code is working fine.

Please anyone help me to get rid over it. That will be of great help indeed.

My solution — link

problem Link- link

asked 23 Sep, 18:15

deepak_097's gravatar image

accept rate: 0%

edited 23 Sep, 19:15

While finding the next group index, we won't see the next change index over zero bits of a number because zero bits are anyway not going to change.
So the next change index should be the minimum of next change indexes over the one bits of a number.
So this code snippet on line 183:
for(j=0;j<=30;j++) { mn=min(mn,dp[j][z]); }

Will change to:
for(j=0;j<=30;j++) { if( (1 << j) & val) mn=min(mn,dp[j][z]); }

You can have a look at my upsolved solution.


answered 24 Sep, 14:49

adzo261's gravatar image

accept rate: 37%

Thanks i got AC :)

(24 Sep, 17:39) deepak_0974★
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here



Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text]( "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported
  • mathemetical formulas in Latex between $ symbol

Question tags:


question asked: 23 Sep, 18:15

question was seen: 188 times

last updated: 24 Sep, 17:39