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 ;}