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 一个使 ...
随机推荐
- c++ 中十进制 八进制 十六进制 二进制转换 最简方法
#include<iostream> using namespace std; int main() { int i; cin>>dec>>i; //cin> ...
- RabbitMQ-消费者"未处理完的消息"丢失
一个关于客户端(消费者)开启自动应答,重启后"未处理消息丢失"的小坑.(主要是对RabbitMQ理解不够) 首先,申明一下: 本文所谓的 "丢失消息" 不是指服 ...
- Smallest Common Multiple-freecodecamp算法题目
Smallest Common Multiple 1.要求 找出能被两个给定参数和它们之间的连续数字整除的最小公倍数. 2.思路 设定一个twoMultiple(a,b)函数,求出输入两个参数的最小公 ...
- jrtplib移植
jrtplib版本:3.11.1 jthread版本:1.3.3 libsrtp版本:1.6.0 jrtplib库有两种编译方式: 1. 使能jthread编译,此方式可使jrtplib自动在后台轮询 ...
- 模态框获取内容jQuery
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- MySQL - 表中某个状态字段的状态表示区分最好用数字,如status - [9999:失败,1111:成功]
表中某个状态字段的状态表示区分最好用数字,如status - [9999:失败,1111:成功]
- JZOJ 3463. 【NOIP2013模拟联考5】军训
3463. [NOIP2013模拟联考5]军训(training) (Standard IO) Time Limits: 2000 ms Memory Limits: 262144 KB Deta ...
- python 正则表达式与JSON字符串
目录 正则表达式 概括单字符集 匹配单字符 匹配字符集 普通字符与元字符 元字符和普通的字符的混用 数量词{整数|*|+|?} 匹配指规则的字母 贪婪模式 匹配指定长度的字符串 非贪婪模式 匹配指定长 ...
- SQLite3 of python
SQLite3 of python 一.SQLite3 数据库 SQLite3 可使用 sqlite3 模块与 Python 进行集成,一般 python 2.5 以上版本默认自带了sqlite3模块 ...
- 动态规划:HDU2844-Coins(多重背包的二进制优化)
Coins Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Subm ...