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 = ...
随机推荐
- 轻型池不支持执行公共语言运行时(CLR)。禁用以下两个选项中的一个: “clr enabled”或“lightweight pooling”解决方法
执行2变一下代码 : 注意:1表示启用,0表示禁用. sp_configure ; GO sp_configure ; GO sp_configure ; go RECONFIGURE; GO E ...
- 2016NOI冬令营day0
上午写了一道题. 中午收拾好东西后兴高采烈地坐老司机开的出租车来到了美丽的南山中学!!!:) 志愿者太多了,弄得我们有点不好意思......:) 来到寝室,看到了传闻中的被子&空(kong4) ...
- [转载]ASP.NET-----Repeater数据控件的用法总结
一.Repeater控件的用法流程及实例: 1.首先建立一个网站,新建一个网页index.aspx. 2.添加或者建立APP_Data数据文件,然后将用到的数据库文件放到APP_Data文件夹中. 3 ...
- C++系统时间及字符串转换参考资料
https://msdn.microsoft.com/en-us/library/a442x3ye.aspx https://msdn.microsoft.com/en-us/library/fe06 ...
- python脚本监控获取当前Linux操作系统[内存]/[cpu]/[硬盘]/[登录用户]
此脚本应用在linux, 前提是需要有python和python的psutil模块 脚本 #!/usr/bin/env python # coding=utf-8 import sys import ...
- js面向对象编程: js类定义函数时prototype和this区别?
参考文章的链接:http://www.2cto.com/kf/201406/307790.html 测试代码如下: function ListCommon2(afirst) { var first=a ...
- Spring Boot + thymeleaf 实现文件上传下载
参考博客:https://juejin.im/post/5a326dcaf265da431048685e 技术选型:spring boot 2.1.1+thymeleaf+maven 码云地址:htt ...
- Python3基础 str + 字符串变量拼接
Python : 3.7.0 OS : Ubuntu 18.04.1 LTS IDE : PyCharm 2018.2.4 Conda ...
- poj3352 Road Construction & poj3177 Redundant Paths (边双连通分量)题解
题意:有n个点,m条路,问你最少加几条边,让整个图变成边双连通分量. 思路:缩点后变成一颗树,最少加边 = (度为1的点 + 1)/ 2.3177有重边,如果出现重边,用并查集合并两个端点所在的缩点后 ...
- ACM-ICPC 2018 沈阳赛区网络预赛 Made In Heaven(K短路)题解
思路:K短路裸题 代码: #include<queue> #include<cstring> #include<set> #include<map> # ...