^m
路漫漫

题意:懒得写了有空再补上

链接:http://www.lydsy.com/JudgeOnline/problem.php?id=2054

离线从后往前做,并查集维护下一个没染色的就可以啦~

 1 #include<bits/stdc++.h>
 2 
 3 using namespace std;
 4 
 5 const int MAXN = 1010000;
 6 long long n, m, p, q;
 7 int fa[MAXN], color[MAXN];
 8 
 9 template <typename tn> void read (tn & a) {
10     tn x = 0, f = 1; char c = getchar();
11     while (c < '0' || c > '9') { if (c == '-') f = -1; c = getchar(); }
12     while (c >= '0' && c <= '9') { x = x * 10 + c - '0'; c = getchar(); }
13     a = f == 1 ? x : -x;
14 }
15 
16 int find (int x) { return (fa[x] == x || fa[x] == 0) ? x : fa[x] = find(fa[x]); }
17 
18 int main() {
19     read(n);
20     read(m);
21     read(p);
22     read(q);
23     for (int i = 1; i <= n; ++i) fa[i] = i;
24     for (long long i = m; i > 0; --i) {
25         long long x = (i * p + q) % n + 1, y = (i * q + p) % n + 1;
26         if (x > y) { int t = x; x = y; y = t; }
27         for (int j = find(x); j <= y; j = find(j)) color[j] = i, ++fa[j];
28     }
29     for (int i = 1; i <= n; ++i) printf("%d\n", color[i]);
30     return 0;
31 }
View Code

 

posted on 2018-03-24 19:31  ^m  阅读(115)  评论(0编辑  收藏  举报