You are not logged in. Please login at www.codechef.com 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

4★deepak_097
933
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.

link

answered 24 Sep, 14:49

adzo261's gravatar image

3★adzo261
2898
accept rate: 37%

Thanks i got AC :)

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

Follow this question

By Email:

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

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "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:

×1,702
×262
×238
×155

question asked: 23 Sep, 18:15

question was seen: 188 times

last updated: 24 Sep, 17:39