Negationist's blog

By Negationist, history, 5 weeks ago, In English

In the problem: https://mirror.codeforces.com/contest/2022/problem/C. My implementation involves pushing the strings one character forward to fix the off by one. In the official solution, they push the votes in a different way, here is a link: https://mirror.codeforces.com/blog/entry/135095. Look for "vot[k][i+1]=1;." why does my way not work? Here is the code:

My Code

Full text and comments »

  • Vote: I like it
  • -1
  • Vote: I do not like it

By Negationist, history, 6 weeks ago, In English

I feel like there are certain questions which have a specific type of implementation(maybe I am just thinking of implementation tho i feel like this may be different) where, even though you may know exactly what pattern you want to create, finding an implementation that is simple and doesn't was time with potential bugs and corner cases and such is hard. For example, I was just doing the problem: https://mirror.codeforces.com/contest/1898/problem/C.

In this problem, even though I found the conditions for a solution and the cycles in my graph that I needed, I struggled to put it together into code and went and looked at jiangly's code for it: https://mirror.codeforces.com/contest/1898/submission/233522554.

It was elegant as expected, but it made me realize am I missing this critical skill of sleek implementation that he has for annoying problems. Does any one know what I'm talking about or how to improve at this. Thanks!

Full text and comments »

  • Vote: I like it
  • +27
  • Vote: I do not like it

By Negationist, history, 7 weeks ago, In English

Problem: Array Game — https://mirror.codeforces.com/contest/1904/problem/C Idea of the code, consider all possible combinations of 2 elements to make diff, mn = min of, mn, diff, [first element greater than diff]-diff, [one element left of the first element greater than diff]-diff. Thanks so much.

My Code

Full text and comments »

  • Vote: I like it
  • 0
  • Vote: I do not like it

By Negationist, history, 7 weeks ago, In English

Is it just me or do editorials kind of suck? Often, the methods they present are overly complicated and/or not made with idea of improving the reader's intuition in mind. It's gotten to the point that I only look for broad ideas and never look for specific implementation. And I always leave them kind of annoyed.

Example Problem: https://mirror.codeforces.com/contest/2008/problem/G (sakurako's task) What I don't like: "Now, we can find where the mexk should be in linear time. Firstly, if it is before the first one, then the answer is k, otherwise, we can assign k=k−a1. Then let's look at the second element. If a1+k<a2, then answer should be a1+k and otherwise we can assign k=k−a2+a1−1. In other words, when we look if our k can be in range from ai to ai+1, we know that number of elements that were not in the array and less than ai equal to k+ai. Then, when we find such i, we can output the answer."

This is dumb and overcomplicated. What they should have said was something like this. "Assume the array is empty, then, mex = k-1. For every array element(0 to n-1) check if mex >= i*GCD. If so, it means the mex is influenced by this array element. Thus we should do mex++. Otherwise do nothing." I went to bed trying to understand the editorial and sleeping frustrated. It seems to me like the tutorial writer care more about showing off then actually developing useful intuition.

I understand making contests and tutorials is hard but still. Some editiorials just seem so disconnected. idk. Anyone else feel this way?

Full text and comments »

  • Vote: I like it
  • +5
  • Vote: I do not like it

By Negationist, history, 7 weeks ago, In English

Why does my rolling hash never work?

hash implementation

Full text and comments »

  • Vote: I like it
  • +3
  • Vote: I do not like it

By Negationist, history, 2 months ago, In English

I hate being the guy that spams questioning blogs but... On the problem, Did We Get Everything Covered?, I did the solution but in reverse kind of. Just look at my code and you'll see what I mean, but something is wrong. What?

Code

Edit: I failed test case 140 in test 2.

Full text and comments »

  • Vote: I like it
  • +1
  • Vote: I do not like it

By Negationist, history, 2 months ago, In English

Here is an AC submission:

AC

Here is an WA submission:

WA

The only difference is a custom sqrt function. This was my worse contest ever because of this. Wasted like 40 mins trying figure this out and needed like 1 more min to solve C. Someone please explain because this is so weird and frustrating.

