MIRAJ12's blog

By MIRAJ12, history, 2 months ago, In English

For some time, I have been using a specific kind of data structure (I created it while solving a problem without any prior knowledge of the Disjoint Sparse Table). I am pretty sure it is basically a Disjoint Sparse Table, but implemented in a simpler way, so I thought of sharing it.

Prerequisites

The main idea comes from the sliding window technique. Suppose you have q queries where every query has a fixed length (r - l) = k. You can answer each query by combining information from two blocks of size k-1 use the suffix left block and the prefix right block. Then, you can compute the ans using those two values.

Here n = 12, k = 4, and one of the queries is: l = 6, r = 9

So, we create prefix and suffix blocks of size 3. Then, we can computed information from these two blocks to answer the query in O(1).

One example problem: CSES Sliding Window Or

One very important thing to notice here k-1 makes sure that all l, r are in adjacent blocks. So the block size is not the important part, the main point is that l and r have to belong to some adjacent blocks.

DSL like idea:

Build structure:

Create suffix and prefix blocks with sizes that are powers of 2, So, have to repeat log(n) times. The memory complexity is also O(2 * n log n), and the time complexity is the same.

For n = 12

Build code

Query structure:

For any query l, r, let x = r - l. l and r will always belong to adjacent blocks, where the block size is either the closest power of 2 to <=x or the next larger power of 2.

Example problem and code:

Static Range Sum Queries

Code

Count maxima on an interval

code

You might need to join the Codeforces group to access this problem

Full text and comments »

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

By MIRAJ12, history, 5 months ago, In English

For contests, I use the Codeforces m1 site mainly because it has a built-in dark mode, and sometimes the site responds faster than the main one. However, it has two really annoying problems:

  1. Any announcement notification is shown multiple times repeatedly. ( most annoying ) prove 1

  2. While submitting, if you click quickly multiple times, it submits the solution multiple times. prove 2

So I request MikeMirzayanov and Vladosiya to fix these issues (at list problem 1 ), or please introduce dark mode on the main site also I have seen the first problem on the main site long time ago, but on the m1 site it occurs much more frequently and keeps repeating again and again.

Full text and comments »

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

By MIRAJ12, history, 6 months ago, In English

Recently, I tried to solve the problem: Meteors

It is a well-known problem that is usually solved using Parallel Binary Search.

However, before learning about that technique, I attempted to solve it in my own way. Surprisingly, my solution somehow passed within the time limit, even though I expected it to get TLE based on my complexity estimation.

MY CODE

At first, I estimated my code’s complexity as: (n + m) * log(m) * log(q)^2

The part that confuses me is the binary search: inside it, I loop over a node vector of size roughly log(m). At the same time, the total size of all vectors could be around q * log(m), as far as I understand.

Does the segment tree structure somehow reduce the number of iterations or the effective number of values processed, or am I misunderstanding the actual complexity?

For context, the input function is implemented as an iterative segment tree. Each query stores a prefix sum over a range, and the crn_node function is used to collect all the relevant node indices along the path for a given position p.

To my understanding, I would have needed to remove at least one or more log factors from the complexity just to pass the time limits.

If there’s some good reason why it passed, then this kind of trick could be really useful for other problems as well. I’d love to understand it properly and learn how and why. Any insights or guidance would be greatly appreciated:)

update: [ I don’t really care whether people upvote or downvote, I just want to understand the reason. I’ll most probably delete the blog after I get the answer. If anyone know why it passed, please let me know. I’ve even asked several AIs about this, but none of them gave a convincing explanation. Most of the time they just hallucinated answers, and when I tried to argue with the reasoning, the explanation kept changing every time, which made it even more confused ]

Full text and comments »

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

By MIRAJ12, history, 11 months ago, In English

Hey everyone!

I’ve been doing Codeforces contests for a while and I love solving problems. Recently, I came up with two really nice problems that I think could be fun for everyone. I badly want to propose them so people can enjoy them too.

The problem is… I don’t have the option to propose a contest or problem yet. Does anyone know how I can get it activated? I’d be really grateful for any help or advice!

In my account:

Screenshot-2025-10-18-at-12-15-11-AM

Normally in other account:

Also I know about polygon.

Can’t wait for the day I can share my problems officially!

Full text and comments »

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