Idleness limit exceeded codeforces719

@st0rmbrk , i have another question , wasn’t the test cases invalid , because as per the problem 1 <= n <= 2*10^5 , but in some test cases n is given as 0 , like in TC 2 , which was 0 1 1 ??

No, that’s actually the binary string and not n

but the problem statement is like this ,
image
where n is size of the string.

That’s the interaction part.
In the input format, they’ve shown given initial hidden binary string and t value.

3 Likes

That’s what @akshitm16 is saying that n is not there.

2 Likes

actually in every case they are showing hidden array and t which is 1 and k.

1 Like

Ok , now i get it , it was not the input that i was getting from the grader. Thank you @akshitm16 for clearing my doubt.

1 Like

You can use cout << "! " << i << endl instead of cout.flush(). I think because of FAST I/O, fflush(stdout) won’t work. @akshitm16 , can you confirm this?
EDIT: @st0rmbrk , remove the FAST I/O and check again.

1 Like

but why fflush(stdout) was not working when in question it was written that it will work for c++.

got it. @samarth2017 , @st0rmbrk , it was my first interactive problem in CF ( i think ) , so that’s why the confusion.

Yes it worked
Ac link → Submission #115344437 - Codeforces
Any specific reason for that ??.

I think with fast i/o, it gives output after taking all the input but I’m not sure.

2 Likes

You can read here, I also don’t know much about it. But in interactive problems, it is better to use “endl”. You won’t get TLE because of that atleast.

2 Likes

I dont think so, I used fast i/o and got AC. In interaction problems instead on “\n” use endl always because endl flushes the output immediately but “\n” accumulates everything then prints it. And most of the interactive problems are always binary search or ternary search :rofl:.

2 Likes
#include<bits/stdc++.h>
using namespace std; 

void recurse(int l,int r, int k)
{
	int mid=l+(r-l)/2;
	if(l==r)
	{
		if(k==1)
		{
			cout<<"! "<<l<<endl;
			return;
		}
		if(k==0)
		{
			cout<<"! "<<l+1<<endl;
			return;
		}
		return;
	}
	cout<<"? "<<l<<" "<<mid<<endl;
	int a;	cin>>a;
	if(mid-l+1-a>=k)
		recurse(l,mid,k);
	else
		recurse(mid+1,r,k-(mid-l+1-a));
	return;
}
 
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int n,t,k;
	cin>>n>>t>>k;
	int l=1,r=n;
	recurse(l,n,k);
	return 0;
}`

This was my working code for it by using fast i/o.

same happened with me, then I used cout.flush(). some users got ac without any of these.
weird.

thanks brother, not knowing about such thing. I define endl as “\n” :joy:

Yeah using “endl” is absolutely fine. This post is about using fflush(stdout) with FAST I/O on which @akshitm16 has commented.

1 Like

@st0rmbrkendl” by default performs flush operation.
you can use endl or fflush stdout for flush operation.
You can check my Solution here.
Solution Link
Link to Explanation

1 Like

According to you endl or fflush(stdout) both work but the Wrong Submission that i have provided above in the post contradict your assumption.
The solution that was provided @akshitm16 is that fflush(stdout) doesn’t work with Fast i/o and your solution only worked b/c of endl b/c fflush(stdout) doesn’t work .
I have made slight changes in your code to prove you this.
Submission link->Submission #115403078 - Codeforces
I had only remove endl before the fflush statement.
Although I have no understanding why is this happening but in above code if you remove Fast i/o it will work.