当前位置:网站首页>[supplementary question] 2021 Niuke summer multi school training camp 1-3
[supplementary question] 2021 Niuke summer multi school training camp 1-3
2022-06-25 08:03:00 【Mfy's little brother 1】
NO.1
H.Hash Function
The question :
n Different numbers , Find the smallest number , Make this n The results of all the mathematical models are different
Ideas :
We found that a ≡ b m o d m a\equiv b\mod m a≡bmodm If and only if ∣ a − b ∣ ∣ a − b ∣ ∣a−b∣ Can be m m m to be divisible by .
In this way, the problem becomes to find a minimum m m m , Its satisfaction he is not any one ∣ a i − a j ∣ ∣ a_i − a_j ∣ ∣ai−aj∣ The divisor of .
We found that 1 ≤ ∣ a i − a j ∣ ≤ 5 e 5 1\leq|a_i-a_j|\leq5e5 1≤∣ai−aj∣≤5e5, Consider transforming to find
( x a 1 + x a 2 + . . . + x a n ) ∗ ( x − a 1 + x − a 2 + . . . + x − a n ) (x^{a_1} +x^{a_2}+...+x^{a_n})*(x^{-a_1} +x^{-a_2}+...+x^{-a_n}) (xa1+xa2+...+xan)∗(x−a1+x−a2+...+x−an) The expanded results , The existing coefficient is the result of subtracting any two terms of the original array .
Add negative numbers N Make it a positive number , Last FFT after , Judge when processing N+i Whether the coefficient of the term exists or not .
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
const int maxn=(1<<20)+5;
const double PI=acos(-1);
struct Complex
{
double x,y;
Complex operator+(const Complex &o) const{
return{
x+o.x,y+o.y};}
Complex operator-(const Complex &o) const{
return{
x-o.x,y-o.y};}
Complex operator*(const Complex &o) const{
return{
x*o.x-y*o.y,x*o.y+y*o.x};}
}A[maxn],B[maxn];
int rev[maxn];
int limit=1;
void FFT(Complex *a,int inv){
for(int i=0;i<limit;i++)
if(i<rev[i])swap(a[i],a[rev[i]]);
for(int mid=1;mid<limit;mid<<=1){
Complex Wn=Complex({
cos(PI/mid),inv*sin(PI/mid)});
for(int i=0;i<limit;i+=mid*2){
Complex w=Complex({
1,0});
for(int j=0;j<mid;j++,w=w*Wn){
Complex x=a[i+j],y=w*a[i+j+mid];
a[i+j]=x+y,a[i+j+mid]=x-y;
}
}
}
if(inv==-1) for(int i=0;i<limit;i++) A[i].x/=limit;
}
// --------FFT
int n;
const int Bs=500000;
int vis[maxn];
int main(){
cin>>n;
for(int i=1;i<=n;i++)
{
int b;
cin>>b;
A[b].x=1;//ax^b, Input b Is power ,1 Is the coefficient a
B[Bs-b].x=1;// use Bs-b A negative number
}
int bit=20;
limit=1<<20;//limit Must be greater than the maximum number of times
for(int i=1;i<limit;i++) rev[i]=rev[i>>1]>>1|(i&1)<<(bit-1);
FFT(A,1),FFT(B,1);
for(int i=0;i<limit;i++) A[i]=A[i]*B[i];
FFT(A,-1);
for(int i=0;i<=Bs;i++) vis[i]=int(A[i+Bs].x+0.5);// The coefficient , Because it's subtraction , Added Bs, Greater than Bs And meet the requirements , Determine whether there is a modified power
for(int i=n;;i++)
{
bool ok=1;
for(int j=i;j<=Bs;j+=i)
if(vis[j]) {
ok=0;break;}
if(ok) return cout<<i<<'\n',0;
}
return 0;
}
J.Journey among Railway Stations
Yes n A station , The opening hours of each station are [ u i , v i ] [ u_i , v_i ] [ui,vi] , The vehicle passes through the i From the first station to the i + 1 The time for each station is c o s t [ i ] cost[i] cost[i] , If you arrive at a station in advance, you can wait , If you reach the i There are more than stations in the world v i v_i vi You can't stop at this station , Yes q operations
0 l r : : Power on l Station departure stops at each station and finally arrives at r Station , Can output Yes, Otherwise output No
1 pos c : Will be the first pos The time from the station to the next station is modified to c
2 pos : Will be the first pos The opening hours of the station are changed to [ l , r ] [l,r] [l,r]
Ideas :
Segment tree interval merging ,
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define lson rt<<1,l,mid
#define rson rt<<1|1,mid+1,r
const int maxn=2e6+5;
struct node{
// Get to the next station at the earliest Arrive at the latest After spending time Can we get to
int u,v,cost,f;
}tr[maxn<<2];
int u[maxn],v[maxn],cost[maxn],t,n,m;
node merge(node a,node b){
node tmp;
tmp.f=a.f&b.f;
if(a.u>b.v)tmp.f=0;
tmp.cost=a.cost+b.cost;// to update
tmp.u=max(b.u,a.u+b.cost);
tmp.v=min(a.v,b.v-a.cost);
return tmp;
}
void build(int rt,int l,int r){
if(l==r){
tr[rt]={
u[l]+cost[l],v[l],cost[l],1};
return;
}
int mid=(l+r)>>1;
build(lson);
build(rson);
tr[rt]=merge(tr[rt<<1],tr[rt<<1|1]);
}
void update(int rt,int l,int r,int x){
if(l==r){
tr[rt]={
u[l]+cost[l],v[l],cost[l],1};
return;
}
int mid=(l+r)>>1;
if(x<=mid)update(lson,x);
else update(rson,x);
tr[rt]=merge(tr[rt<<1],tr[rt<<1|1]);
}
node query(int rt,int l,int r,int x,int y){
if(x<=l&&r<=y)return tr[rt];
int mid=(l+r)>>1;
if(y<=mid)return query(lson,x,y);
if(x>mid)return query(rson,x,y);
return merge(query(lson,x,y),query(rson,x,y));
}
int main(){
scanf("%d",&t);
while(t--){
scanf("%d",&n);
for(int i=1;i<=n;i++)
scanf("%d",&u[i]);
for(int i=1;i<=n;i++)
scanf("%d",&v[i]);
for(int i=1;i<n;i++)
scanf("%d",&cost[i]);
build(1,1,n);
scanf("%d",&m);
while(m--){
int op,l,r,q;
scanf("%d%d%d",&op,&l,&r);
if(op==0){
if(query(1,1,n,l,r).f)printf("Yes\n");
else printf("No\n");
}
else if(op==1){
cost[l]=r;
update(1,1,n,l);
}
else if(op==2){
scanf("%d",&q);
u[l]=r,v[l]=q;
update(1,1,n,l);
}
}
}
}
NO2.
L.
#include <bits/stdc++.h>
using namespace std;
const int maxn=2e5+10;
int n,m,q;
vector<int>mp[maxn];
vector<vector<pair<int,int>>>vx(maxn);
int main(){
scanf("%d%d%d",&n,&m,&q);
for(int i=1,x,y;i<=m;i++){
scanf("%d%d",&x,&y);
mp[x].push_back(y);
mp[y].push_back(x);
}
for(int i=1,x,y;i<=q;i++){
scanf("%d%d",&x,&y);
vx[x].push_back({
y,i});
}
for(int i=1;i<=n;i++){
for(int j=1;j<vx[i].size();j++){
vx[i][j].first+=vx[i][j-1].first;
}
}
int tmp=400;
for(int i=1;i<=n;i++){
int ans=0;
if(mp[i].size()<=tmp){
for(int j=0;j<vx[i].size();j++){
int t=q;
int x=vx[i][j].first,y=vx[i][j].second;
if(j!=vx[i].size()-1)t=vx[i][j+1].second;
for(auto d:mp[i]){
auto it=lower_bound(vx[d].begin(),vx[d].end(),(pair<int ,int>){
x,0});
if(it!=vx[d].end()){
t=min(t,(*it).second);
}
}
ans+=max(0,t-y);
}
}
else{
vector<int>tor(2e4,2e5+1);
for(auto j:mp[i]){
for(auto d:vx[j]){
tor[d.first]=min(tor[d.first],d.second);
}
}
for(int j=9999;j;j--)tor[j]=min(tor[j],tor[j+1]);
for(int j=0;j<vx[i].size();j++){
int x=vx[i][j].first,y=vx[i][j].second,t=q;
if(j!=vx[i].size()-1)t=vx[i][j+1].second;
t=min(t,tor[x]);
ans+=max(0,t-y);
}
}
printf("%d\n",ans);
}
}
NO.3
B.
Give a n ∗ m Matrix , It's all white at first , Can spend c o s t [ i ] [ j ] cost[i][j] cost[i][j] Put the grid ( i , j ) (i,j) (i,j) Blacken , You can also select two lines by magic x 1 , x 2 x1,x2 x1,x2 And two columns y 1 , y 2 y1,y2 y1,y2, If three of the four points in the mark are black , Then the fourth point can be dyed black directly
Ideas :
Analyze the options n+m-1 Just a little bit , Of course, it's not optional , Think of rows and columns as points , Point as edge , Make a new picture , Just find the smallest spanning tree
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=1e5+5;
ll n,m,a,b,c,d,p,ans,fa[maxn];
vector<pair<int,int>>mp[maxn];
int find(int x){
return fa[x]==x?x:fa[x]=find(fa[x]);
}
int main(){
scanf("%lld%lld%lld%lld%lld%lld%lld",&n,&m,&a,&b,&c,&d,&p);
for(int i=1;i<=n;i++){
for(int j=1;j<=m;j++){
a=(a*a*b+a*c+d)%p;
mp[a].push_back({
i,j+n});
}
}
for(int i=1;i<=n+m;i++)fa[i]=i;
for(int i=0;i<p;i++){
for(auto j:mp[i]){
int x=j.first,y=j.second;
int fx=find(x),fy=find(y);
if(fx!=fy){
ans+=i;
fa[fx]=fy;
}
}
}
printf("%lld\n",ans);
}
边栏推荐
- Electronics: Lesson 012 - Experiment 13: barbecue LED
- How to use ad wiring for PCB design?
- Knowledge sharing 𞓜 conventional laminated structure of six layer PCB
- Machine learning notes linear regression of time series
- 使用报文和波形记录分析仪RoyalScope的帧统计功能排查CAN总线偶发性故障
- How to select lead-free and lead-free tin spraying for PCB? 2021-11-16
- Dietary intervention reduces cancer treatment-related symptoms and toxicity
- ffmpeg+SDL2实现音频播放
- Electronics: Lesson 010 - Experiment 9: time and capacitors
- Analysis of kinsing dual platform mining family virus
猜你喜欢

