hdu多校(二) 1004 1007 1010
Game
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 0 Accepted Submission(s): 0
The game is played on a set of positive integers from 1 to n.
In one step, the player can choose a positive integer from the set, and erase all of its divisors from the set. If a divisor doesn't exist it will be ignored.
Alice and Bob choose in turn, the one who cannot choose (current set is empty) loses.
Alice goes first, she wanna know whether she can win. Please judge by outputing 'Yes' or 'No'.
For each test case, a line containing an integer n. (1≤n≤500)
#include<bits/stdc++.h>
using namespace std;
int main(){
int n;
while(cin>>n){
puts("Yes");
}
}
Naive Operations
Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 502768/502768 K (Java/Others)
Total Submission(s): 0 Accepted Submission(s): 0
b is a static permutation of 1 to n. Initially a is filled with zeroes.
There are two kind of operations:
1. add l r: add one for al,al+1...ar
2. query l r: query ∑ri=l⌊ai/bi⌋
For each test case, in the first line, two integers n,q, representing the length of a,b and the number of queries.
In the second line, n integers separated by spaces, representing permutation b.
In the following q lines, each line is either in the form 'add l r' or 'query l r', representing an operation.
1≤n,q≤100000, 1≤l≤r≤n, there're no more than 5 test cases.
1 5 2 4 3
add 1 4
query 1 4
add 2 5
query 2 5
add 3 5
query 1 5
add 2 4
query 1 4
add 2 5
query 2 5
add 2 2
query 1 5
1
2
4
4
6
#include<bits/stdc++.h>
using namespace std;
#define LL long long
const int MAXN=;
int b[MAXN],n,m,l,r;
char s[];
class ST{
public:
#define lc (id<<1)
#define rc (id<<1|1)
#define mid ((L+R)>>1) int minb[MAXN<<],sum[MAXN<<],laz[MAXN<<]; void pushup(int id){
sum[id]=sum[lc]+sum[rc];
minb[id]=min(minb[lc],minb[rc]);
}
void pushdown(int id,int L,int R){
if(laz[id]){
laz[lc]+=laz[id],minb[lc]-=laz[id];
laz[rc]+=laz[id],minb[rc]-=laz[id];
laz[id]=;
}
}
void build(int id,int L,int R){
sum[id]=laz[id]=;
if(L==R){
scanf("%d",b+L);
minb[id]=b[L];
return;
}
build(lc,L,mid);
build(rc,mid+,R);
pushup(id);
}
void add(int id,int L,int R,int l,int r){ if(L>=l&&R<=r){
laz[id]++;
minb[id]--;
return ;
}
pushdown(id,L,R);
if(l<=mid) add(lc,L,mid,l,r);
if(r>mid) add(rc,mid+,R,l,r);
pushup(id);
}
int query(int id,int L,int R,int l,int r){
if(minb[id]>&&L>=l&&R<=r){
return sum[id];
}
if(L==R){
if(minb[id]<=){
int d=(-minb[id]+b[L])/b[L];
sum[id]+=d;
minb[id]=b[L]-(-minb[id]/*+b[L]-d*b[L]*/)%b[L];
}
return sum[id];
}
else{
pushdown(id,L,R);
int s=;
if(l<=mid) s+=query(lc,L,mid,l,r);
if(r>mid) s+=query(rc,mid+,R,l,r);
pushup(id);
return s;
}
}
}a;
int main(){
while(scanf("%d%d",&n,&m)!=EOF){
a.build(,,n);
while(m--){
scanf("%s %d%d",s,&l,&r);
if(s[]=='a'){
a.add(,,n,l,r);
}
else{
printf("%d\n",a.query(,,n,l,r));
}
}
}
return ;
}
Swaps and Inversions
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 0 Accepted Submission(s): 0
Tonyfang think this sequence is messy, so he will count the number of inversions in this sequence. Because he is angry, you will have to pay x yuan for every inversion in the sequence.
You don't want to pay too much, so you can try to play some tricks before he sees this sequence. You can pay y yuan to swap any two adjacent elements.
What is the minimum amount of money you need to spend?
The definition of inversion in this problem is pair (i,j) which 1≤i<j≤n and ai>aj.
For each test, in the first line, three integers, n,x,y, n represents the length of the sequence.
In the second line, n integers separated by spaces, representing the orginal sequence a.
1≤n,x,y≤100000, numbers in the sequence are in [−109,109]. There're 10 test cases.
1 2 3
3 1 666
3 2 1
3
#include<bits/stdc++.h>
using namespace std;
#define LL long long
int a[],b[];
LL C[],n;
map<int,int>M;
set<int>S;
set<int>::iterator it;
int lowbit(int x){
return x&-x;
}
int sum(int x){
LL ret=;
while(x>){
ret+=C[x];
x-=lowbit(x);
}
return ret;
}
void add(int x,int d){
while(x<=n){
C[x]+=d;
x+=lowbit(x);
}
}
int main(){
int x,y,i,j,k;
while(cin>>n>>x>>y){
memset(C,,sizeof(C));
M.clear();
S.clear();
LL ans=;
for(i=;i<=n;++i){
scanf("%d",a+i);
b[i]=a[i];
}
int tot=;
sort(b+,b++n);
for(i=;i<=n;++i){
if(M[b[i]]) continue;
M[b[i]]=++tot;
} for(i=n;i>=;--i){
ans+=sum(M[a[i]]-);
add(M[a[i]],);
}
cout<<ans*min(x,y)<<endl;
}
return ;
}
hdu多校(二) 1004 1007 1010的更多相关文章
- HDU 多校对抗赛第二场 1010 Swaps and Inversions
Swaps and Inversions Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Oth ...
- hdu多校第八场 1010(hdu6666) Quailty and CCPC 排序/签到
题意: CCPC前10%能得金牌,给定队伍解题数和罚时,问你有没有一个队伍如果向上取整就金了,四舍五入就银了. 题解: 排序后按题意求解即可. #include<iostream> #in ...
- HDU 4699 Editor (2013多校10,1004题)
Editor Time Limit: 3000/2000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)Total Su ...
- HDU 4679 Terrorist’s destroy (2013多校8 1004题 树形DP)
Terrorist’s destroy Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Othe ...
- HDU 4669 Mutiples on a circle (2013多校7 1004题)
Mutiples on a circle Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 65535/65535 K (Java/Oth ...
- hdu 5517 Triple(二维树状数组)
Triple Time Limit: 12000/6000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Sub ...
- 2018 HDU多校第四场赛后补题
2018 HDU多校第四场赛后补题 自己学校出的毒瘤场..吃枣药丸 hdu中的题号是6332 - 6343. K. Expression in Memories 题意: 判断一个简化版的算术表达式是否 ...
- 2018 HDU多校第三场赛后补题
2018 HDU多校第三场赛后补题 从易到难来写吧,其中题意有些直接摘了Claris的,数据范围是就不标了. 如果需要可以去hdu题库里找.题号是6319 - 6331. L. Visual Cube ...
- 2015 HDU 多校联赛 5363 Key Set
2015 HDU 多校联赛 5363 Key Set 题目: http://acm.hdu.edu.cn/showproblem.php? pid=5363 依据前面给出的样例,得出求解公式 fn = ...
随机推荐
- mysql删除有外链索引数据,Cannot delete or update a parent row: a foreign key constraint fails 问题的解决办法
mysql删除有外链索引数据Cannot delete or update a parent row: a foreign key constraint fails 问题的解决办法查询:DELETE ...
- 谷歌笔试题--给定一个集合A=[0,1,3,8](该集合中的元素都是在0,9之间的数字,但未必全部包含), 指定任意一个正整数K,请用A中的元素组成一个大于K的最小正整数。
谷歌笔试题--给定一个集合A=[0,1,3,8](该集合中的元素都是在0,9之间的数字,但未必全部包含), 指定任意一个正整数K,请用A中的元素组成一个大于K的最小正整数. Google2009华南地 ...
- Python入门之面向对象的__init__和__new__方法
Python入门之面向对象的__init__和__new__方法
- 09: python基础补充
1.1 闭包 1.闭包概念 1. 在一个外函数中定义了一个内函数,内函数里运用了外函数的临时变量,并且外函数的返回值是内函数的引用,这样就构成了一个闭包 2. 一般情况下,在我们认知当中,如果一个函数 ...
- CentOS7.3防火墙firewalld简单配置
今天安装了centos7.3, 想用iptables的save功能保存规则的时候发现跟rhel不一样了, 后来度娘说centos用的是firewalld而不是iptables了, 平时工作都是用re ...
- bootstrap4
lipsum, lorem生成假文, 是在编辑器中按tab键时生成的, 那个时候就已经生成了, 所以你在浏览器上看到的内容就是编辑器中的内容, 这个内容不会再变了. 所以你不要企图想刷新浏览器而改变假 ...
- HDU 4819 Mosaic (二维线段树&区间最值)题解
思路: 二维线段树模板题,马克一下,以后当模板用 代码: #include<cstdio> #include<cmath> #include<cstring> #i ...
- 【Coursera】History: Dawn of Electronic Computing学后小结
今天学习了Coursera上University of Michigan开的互联网的历史.技术和安全课程的FirstWeek内容. 先是吐槽下这个Coursera,认证非常麻烦,PC端需要摄像头拍照. ...
- SublimeText3常用快捷键和优秀插件(亲测)
SublimeText3常用快捷键和优秀插件 SublimeText是前端的一个神器,以其精简和可DIY而让广大fans疯狂.好吧不吹了直入正题 -_-!! 首先是安装,如果你有什么软件管家的话搜一下 ...
- 【Python】【元编程】【从协议到抽象基类】
"""class Vector2d: typecode = 'd' def __init__(self,x,y): self.__x = float(x) self.__ ...