Master of Sequence
Master of Sequence
时间限制: 10 Sec 内存限制: 128 MB
题目描述
. 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)}
输入
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 一个使 ...
随机推荐
- 4396: [Usaco2015 dec]High Card Wins
Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 275 Solved: 175[Submit][Status][Discuss] Descriptio ...
- jquery 省市区联动插件
使用方式: <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF ...
- Table 分页处理
介绍两种table分页处理:PHP分页 和 js(jquery.table)分页. 一:jquery.table: 1:下载两个文件:table_jui.css 和 jquery.dataTables ...
- centos7.3网络配置
一.关闭NetworkManager 默认状态下最小化安装使用NetworkManager这个服务来控制联网的,但是这个配置在配置生产环境服务器时一般不会使用,而是使用系统自带的network服务,更 ...
- bootmem API总结
bootmem_init()函数执行完成后,linux启动初期的bootmem分配器就初始化完成了,可以调用bootmem提供的API分配内存. 这些API在include/linux/bootmem ...
- mysql--timestamp加减
利用timestamp()对timestamp类型进行秒加减操作: 1.加10秒: 2.减10秒:
- POJ 2771 Guardian of Decency (二分图最大点独立集)
Guardian of Decency Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 6133 Accepted: 25 ...
- 朴素贝叶斯python小样本实例
朴素贝叶斯优点:在数据较少的情况下仍然有效,可以处理多类别问题缺点:对于输入数据的准备方式较为敏感适用数据类型:标称型数据朴素贝叶斯决策理论的核心思想:选择具有最高概率的决策朴素贝叶斯的一般过程(1) ...
- Windows Server 2012 R2:细节信息汇总
Windows Server 2012 R2:细节信息汇总 2013年08月09日00:10 it168网站原创 作者:核子可乐编译 编辑:王晓东 我要评论(0) 标签: 操作系统 , Windows ...
- C++编程规范(101条准则)
记录学习,方便以后查看. 2014-12-28 看完这本书,但是我做到的又有多少呢?确实有一部分 0 不要拘泥于小节 1 在高警告级别干净利落的进行编译,不放过任何警告 2 使用自动构建系统 3 使 ...