BZOJ 2054 crazy steamed bread and query set, bzoj2054 steamed bread

Source: Internet
Author: User

BZOJ 2054 crazy steamed bread and query set, bzoj2054 steamed bread

Given a sequence, a certain interval is repeatedly colored to find the color of each vertex.

M <= 1000 W, the line segment tree must be T

Because only the last Dyeing of each vertex is used, if a vertex has been stained, link the vertex to the right in the query set.

In this way, each vertex is stained only once, and the time complexity is O (n + m)

# Include <cstdio> # include <cstring> # include <iostream> # include <algorithm> # define M 1001001 using namespace std; int n, m, p, q; int a [M]; namespace Union_Find_Set {int fa [M]; int Find (int x) {if (! Fa [x] | fa [x] = x) return fa [x] = x; return fa [x] = Find (fa [x]);} int main () {using namespace Union_Find_Set; int I, j; cin> n> m> p> q; for (I = m; I --) {int x = (long) I * p + q) % n + 1; int y = (long) I * q + p) % n + 1; if (x> y) swap (x, y); for (j = Find (x); j <= y; j = Find (j )) a [j] = I, fa [j] = j + 1 ;}for (I = 1; I <= n; I ++) printf ("% d \ n", a [I]); return 0 ;}


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.