题意

两个1e5的数组a,b,定义\(S(t)=\left \lfloor \frac{t-b_i}{a_i} \right \rfloor\),有三个操作

1 x y:将\(a[x]\)变为\(y\)

2 x y:将\(b[x]\)变为\(y\)

3 x:求使得\(S(t)\geq k\)的最小\(k\)

其中\(a_i\leq 1000\),\(b_i,k\leq 1e9\)

思路

这题主要突破口在于\(a_i\leq 1000\)

我们先从下整除下手,

\(\left \lfloor \frac{t-b_i}{a_i} \right \rfloor=\left \lfloor \frac{k_1a_i+c_1-k_2a_i-c_2}{a_i} \right \rfloor=k_1-k_2+\left \lfloor \frac{c_1-c_2}{a_i} \right \rfloor\)

其中

\(c_1=t\bmod a_i\)

\(c_2=b_i \bmod a_i\)

\(k_1=t/ a_i\)

\(k_2=b_i/ a_i\)

\(\left \lfloor \frac{c_1-c_2}{a_i} \right \rfloor=\left\{\begin{matrix}
-1,c_1<c_2\\ 0,c_1\geq c_2
\end{matrix}\right.\)

那么

\(S(t)=ret+\sum_{i=1}^{1000}(\frac{t}{i}cnt[i]-f[i][t\bmod i+1])\)

其中

\(f[x][y]\)表示\(a_i=x\)时,\(y \leq c_2 \leq 1000\)的个数

\(cnt[x]\)表示\(a_i=x\)的个数,即\(f[x][0]\)

\(ret\)表示所有数\(k_2\)的和

这题就做完了。。

代码

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<string>
#include<stack>
#include<queue>
#include<deque>
#include<set>
#include<vector>
#include<map>
#include<functional> #define fst first
#define sc second
#define pb push_back
#define mem(a,b) memset(a,b,sizeof(a))
#define lson l,mid,root<<1
#define rson mid+1,r,root<<1|1
#define lc root<<1
#define rc root<<1|1
#define lowbit(x) ((x)&(-x)) using namespace std; typedef double db;
typedef long double ldb;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> PI;
typedef pair<ll,ll> PLL; const db eps = 1e-6;
const int mod = 998244353;
const int maxn = 2e6+100;
const int maxm = 2e6+100;
const int inf = 0x3f3f3f3f;
const db pi = acos(-1.0); int n,m;
ll a[maxn],b[maxn];
ll f[1111][1111];
ll ret;
ll S(ll t){
ll ans = 0;
for(int i = 1; i <= 1000; i++){
ans+=t/i*f[i][0]-f[i][t%i+1];
}
return ans-ret;
} int main() {
int T;
scanf("%d", &T);
while(T--){
scanf("%d %d", &n, &m);
for(int i = 1; i <= n; i++){
scanf("%lld",&a[i]);
}
for(int i = 1; i <= n; i++){
scanf("%lld", &b[i]);
}
mem(f, 0);
ret = 0;
for(int i = 1; i <= n; i++){
ret+=b[i]/a[i];
f[a[i]][b[i]%a[i]]++;
}
for(int i = 1; i <= 1000; i++){
for(int j = i-1; j >= 0; j--){
f[i][j]+=f[i][j+1];
}
}
while(m--){
int op,x;
ll y;
scanf("%d",&op);
if(op<=2){
scanf("%d %lld", &x ,&y);
if(op==1){
ret-=b[x]/a[x];
ret+=b[x]/y;
for(int i = b[x]%a[x]; i >= 0; i--)f[a[x]][i]--;
for(int i = b[x]%y; i >= 0; i--)f[y][i]++;
a[x]=y;
}
else if(op==2){
ret-=b[x]/a[x];
ret+=y/a[x];
for(int i = b[x]%a[x]; i >= 0; i--)f[a[x]][i]--;
for(int i = y%a[x]; i >= 0; i--)f[a[x]][i]++;
b[x]=y;
}
}
else{
ll ans = 0;
scanf("%lld", &y);
ll l = 0,r = 1e13;
while(l<=r){
ll mid = l+r>>1;
if(S(mid)>=y){
ans=mid;r=mid-1;
}
else l=mid+1;
}
printf("%lld\n",ans);
} } }
return 0;
}
/*
2
4 6
2 4 6 8
1 3 5 7
1 2 3
2 3 3
3 15
1 3 8
3 90
3 66
8 5
2 4 8 3 1 3 6 24
2 2 39 28 85 25 98 35
3 67
3 28
3 73
3 724
3 7775
*/

HDU 6274 Master of Sequence (暴力+下整除)的更多相关文章

  1. HDU 5273 Dylans loves sequence 暴力递推

    题目链接: hdu:http://acm.hdu.edu.cn/showproblem.php?pid=5273 bc:http://bestcoder.hdu.edu.cn/contests/con ...

  2. HDU 5063 Operation the Sequence(暴力)

    HDU 5063 Operation the Sequence 题目链接 把操作存下来.因为仅仅有50个操作,所以每次把操作逆回去执行一遍,就能求出在原来的数列中的位置.输出就可以 代码: #incl ...

  3. HDU - 1711 A - Number Sequence(kmp

    HDU - 1711 A - Number Sequence   Given two sequences of numbers : a[1], a[2], ...... , a[N], and b[1 ...

  4. HDU 5783 Divide the Sequence(数列划分)

    p.MsoNormal { margin: 0pt; margin-bottom: .0001pt; text-align: justify; font-family: Calibri; font-s ...

  5. 判断相同区间(lazy) 多校8 HDU 5828 Rikka with Sequence

    // 判断相同区间(lazy) 多校8 HDU 5828 Rikka with Sequence // 题意:三种操作,1增加值,2开根,3求和 // 思路:这题与HDU 4027 和HDU 5634 ...

  6. hdu 4893 Wow! Such Sequence!(线段树)

    题目链接:hdu 4983 Wow! Such Sequence! 题目大意:就是三种操作 1 k d, 改动k的为值添加d 2 l r, 查询l到r的区间和 3 l r. 间l到r区间上的所以数变成 ...

  7. 2017ccpc 杭州Master of Sequence

    Problem K. Master of SequenceTherearetwosequencesa1,a2,··· ,an, b1,b2,··· ,bn. LetS(t) =∑n i=1⌊t−bi ...

  8. HDU 2920 分块底数优化 暴力

    其实和昨天写的那道水题是一样的,注意爆LL $1<=n,k<=1e9$,$\sum\limits_{i=1}^{n}(k \mod i) = nk - \sum\limits_{i=1}^ ...

  9. Master of Sequence

    Master of Sequence 时间限制: 10 Sec  内存限制: 128 MB 题目描述 There are two sequences a1,a2,...,an , b1,b2,..., ...

随机推荐

  1. Java 多线程与并发(六):AQS

    我们前面几张提到过,JUC 这个包里面的工具类的底层就是使用 CAS 和 volatile 来保证线程安全的,整个 JUC 包里面的类都是基于它们构建的.今天我们介绍一个非常重要的同步器,这个类是 J ...

  2. 10.Python中print函数中中逗号和加号的区别

    先看看print中逗号和加号分别打印出来的效果.. 这里以Python3为例 1 print("hello" + "world") helloworld 1 p ...

  3. 【转】python及其工具包安装基本流程

    昨天晚上在家里的旧电脑上安装了<利用python进行数据分析>的部分环境,遇到若干问题,在此予以记录. 部分细节转:http://blog.csdn.net/huanbia/article ...

  4. MySQL故障演习

    MySQL故障演习 接上次的 MySQL定时备份 该次实验主要是练习在MySQL数据库发生误删等意外情况下,利用全量备份文件和增量备份文件恢复数据. 1. 实验环境 -- 创建数据库 create d ...

  5. 通过模拟Mybatis动态代理生成Mapper代理类,讲解Mybatis核心原理

    本文将通过模拟Mybatis动态代理生成Mapper代理类,讲解Mybatis原理 1.平常我们是如何使用Mapper的 先写一个简单的UserMapper,它包含一个全表查询的方法,代码如下 pub ...

  6. cogs 182. [USACO Jan07] 均衡队形 线段树

    182. [USACO Jan07] 均衡队形 ★★☆   输入文件:lineup.in   输出文件:lineup.out   简单对比时间限制:4 s   内存限制:128 MB 题目描述 农夫约 ...

  7. 使用Robot Framework框架远程操作UNIX系统

    bot Framework是一个强大的自动化测试框架,依靠社区力量编写的Test Library为它提供了非常强的扩展性.下面我将介绍的就是如何使用第三方提供的扩展测试库(Test Library)来 ...

  8. python接口自动化中,注册接口随机生成手机号码

    如大家所知在注册接口中,手机号参数需要的是未注册的手机号,而在测试用例中,你写入的手机号不一定是未注册的.所以这时需要对注册接口中传入的手机号做处理.下面我就分享一个课程里面学到的一个处理手机号的py ...

  9. 手把手写一个基于Spring Boot框架下的参数校验组件(JSR-303)

    前言 之前参与的新开放平台研发的过程中,由于不同的接口需要对不同的入参进行校验,这就涉及到通用参数的校验封装,如果不进行封装,那么写出来的校验代码将会风格不统一.校验工具类不一致.维护风险高等其它因素 ...

  10. xlwings excel(三)

    App相当于Excel程序,Book相当于工作簿.N个Excel程序则由apps表示,N个工作簿由books表示. 对工作簿的操作 #导入xlwings模块 import xlwings as xw ...