Master of Sequence

时间限制: 10 Sec  内存限制: 128 MB

题目描述

There are two sequences a1,a2,...,an , b1,b2,...,bn . Let . There are m operations within three kinds as following:
• 1 x y: change value ax to y.
• 2 x y: change value bx to y.
• 3 k: ask min{t|k≤S(t)}

输入

The first line contains a integer T (1≤T≤5) representing the number of test cases.
For each test case, the first line contains two integers n (1≤n≤100000), m (1≤m≤10000).
The following line contains n integers representing the sequence a1,a2,...,an .
The following line contains n integers representing the sequence b1,b2,...,bn .
The following m lines, each line contains two or three integers representing an operation mentioned above.
It is guaranteed that, at any time, we have 1≤ai≤1000, 1≤bi,k≤109 . And the number of queries (type 3 operation) in each test case will not exceed 1000.

输出

For each query operation (type 3 operation), print the answer in one line.

样例输入

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

样例输出

17
87
65
72
58
74
310
2875 题目链接:http://icpc.upc.edu.cn/problem.php?cid=1723&pid=10

思路: (t-bi)/ai = [k1*ai+c1-(k2*ai+c2)]/ai = k1-k2 + (c1-c2)/ai,这样就可以分别维护k1的和,k2的和,再维护一下c2>c1的情况。
#include<bits/stdc++.h>
#define N 1005
using namespace std; long long c[N][N]={}; void updata(long long arr[],long long pos,long long value)
{
pos++;
for(long long i=pos;i<N;i+=i&(-i))arr[i]+=value;
} long long Sum(long long arr[],long long pos)
{
pos++;
long long ans=;
for(long long i=pos;i>;i-=i&(-i))ans+=arr[i];
return ans;
} long long sum_a[N]={};
long long cnt=; void init()
{
cnt=;
memset(sum_a,,sizeof(sum_a));
memset(c,,sizeof(c));
} long long a[N*],b[N*]; long long f(long long t)
{
long long ans=cnt;
for(long long i=;i<N;i++)
if(sum_a[i])
{
ans+=t/i*sum_a[i];
ans-=sum_a[i]-Sum(c[i],t%i);
}
return ans;
} int main()
{
long long t;
scanf("%lld",&t);
while(t--)
{
init();
long long n,m;
scanf("%lld %lld",&n,&m);
for(long long i=;i<=n;i++)scanf("%lld",&a[i]);
for(long long i=;i<=n;i++)scanf("%lld",&b[i]); for(long long i=;i<=n;i++)
{
sum_a[a[i]]++;
updata(c[a[i]],b[i]%a[i],);
cnt-=b[i]/a[i];
} while(m--)
{
long long type;
scanf("%lld",&type);
if(type==)
{
long long x,y;
scanf("%lld %lld",&x,&y);
sum_a[a[x]]--;
updata(c[a[x]],b[x]%a[x],-);
cnt+=b[x]/a[x]; sum_a[y]++;
updata(c[y],b[x]%y,);
cnt-=b[x]/y;
a[x]=y;
}
else
if(type==)
{
long long x,y;
scanf("%lld %lld",&x,&y);
updata(c[a[x]],b[x]%a[x],-);
cnt+=b[x]/a[x]; updata(c[a[x]],y%a[x],);
cnt-=y/a[x];
b[x]=y;
}
else
{
long long k;
scanf("%lld",&k);
long long l=,r=1e14;
long long ans=; while(l<=r)
{
long long mid=(l+r)/;
if(f(mid)>=k)
{
ans=mid;
r=mid-;
}
else
l=mid+;
}
printf("%lld\n",ans);
}
}
}
return ;
}

