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 一个使 ...
随机推荐
- 问题002:我们要使用的Java是哪个版本的?什么是JVM、JRE、JDK、IDE、API?
三个版本:1.java SE 标准版 2.java EE企业版 3.Java ME 小型版本 JVM (java virtual machine) java虚拟机 JRE(java runtime e ...
- 洛谷P1048采药
这道题一看就知道是01背包,我门用f[i]来表示时间剩余i时的最大的价值 一共只有两种选择取或者不取,可以得到方程式f[i]=max(f[i],f[i-a[i]]+v[i])(a[i]是表示时间,v[ ...
- ZJOI2019Round#1
考的这么差二试基本不用去了 不想说什么了.就把这几天听课乱记的东西丢上来吧 这里是二试乱听课笔记ZJOI2019Round#2 ZJOI Round#1 Day1 M.<具体数学>选讲 罗 ...
- mysql 报错 Operand should contain 1 column(s)
报错 Operand should contain 1 column(s) 原因 select 后面加了 () select (x,x,x)
- git 命令汇总
本地库处理 git init 初始化仓库 git clone [地址] 下载项目 git status 查看当前暂存等状态 git add 添加暂存 cat .git/config 查看git配置 l ...
- 六、MySQL 删除数据库
MySQL 删除数据库 使用普通用户登陆 MySQL 服务器,你可能需要特定的权限来创建或者删除 MySQL 数据库,所以我们这边使用 root 用户登录,root 用户拥有最高权限. 在删除数据库过 ...
- 【IDEA】热部署插件Jrebel破解安装
JRebel 介绍 IDEA上原生是不支持热部署的,一般更新了 Java 文件后要手动重启 Tomcat 服务器,才能生效,浪费不少生命啊.目前对于idea热部署最好的解决方案就是安装JRebel插件 ...
- 四 python并发编程之协程
一 引子 本节的主题是基于单线程来实现并发,即只用一个主线程(很明显可利用的cpu只有一个)情况下实现并发,为此我们需要先回顾下并发的本质:切换+保存状态 cpu正在运行一个任务,会在两种情况下切走去 ...
- Xenia and Bit Operations CodeForces - 339D
Xenia and Bit Operations CodeForces - 339D Xenia the beginner programmer has a sequence a, consistin ...
- Git add命令
git add -A和 git add . git add -u在功能上看似很相近,但还是存在一点差别 git add . :他会监控工作区的状态树,使用它会把工作时的所有变化提交到暂存区,包括文 ...