Having trouble in solving segment tree problem.

Revision en2, by NotHandsomeBoizz, 2024-01-12 16:23:39

Hi everyone!

I have just participated in an IT contest in my city recently. And there was a segment tree problem that for now, I cant think of the way to use the segment tree properly. Here's the problem:

Given an array a contains only two numbers: 1 and -1, all the elements index from 1 to n.

Input:

The first line contains two integer n and q (1 <= n,q <= 10^5), corresponding to the size of the array and number of operation. The next line contains array of integers a1, a2, a3, ..., an of length n (a[i] ∈ {1;-1}). The next q following lines contain the description of the operations. The description of each operation is as follows:

  • 1 i v: set the element with index i to v (1 <= i <= n, v ∈ {1;-1})
  • 2 l r k: this operation needs to find two number x, y (l >= x >= y >= r) such that the sum of all element from x to y equals to k.

Output

For each operation of the second type print the corresponding x, y. If no answer exists, print -1.

  • Example:

Tags segment tree, math, problem solving, binary search

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en7 English NotHandsomeBoizz 2025-05-29 17:50:54 0 (published)
en6 English NotHandsomeBoizz 2024-01-14 04:48:05 6 Tiny change: 'r x, y (l >= x >= y >= r) such ' -> 'r x, y (l <= x <= y <= r) such ' (saved to drafts)
en5 English NotHandsomeBoizz 2024-01-12 16:40:13 0 (published)
en4 English NotHandsomeBoizz 2024-01-12 16:39:20 20 Tiny change: 'ntegers a1, a2, a3, ' -> 'ntegers a1\n-, a2, a3, '
en3 English NotHandsomeBoizz 2024-01-12 16:37:26 391
en2 English NotHandsomeBoizz 2024-01-12 16:23:39 796 Tiny change: 'nt -1.\n\n\n`hello`\n' -> 'nt -1.\n\n* Example:\n'
en1 English NotHandsomeBoizz 2024-01-11 19:13:40 349 Initial revision (saved to drafts)