#include"bits/stdc++.h"
#define db double
#define ll long long
#define vec vector<ll>
#define Mt vector<vec>
#define ci(x) scanf("%d",&x)
#define cd(x) scanf("%lf",&x)
#define cl(x) scanf("%lld",&x)
#define pi(x) printf("%d\n",x)
#define pd(x) printf("%f\n",x)
#define pl(x) printf("%lld\n",x)
using namespace std;
const int N = 1e6 + ;
int a[N],b[N],s[][],n; //s[x][y]表示对于所有a[i]==x时的b[i]%a[i]余数大于等于y的数目
ll ret;
bool check(ll x,ll k)
{
ll ans=ret*-;
for(int i=; i<=; i++)
{
ans+=x/i*s[i][]; //s[i][0]为a数组中等于i的数的个数
ans-=s[i][x%i+]; //减掉所有 c1<c2 的情况
}
return ans>=k;
}
ll cal(ll x)
{
ll l=,r=1e13,mid;
ll res=l;
while(l<=r)
{
mid=(l+r)>>;
if(check(mid,x)) res=mid,r=mid-;
else l=mid+;
}
return res;
}
int main()
{
int TA,T,x,y,z;
scanf("%d",&TA);
while(TA--)
{
scanf("%d%d",&n,&T);
ret=;
memset(s,, sizeof(s));
for(int i=; i<=n; i++) scanf("%d",&a[i]);
for(int i=; i<=n; i++) scanf("%d",&b[i]),ret+=(b[i]/a[i]),s[a[i]][b[i]%a[i]]++;
for(int i=; i<=; i++)
for(int j=i-; j>=; j--)
s[i][j]+=s[i][j+];
while(T--)
{
scanf("%d%d",&z,&x);
if(z==)
{
scanf("%d",&y);
for(int i=b[x]%a[x]; i>=; i--) s[a[x]][i]--;
for(int i=b[x]%y; i>=; i--) s[y][i]++;
ret-=(b[x]/a[x]);
ret+=(b[x]/y);
a[x]=y;
}
else if(z==)
{
scanf("%d",&y);
for(int i=b[x]%a[x]; i>=; i--) s[a[x]][i]--;
for(int i=y%a[x]; i>=; i--) s[a[x]][i]++;
ret-=(b[x]/a[x]);
ret+=(y/a[x]);
b[x]=y;
}
else
{
printf("%lld\n",cal(1ll*x));
}
}
}
}

最新文章

  1. vim 学习积累(一)
  2. 【高级功能】使用 Ajax(续)
  3. 【网络资料】Astar算法详解
  4. BZOJ3759: Hungergame 博弈论+线性基
  5. 使用visualVM 1.3.8(visualvm_138-ml.zip) 监控远程Tomcat运行情况
  6. HTML5地理位置概述和地理位置对象的详解
  7. [转]Ubuntu 12.04开机自动挂载Windows分区
  8. JS input文本框禁用右键和复制粘贴功能的代码
  9. elecworks中“插入点”的意思
  10. C# 导出Excel Aspose.Cells
  11. Effective C++ 10
  12. mybatis基础学习1---(配置文件和sql语句)
  13. 真正的轻量级WebService框架——使用JAX-WS(JWS)发布WebService(转载)
  14. tensorflow (七) k-means
  15. 深入理解 RPC
  16. 使用ueditor的时候,style样式传递到后台时被过滤没了
  17. [Math] Unconstrained &amp; Constrained Optimization
  18. 【转】以太网最大帧和最小帧、MTU
  19. 2017-2018-2 20155233『网络对抗技术』Exp6:信息收集与漏洞扫描
  20. 第12月第2天 uiscrollview _adjustContentOffsetIfNecessary 圆角

热门文章

  1. Hibernate课程 初探一对多映射5-2 Eclipse添加数据库连接
  2. 解决 Maven 项目中找不到 jdk 的 tools.jar 文件的办法(多数情况下适用)
  3. DOMNodeInserted,DOMNodeRemoved 和监听内容变化插件
  4. Sharepoint 2013企业内容管理学习笔记终章
  5. 【起航计划 026】2015 起航计划 Android APIDemo的魔鬼步伐 25 App-&gt;Notification-&gt;Status Bar 状态栏显示自定义的通知布局,省却声音、震动
  6. [译文]PHP千年虫(y2k compliance)
  7. 1.06 在WHERE子句中引用取别名的列
  8. python_1_变量的使用
  9. redis list类型
  10. 通过redis实现的一个抢红包流程,仅做模拟【上】