Full text and comments »

  • Vote: I like it
  • +4
  • Vote: I do not like it

By Negationist, history, 2 months ago, In English

In the speedbreaker question, why do we need to do: c++ mn[i]=min(mn[i],mn[i-1]),mx[i]=max(mx[i],mx[i-1]);

Full Code

Also, I get why the first condition is necessary for there to be a solutions and I get why the second part of the code finds that good interval, but I'm having a little trouble piecing together the sufficiency of the two to guarantee the right answer. Perhaps this is also why I font understand why you have to do the operations on the mins and maxes too.

Full text and comments »

  • Vote: I like it
  • 0
  • Vote: I do not like it

By Negationist, history, 2 months ago, In English

In the speedbreaker question, why do we need to do: c++ mn[i]=min(mn[i],mn[i-1]),mx[i]=max(mx[i],mx[i-1]);

I (mostly) get everything besides that. Thanks in advance!

Full submission by Zqr123456 on Div 2 contest:

Also, I get why the first condition is necessary for there to be a solutions and I get why the second part of the code finds that good interval, but I'm having a little trouble piecing together the sufficiency of the two to guarantee the right answer. Perhaps this is also why I font understand why you have to do the operations on the mins and maxes too.

#include<bits/stdc++.h>
using namespace std;
int T,n,a[200005],mn[200005],mx[200005],l,r;
void solve(){
	cin>>n;
	for(int i=0;i<=n;i++)mn[i]=n+1,mx[i]=0;
	for(int i=1;i<=n;i++)cin>>a[i],mn[a[i]]=min(mn[a[i]],i),mx[a[i]]=max(mx[a[i]],i);
	for(int i=1;i<=n;i++){
		mn[i]=min(mn[i],mn[i-1]),mx[i]=max(mx[i],mx[i-1]);
		if(mx[i]-mn[i]>=i){cout<<"0\n";return;}
	}
	l=1,r=n;
	for(int i=1;i<=n;i++)l=max(l,i-a[i]+1),r=min(r,i+a[i]-1);
	cout<<r-l+1<<'\n';
}
signed main(){
	ios::sync_with_stdio(false);
	cin.tie(0),cout.tie(0);
	cin>>T;
	while(T--)solve();
	return 0;
}

Full text and comments »

  • Vote: I like it
  • +17
  • Vote: I do not like it

By Negationist, history, 2 months ago, In English

In the editorial, they use prefix sums to find the MEXs, but we can actually calculate the final MEX of the subsegments directly. This is based on the fact that if an element is in the array, there MUST be a subsegment that does NOT have it as the MEX. Thus, the final MEX(for all subsegments) must be just the MEX of the original array. With this knowledge we can simply find the first subsegment with that MEX as the MEX. From there, we look for one more subsegment with this as the MEX, if found, we are done. If not, we know it must be impossible. Please note this is my first real blog, let me know if I did something wrong.

Code: https://mirror.codeforces.com/contest/1935/submission/282863993

Full text and comments »

  • Vote: I like it
  • 0
  • Vote: I do not like it

By Negationist, history, 2 months ago, In English

On many problems, I think of the solution very quickly but often spend a long time fixing and debugging the code to do what I want. For https://mirror.codeforces.com/problemset/problem/1973/B, I thought of a sliding window technique to find all windows that satisfy the or condition which is O(n). Yet, it took me like an hour and multiple failed submissions to get an AC. Right now, it feels like I have the "brains"(ingenuity) but not the "brawn"(implementation skills) right now. Furthermore, when I'm spending more time debugging than constructing it feels like I'm somewhat wasting my time(also its not very fun lol). What should I do?

P.S: I know someone is going to comment on how long I have been doing cp. Yes, I have only being doing cp for 1.5 months, and yes I know my implementation will naturally get better over time. Still, I'm looking for any advice BESIDES that. Thank you.

Full text and comments »

  • Vote: I like it
  • +2
  • Vote: I do not like it