Master of Sequence
Master of Sequence
时间限制: 10 Sec 内存限制: 128 MB
题目描述

• 1 x y: change value ax to y.
• 2 x y: change value bx to y.
• 3 k: ask min{t|k≤S(t)}
输入
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.
输出
样例输入
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的更多相关文章
- 2017ccpc 杭州Master of Sequence
Problem K. Master of SequenceTherearetwosequencesa1,a2,··· ,an, b1,b2,··· ,bn. LetS(t) =∑n i=1⌊t−bi ...
- 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\ ...
- Oracle 11.2.0.4.0 Dataguard部署和日常维护(5)-Datauard 主备切换和故障转移篇
1. dataguard主备切换 1.1. 查看当前主备库是否具备切换条件 on slave select sequence#,first_time,next_time,archived,appl ...
- python---基础知识回顾(九)图形用户界面-------Tkinter
前戏:老牌python GUI程序(Tkinter) import tkinter.messagebox as messagebox class Application(Frame): def __i ...
- The 2017 China Collegiate Programming Contest, Hangzhou Site Solution
A: Super_palindrome 题面:给出一个字符串,求改变最少的字符个数使得这个串所有长度为奇数的子串都是回文串 思路:显然,这个字符串肯定要改成所有奇数位相同并且所有偶数位相同 那统计一下 ...
- 2017 CCPC杭州 题解
2017CCPC杭州题目PDF Problem A. Super-palindrome 题解: 给你一个字符串,每一步可以将一个字符替换为另一个字符,问你最少多少步可以使得,该字符串任意奇数子串为回文 ...
- spark HMM
Scala实现的: https://github.com/skrusche63/spark-intent/tree/master/src/main/scala/de/kp/scala/hmm http ...
- zookeeper适用场景:如何竞选Master及代码实现
问题导读:1.如何利用zookeeper保证集群Master可用性和唯一性?2.zookeeper竞选Master包含哪些过程?3.zookeeper竞选Master机制利用了zk哪些特性? 在zoo ...
- 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 一个使 ...
随机推荐
- 抽屉head部分,hover应用,鼠标放上变色
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- hibernate系列之二
首先先介绍一下持久化: 持久化:将程序数据在持久状态和瞬时状态间转换的机制:即将内存的数据永久存在关系型数据库中: 持久化类的编写规则: 持久化类需要提供无参构造方法: 持久化类的属性需要私有,对私有 ...
- 绘制文字:imagettftext()
<?php //1. 绘制图像资源(创建一个画布) $image = imagecreatetruecolor(500, 300); //2. 先分配一个绿色 $green = imagecol ...
- 绘制圆形 和 椭圆形:边圆形 imageellipse() 、 填充圆形imagefilledellipse()
<?php //1. 绘制图像资源(创建一个画布) $image = imagecreatetruecolor(500, 300); //2. 先分配一个绿色 $green = imagecol ...
- 饭卡 HDU - 2546(dp)
电子科大本部食堂的饭卡有一种很诡异的设计,即在购买之前判断余额.如果购买一个商品之前,卡上的剩余金额大于或等于5元,就一定可以购买成功(即使购买后卡上余额为负),否则无法购买(即使金额足够).所以大家 ...
- A1083 List Grades (25)(25 分)
A1083 List Grades (25)(25 分) Given a list of N student records with name, ID and grade. You are supp ...
- V4L2学习(四)VIVI分析
vivi 相对于后面要分析的 usb 摄像头驱动程序,它没有真正的硬件相关层的操作,也就是说抛开了复杂的 usb 层的相关知识,便于理解 V4L2 驱动框架,侧重于驱动和应用的交互. 前面我们提到,V ...
- Fiddler用AutoResponder实现app升级异步更新
先说一下我自己理解的异步更新:用app异步升级举例,app是否升级的检查是在启动app时访问服务器的,把app本地的最新版本号与服务器端的最新版本号做对比,假如不一致,则提示升级.但本次已经打开使用a ...
- D3DXCreateTexture
HRESULT D3DXCreateTexture( __in LPDIRECT3DDEVICE9 pDevice, __in UINT Width, __in UINT Height, __in U ...
- 2 Model层-模型成员
1 类的属性 objects:是Manager类型的对象,用于与数据库进行交互 当定义模型类时没有指定管理器,则Django会为模型类提供一个名为objects的管理器 支持明确指定模型类的管理器 c ...