【论文学习】《VQMIVC》

FM signal, modulated signal and carrier

Electronics: Lesson 012 - Experiment 13: barbecue LED

电子学:第010课——实验 9:时间与电容器

Invalid Navicat scheduled task

allgero报错:Program has encountered a problem and must exit. The design will be saved as a .SAV file

Technology blog | how to communicate using SSE

静态网页服务器
![洛谷P1073 [NOIP2009 提高组] 最优贸易(分层图+最短路)](/img/cb/046fe4b47898fd6db86edc8a267c34.png)
洛谷P1073 [NOIP2009 提高组] 最优贸易(分层图+最短路)

电子学:第012课——实验 13:烧烤 LED
随机推荐
50. pow (x, n) - fast power
Use the frame statistics function of the message and waveform recording analyzer royalscope to troubleshoot the accidental faults of the CAN bus
新版USBCAN卡CAN分析仪的CAN&CANFD综合测试分析软件LKMaster主要功能介绍
洛谷P2486 [SDOI2011]染色(树链+线段树 + 树上区间合并 )
Buckle 78: subset
MySQL simple permission management
Basic use of ActiveMQ in Message Oriented Middleware
Apache CouchDB 代码执行漏洞(CVE-2022-24706 )批量POC
剑指offer刷题(中等等级)
2265. number of nodes with statistical value equal to the average value of subtree
Introduction to the main functions of the can & canfd comprehensive test and analysis software lkmaster of the new usbcan card can analyzer
【红旗杯?】补题
协议和服务的区别?
电子学:第010课——实验 8:继电振荡器
Is it safe to open an account through the haircut account opening link now?
【补题】2021牛客暑期多校训练营1-3
洛谷P3313 [SDOI2014]旅行(树链+边权转点权)
电子学:第008课——实验 6:非常简单的开关
27. remove elements
Tips on how to design soft and hard composite boards ~ 22021/11/22