Master of Sequence的更多相关文章

  1. 2017ccpc 杭州Master of Sequence

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

  2. HDU 6274 Master of Sequence (暴力+下整除)

    题意 两个1e5的数组a,b,定义\(S(t)=\left \lfloor \frac{t-b_i}{a_i} \right \rfloor\),有三个操作 1 x y:将\(a[x]\)变为\(y\ ...

  3. Oracle 11.2.0.4.0 Dataguard部署和日常维护(5)-Datauard 主备切换和故障转移篇

    1. dataguard主备切换   1.1. 查看当前主备库是否具备切换条件 on slave select sequence#,first_time,next_time,archived,appl ...

  4. python---基础知识回顾(九)图形用户界面-------Tkinter

    前戏:老牌python GUI程序(Tkinter) import tkinter.messagebox as messagebox class Application(Frame): def __i ...

  5. The 2017 China Collegiate Programming Contest, Hangzhou Site Solution

    A: Super_palindrome 题面:给出一个字符串,求改变最少的字符个数使得这个串所有长度为奇数的子串都是回文串 思路:显然,这个字符串肯定要改成所有奇数位相同并且所有偶数位相同 那统计一下 ...

  6. 2017 CCPC杭州 题解

    2017CCPC杭州题目PDF Problem A. Super-palindrome 题解: 给你一个字符串,每一步可以将一个字符替换为另一个字符,问你最少多少步可以使得,该字符串任意奇数子串为回文 ...

  7. spark HMM

    Scala实现的: https://github.com/skrusche63/spark-intent/tree/master/src/main/scala/de/kp/scala/hmm http ...

  8. zookeeper适用场景:如何竞选Master及代码实现

    问题导读:1.如何利用zookeeper保证集群Master可用性和唯一性?2.zookeeper竞选Master包含哪些过程?3.zookeeper竞选Master机制利用了zk哪些特性? 在zoo ...

  9. A neural chatbot using sequence to sequence model with attentional decoder. This is a fully functional chatbot.

    原项目链接:https://github.com/chiphuyen/stanford-tensorflow-tutorials/tree/master/assignments/chatbot 一个使 ...

随机推荐

  1. Java,集合按自定义规则排序

    import java.util.ArrayList; import java.util.Collections; import java.util.Comparator; import java.u ...

  2. Mysql的一些纪要

    unsigned 整型的每一种都分无符号(unsigned)和有符号(signed)两种类型(float和double总是带符号的),在默认情况下声明的整型变量都是有符号的类型(char有点特别),如 ...

  3. js 发送验证码倒计时

    首先写一个按钮: <input type="button" id="btn" value="免费获取验证码" onclick=&quo ...

  4. Python学习笔记(七)加密加盐

    MD5加密和加盐 Python的MD5加密 Python的hashlib模块的MD5加密,是比较简单一种加密,md5函数必须传入编译后的结果,否则会报错: Traceback (most recent ...

  5. docker 学习(3)

    docker和宿主之间的数据共享以及docker间的数据共享仍然是让人头疼和操心的地方. 几个基本概念: docker: 一种容器管理技术,这里也指既有的开发工具链. container: 容器 im ...

  6. linux 查看CPU内存 网络 流量 磁盘 IO

    使用vmstat命令来察看系统资源情况 在命令行方式下,如何查看CPU.内存的使用情况,网络流量和磁盘I/O? Q: 在命令行方式下,如何查看CPU.内存的使用情况,网络流量和磁盘I/O? A: 在命 ...

  7. opencv中的仿射变换

    什么是仿射变换? 原理:1.一个任意的仿射变换都能表示为 乘以一个矩阵(线性变换) 接着再 加上一个向量(平移) 2.综上所述,我们能够用仿射变换来表示: 1)旋转(线性变换) 2)平移(向量加) 3 ...

  8. tomcat内存泄漏存入dump文件

    很多tomcat进程退出(或者进程假死),都是由于频繁的抛出OutOfMemeoryError导致的. 为了让tomcat退出前或者发生OutOfMemeoryError时自动dump堆栈信息,方便事 ...

  9. Asp.net页面生命周期详解任我行(2)-WebForm页面生命周期WEBFORM_ASPNET控件树的生成和作用

    摘要 页面类是如何结合后台文件类生成整个页面的HTML的代码和后台输出的代码输出到浏览器中呢?这就牵扯到Asp.net页面生命周期中一个很重要的概念控件树.服务器以反射的方式创建了页面类对象 内容 我 ...

  10. C#实现eval 进行四则运算(有码)

    在JavaScript中实现四则运算很简单,只需要调用eval函数就行了,但是不知道什么原因万能的.NET却没有封装这个函数~ 在这里为大家封装了一个C#版本的eval函数,具体的设计参考了<大 ...