正解:数论

解题报告:

传送门$QwQ$

,,,这题还蛮妙的$QwQ$(,,,其实所有数论题对我来说都挺妙的$kk$然后我真的好呆昂我理解了好久$QAQ$

考虑先建$Q$个点,编号为$[0,Q)$,表示膜$Q$的余数.然后每个点$i$向$(i+P)\ mod Q$连边$QwQ$

显然这个是会成环的,事实上这个环的长度就$\frac{P\cdot Q}{gcd(P,Q)}$(不明白的可以去康那道很古早的考过好几遍了的跑跑步那题?那题不是证了个结论是说.在膜$Q$意义下每次走$P$,只会有$gcd(P,Q)$个环嘛,放到这题里就是有$gcd(P,Q)$个长度为$\frac{P\cdot Q}{gcd(P,Q)}$的环$QwQ$

然后枚举膜$P$的余数$a_i$,显然顺着边跑就等同于$a_i$不变,然后现在就变成,从$a_i$开始在环中跑$\lfloor\frac{T-1-a_i}{P}\rfloor$步,问有多少步是跑到的编号膜$Q\in B$的点上$QwQ$

所以考虑先预处理一个环中的属于$B$的数的数量,然后最后剩下的一点小尾巴特殊算下就欧克

$over$!

#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<vector>
using namespace std;
#define il inline
#define rg register
#define gc getchar()
#define int long long
#define ri register int
#define rb register bool
#define rc register char
#define rp(i,x,y) for(rg int i=x;i<=y;++i)
#define my(i,x,y) for(rg int i=x;i>=y;--i)
#define ub(i,x) upper_bound(G[i].begin(),G[i].end(),x)-G[i].begin() const int N=1e6+;
int P,Q,n,m,T,d,len,a[N],id[N],as;
bool b[N];
vector<int>G[N]; il int read()
{
rg char ch=gc;rg int x=;rg bool y=;
while(ch!='-' && (ch>'' || ch<''))ch=gc;
if(ch=='-')ch=gc,y=;
while(ch>='' && ch<='')x=(x<<)+(x<<)+(ch^''),ch=gc;
return y?x:-x;
}
int gcd(ri x,ri y){return y?gcd(y,x%y):x;} signed main()
{
P=read();Q=read();n=read();m=read();T=read()-;rp(i,,n)a[i]=read();rp(i,,m)b[read()]=;d=gcd(P,Q);len=P*Q/d;
rp(i,,d-){ri cnt=,nw=i;while(!cnt || nw!=i){id[nw]=++cnt;if(b[nw])G[i].push_back(cnt);nw=(nw+P)%Q;}}
rp(i,,n)
{
ri num=(T-a[i])/len,to=(T-num*len-a[i])/P;as+=num*(int)(G[a[i]%d].size());
ri l=id[a[i]],r=id[(to*P+a[i])%Q];
if(l<=r){as-=ub(a[i]%d,l-);as+=ub(a[i]%d,r);}
else{swap(l,r);as+=(int)(G[a[i]%d].size());++l;--r;if(l>r)continue;as+=ub(a[i]%d,l-);as-=ub(a[i]%d,r);}
}
printf("%lld\n",as);
return ;
}

最新文章

  1. Greenplum 的分布式框架结构
  2. 笔记 .Net反射机制
  3. Mysql备份系列(3)--innobackupex备份mysql大数据(全量+增量)操作记录
  4. Display Voxel Gird and PCA
  5. 父div高度和宽度的应用
  6. CodeForces 703B(容斥定理)
  7. Lecture Notes: Macros
  8. Android四大组件之服务-Service 原理和应用开发详解
  9. Java笔记(三十)&hellip;&hellip;正则表达式
  10. ShopEx访问提示Incompatible file format: The encoded file has format major ID 2, whereas the Loader expects 4
  11. Hive 3、Hive 的安装配置(本地derby模式)
  12. Tomcat7 + JRebel6.3.0 + IntelliJ idea 热部署配置过程+错误分析
  13. 常用的Python代码段
  14. 《Java并发编程实战》/童云兰译【PDF】下载
  15. Maven安装和使用
  16. linux 工具
  17. JavaScript自定义事件和触发(createEvent, dispatchEvent)
  18. matlab的conv2、imfilter、filter2
  19. jenkins2.0以后的版本提供自动部署和远程部署功能?
  20. Qt——结合qt和python

热门文章

  1. 9-1进程,进程池和socketserver
  2. bzoj 4386: [POI2015]Wycieczki
  3. 记一次sublime text3更新 注册码失效问题和永久解决~
  4. hdu 1532 Drainage Ditches(最大流模板题)
  5. SuperSocket 服务器管理器客户端
  6. Redis在Laravel项目中的应用实例详解
  7. 2019-1-16-git-subtree-pull-错误-Working-tree-has-modifications
  8. centos linux ip地址无法连接数据库,ssh登录服务器时必须使用22端口
  9. HDU 3397&quot;Sequence operation&quot;(线段树区间和并)
  10. 【a403】遍历树问题