Professional Fence Decorator
Time limit2sMemory limit1024 MB
Given n colored slats, process range repaint queries and report whether two equal-length fence segments have the same colors.
- Level
Medium6 of 10
- Topics
- Segment tree, String matching
- Solved
- No attempts yet
Problem
Vasya is an apprentice at a well-known studio. He was recently assigned to help Vitezslav Smolokurov, a young fence decorator with great promise. The task is very important, and Vasya's future depends on how it goes.
Smolokurov's style is highly unusual, and his work is in great demand. The job has two stages. In the first stage, Vasya makes a blank: a long fence made of a row of colored vertical slats. In the second stage, Vitezslav starts working.
To give the fence a calmer, more harmonious look, he repeats the following operation several times: he picks a color and a segment, then repaints that segment in the chosen color. Smolokurov is creative and may change the design completely several times an hour, so he sometimes repaints the same slat more than once. He also does not want any pattern to repeat too often, so he sometimes checks whether one segment of the fence matches another.
Vasya does the repainting and the checking. The work is not easy, so Vasya asks for help, at least with the match checks.
Input
The first line contains one integer , the number of slats in the fence (). The second line contains integers separated by spaces, the colors of the slats.
The third line contains one integer , the number of comparison and repaint tasks (). Each of the next lines contains four integers , , , and .
For a repaint, . It means repainting all slats from to inclusive to color (). For a comparison, . It means comparing the fence pieces of length that start at positions and (, ).
All numbers in the input are positive and do not exceed .
Output
Output one line. For each comparison query, print <<+>> if the two pieces match and <<->> otherwise.