# Bzoj4377 [poi2015]kurs szybkiego czytania

## 区间求交集的转化

Posted by yjjr's blog on November 27, 2018

# 题目

## Sample Input

9 5 6 4 3
101


### Sample Output

3
HINT


# 分析

$x$为小串第一个数实际值，那么即可得到小串第$i$个数实际的值为$(x+(i-1)\times a)\mod p$

# code

#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<algorithm>
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define dep(i,a,b) for(int i=a;i>=b;i--)
#define ll long long
#define mem(x,num) memset(x,num,sizeof x)
#define reg(x) for(int i=last[x];i;i=e[i].next)
using namespace std;
ll f=1,x=0;char ch=getchar();
while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
return x*f;
}
const int maxn=1e6+6;
int n,a,b,p,m,cnt=0,ans,r;char w[maxn];
struct node{int x,y;}e[maxn<<2];
inline bool cmp(node a,node b){return a.x<b.x;}
void add(int x,int y,int z,int r){
if(x)e[++cnt]=(node){0,x};
if(y<z)e[++cnt]=(node){y,z};
if(r<n)e[++cnt]=(node){r,n};
}
int main(){
rep(i,0,m-1){
b=(b+a)%n;
}
b=n-a;
dep(i,n-1,n-m+1){
b=(b-a+n)%n;
e[++cnt]=(node){b,b+1};
}
e[++cnt]=(node){n,n+1};
sort(e+1,e+1+cnt,cmp);
rep(i,1,cnt){
if(e[i].x>r)ans+=e[i].x-r;
if(e[i].y>r)r=e[i].y;
}
cout<<ans<<endl;
return 0;
}