当前位置:网站首页>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
边栏推荐
- Ffmpeg download and installation
- Web: compiling big refactoring from 10 to 1
- Unity 之 UPR优化建议汇总
- MCU experiment record
- Metinfo function public function getcity() error: XXX function no permission load!!!
- Introduction to CpG control network
- IT自媒体高调炫富,被黑客组织盯上,铁定要吃牢饭了…
- OA and fansoft Bi cross system users, departments and posts synchronous summary
- GBase JDBC 连接数据库异常
- How to merge cells in a table by markdown
猜你喜欢

Interview required: how to design the seckill system?

实战|记一次攻防演练打点

IT自媒体高调炫富,被黑客组织盯上,铁定要吃牢饭了…

Completed project series Tutorials - smart campus management system

暗黑王者|ZEGO 低照度图像增强技术解析

Unity 之 UPR优化建议汇总
![[wechat applet] design and interactive implementation of auction product details page (including countdown and real-time update of bids)](/img/01/42de6280191b9c32a7f37d7727bd4f.png)
[wechat applet] design and interactive implementation of auction product details page (including countdown and real-time update of bids)

【微信小程序】拍卖商品详情页设计与交互实现(包含倒计时、实时更新出价)

01 create project warehouse

Unity3d learning note 9 - loading textures
随机推荐
LVGL 8.2 Tabview
【浅析STM32之GPIO寄存器(CRL/CRH)配置 】
Zhongchuang computing power won the recognition of "2022 technology-based small and medium-sized enterprises"
Novel capture practice
Completed project series Tutorials - smart campus management system
Information System Project Manager --- Chapter IX examination questions of project human resource management over the years
中创算力荣获「2022年科技型中小企业」认定
Gbase 8A about no suitable driver
@Summary of ResponseBody annotation
5年经验的大厂测试/开发程序员,怎样突破技术瓶颈?大厂通病......
ESWC 2018 | R-GCN:基于图卷积网络的关系数据建模
Ora-01460: conversion request cannot be implemented or unreasonable
Actual combat | record an attack and defense drill management
IT自媒体高调炫富,被黑客组织盯上,铁定要吃牢饭了…
Libenent and libev
ESWC 2018 | r-gcn: relational data modeling based on graph convolution network
深入掌握Service
Unity3d learning note 9 - loading textures
Idea2021 installation
[cloud picture theory] 248 illustrated public network domain name resolution: easy domain name access to websites / mailboxes