Please Help :(

My code is running successfully for 5 testcases but it is failing for others. I have done the same thing as mentioned in the editorial using segment trees. Please provide any test case that my code might be failing. I have been stuck on this problem for days now and any help would be appreciated.

Problem Link: https://www.codechef.com/problems/HMAPPY1
Solution link : https://www.codechef.com/viewsolution/26152057

That solution still seems to be failing the testcase I sent you yesterday(?)

Edit:

Here’s a slightly smaller, and more striking, version:

4 28 2
1 1 0 0
?!?!?!?!?!?!?!?!?!?!?!?!?!?!
2 Likes

The code is working fine for the given test case
OUTPUT (For my code) :-
2
2
2
1
2
2
2
2
1
2
2
2
2
1

Thanks for replying though !

Perhaps I’m misunderstanding the question, but I get (added in some diagnostics :)):

Testcase Run
Processing query # 1  A is currently: 
 1 1 0 0
Query: ?
 maxNum1sInRun: 2
Processing query # 2  A is currently: 
 1 1 0 0
Query: ! - right-circular shift on a; result is: 
 0 1 1 0
Processing query # 3  A is currently: 
 0 1 1 0
Query: ?
 maxNum1sInRun: 2
Processing query # 4  A is currently: 
 0 1 1 0
Query: ! - right-circular shift on a; result is: 
 0 0 1 1
Processing query # 5  A is currently: 
 0 0 1 1
Query: ?
 maxNum1sInRun: 2
Processing query # 6  A is currently: 
 0 0 1 1
Query: ! - right-circular shift on a; result is: 
 1 0 0 1
Processing query # 7  A is currently: 
 1 0 0 1
Query: ?
 maxNum1sInRun: 1
Processing query # 8  A is currently: 
 1 0 0 1
Query: ! - right-circular shift on a; result is: 
 1 1 0 0
Processing query # 9  A is currently: 
 1 1 0 0
Query: ?
 maxNum1sInRun: 2
Processing query # 10  A is currently: 
 1 1 0 0
Query: ! - right-circular shift on a; result is: 
 0 1 1 0
Processing query # 11  A is currently: 
 0 1 1 0
Query: ?
 maxNum1sInRun: 2
Processing query # 12  A is currently: 
 0 1 1 0
Query: ! - right-circular shift on a; result is: 
 0 0 1 1
Processing query # 13  A is currently: 
 0 0 1 1
Query: ?
 maxNum1sInRun: 2
Processing query # 14  A is currently: 
 0 0 1 1
Query: ! - right-circular shift on a; result is: 
 1 0 0 1
Processing query # 15  A is currently: 
 1 0 0 1
Query: ?
 maxNum1sInRun: 1
Processing query # 16  A is currently: 
 1 0 0 1
Query: ! - right-circular shift on a; result is: 
 1 1 0 0
Processing query # 17  A is currently: 
 1 1 0 0
Query: ?
 maxNum1sInRun: 2
Processing query # 18  A is currently: 
 1 1 0 0
Query: ! - right-circular shift on a; result is: 
 0 1 1 0
Processing query # 19  A is currently: 
 0 1 1 0
Query: ?
 maxNum1sInRun: 2
Processing query # 20  A is currently: 
 0 1 1 0
Query: ! - right-circular shift on a; result is: 
 0 0 1 1
Processing query # 21  A is currently: 
 0 0 1 1
Query: ?
 maxNum1sInRun: 2
Processing query # 22  A is currently: 
 0 0 1 1
Query: ! - right-circular shift on a; result is: 
 1 0 0 1
Processing query # 23  A is currently: 
 1 0 0 1
Query: ?
 maxNum1sInRun: 1
Processing query # 24  A is currently: 
 1 0 0 1
Query: ! - right-circular shift on a; result is: 
 1 1 0 0
Processing query # 25  A is currently: 
 1 1 0 0
Query: ?
 maxNum1sInRun: 2
Processing query # 26  A is currently: 
 1 1 0 0
Query: ! - right-circular shift on a; result is: 
 0 1 1 0
Processing query # 27  A is currently: 
 0 1 1 0
Query: ?
 maxNum1sInRun: 2
Processing query # 28  A is currently: 
 0 1 1 0
Query: ! - right-circular shift on a; result is: 
 0 0 1 1
2
2
2
1
2
2
2
1
2
2
2
1
2
2

1 Like

Thank you so so much !

1 Like

Finally got the AC after two very frustrating days ! Thanks again for being there for beginners ! :slight_smile:

1 Like

Glad you got it sorted :slight_smile: It’s a good habit to get into to

a) Write a naive, brute-force solution (usually very easy); and
b) assert that your optimised solution matches the brute force one; and
c) Write a random testcase generator; and
d) Keep throwing random testcases at your solution until you find one where the optimised and brute-force solutions don’t match.

This is (roughly) how I found those testcases :slight_smile:

3 Likes