当前位置:网站首页>Luogu p2391 snow covered problem solution
Luogu p2391 snow covered problem solution
2022-07-25 04:50:00 【q779】
Luogu P2391 snow gleams white Answer key
Topic link :P2391 snow gleams white
The question :
Now there is n n n Snowflakes in a row . pty The snowflakes should be m m m Secondary staining operation , The first i i i Secondary dyeing operation , The first ( ( i × p + q ) m o d n ) + 1 ((i\times p+q)\bmod n)+1 ((i×p+q)modn)+1 A snowflake and ( ( i × q + p ) m o d n ) + 1 ((i\times q+p)\bmod n)+1 ((i×q+p)modn)+1 Snowflakes between snowflakes ( Include endpoints ) Dye into color i i i. among p , q p,q p,q Are given two positive integers . He wants to know in the end n n n What color is a snowflake dyed . Not dyed output 0 0 0.
1 ≤ n ≤ 1 0 6 , 1 ≤ m ≤ 1 0 7 1\leq n\leq 10^6,~1\leq m\leq 10^7 1≤n≤106, 1≤m≤107.
Guarantee 1 ≤ m × p + q , m × q + p ≤ 2 × 1 0 9 1\leq m\times p+q,m\times q+p\leq 2\times 10^9 1≤m×p+q,m×q+p≤2×109.
One sentence question : Linear interval smoothing ( The interval is assigned the same value ), Global query .
We have a mock race t3, It's also something I've been thinking about for months, and the result is the original question , If you don't write a question, you'll lose a lot
Consider modifying in reverse order , Because the value of a position must be determined by the number it was last modified
Violent leveling ? For the flattened point , No more pushing , So we have to skip it
This requires maintaining the node on the right side of each point that has not been pushed flat
You can consider linked list or parallel query set maintenance , Use and search set here
Time complexity O ( n ) O(n) O(n)
Code :
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iomanip>
#include <random>
using namespace std;
// #define int long long
// #define INF 0x3f3f3f3f3f3f3f3f
namespace FastIO
{
#define gc() readchar()
#define pc(a) putchar(a)
#define SIZ (int)(1e6+15)
char buf1[SIZ],*p1,*p2;
char readchar()
{
if(p1==p2)p1=buf1,p2=buf1+fread(buf1,1,SIZ,stdin);
return p1==p2?EOF:*p1++;
}
template<typename T>void read(T &k)
{
char ch=gc();T x=0,f=1;
while(!isdigit(ch)){
if(ch=='-')f=-1;ch=gc();}
while(isdigit(ch)){
x=(x<<1)+(x<<3)+(ch^48);ch=gc();}
k=x*f;
}
template<typename T>void write(T k)
{
if(k<0){
k=-k;pc('-');}
static T stk[66];T top=0;
do{
stk[top++]=k%10,k/=10;}while(k);
while(top){
pc(stk[--top]+'0');}
}
}using namespace FastIO;
#define N (int)(1e6+25)
int n,m,p,q,val[N],f[N];
void init(int n){
for(int i=1; i<=n; i++) f[i]=i;}
int find(int x){
return f[x]==x?x:f[x]=find(f[x]);}
signed main()
{
// ios::sync_with_stdio(0);
// cin.tie(0);cout.tie(0);
// freopen("check.in","r",stdin);
// freopen("check.out","w",stdout);
read(n);init(n+5);
read(m);read(p);read(q);
for(int i=m; i>=1; i--)
{
int l=(1ll*i*p+q)%n+1;
int r=(1ll*i*q+p)%n+1;
if(l>r)swap(l,r);
for(int j=l; j<=r;)
{
int k=find(j); if(k>r)break;
val[k]=i; f[k]=find(k+1); j=f[k];
}
}
for(int i=1; i<=n; i++) write(val[i]),pc('\n');
return 0;
}
Isn't that amazing , I thought about difference before 、 Monotonic stack 、 Line segments cover 、 Two dimensional convex hull (? Wait for a lot of things
边栏推荐
- 读书的思考
- Openworm project compilation
- Introduction to CpG control network
- ESWC 2018 | r-gcn: relational data modeling based on graph convolution network
- What is behind the development of science and technology now is the advent of the era of the meta universe
- Thinking of reading
- If you don't know these 20 classic redis interview questions, don't go to the interview!
- 实战|记一次攻防演练打点
- LVGL 8.2 Tabview
- GBase 8a 关于No Suitable Driver 问题
猜你喜欢
随机推荐
Getting started with scratch
[literature notes] pointmlp
Opencv4.5.x+cuda11.0.x source code compilation and yolov5 acceleration tutorial!
[wechat applet] design and interactive implementation of auction product details page (including countdown and real-time update of bids)
PyG搭建GCN实现链接预测
Interview required: how to design the seckill system?
5年经验的大厂测试/开发程序员,怎样突破技术瓶颈?大厂通病......
Anaconda installs jupyter
Idea2021 installation
Libenent and libev
Today is important
1. If function of Excel
Tiny-emitter.js: a small event subscription and Publishing Library
Ffmpeg download and installation
[ CTF 学习 ] CTF 中的隐写集合 —— 图片隐写术
How to ensure data consistency between MySQL and redis?
推荐系统-协同过滤在Spark中的实现
The strongest JVM in the whole network is coming!
2、 Mysql database foundation
QT download installation tutorial


![[literature notes] pointmlp](/img/8f/654dc6e2f4770b7f12aab49098d3d7.png)






