September Challenge 2017
分析:水题,去维护一下前缀和以及后缀和就好,注意long long
#include "iostream"
#include "cstdio"
#include "cstring"
#include "string"
using namespace std;
const int maxn=1e5+;
const long long INF=1e10+;
long long a[maxn],dp[maxn];
int n;
int main()
{
int T;
scanf("%d",&T);
while(T--){
memset(dp,,sizeof(dp));
scanf("%d",&n);
long long sum=;
for(int i=;i<=n;i++){
scanf("%lld",&a[i]);
sum+=a[i];
dp[i]=dp[i-]+a[i];
}
long long ans=INF;
int pos;
for(int i=;i<=n;i++){
long long num=sum+dp[i];
if(num<ans){
ans=num;
pos=i;
}
sum-=a[i];
}
printf("%d\n",pos);
}
return ;
}
分析:水题,对于个数为偶数的交换任意两个就好,对于个数为奇数的,前面交换任意两个,后三个数做两次交换
#include "iostream"
#include "cstdio"
#include "cstring"
#include "string"
using namespace std;
const int maxn=1e5+;
int T,n,a[maxn];
int main()
{
int T;
cin>>T;
while(T--){
cin>>n;
for(int i=;i<=n;i++)
a[i]=i;
if(n%==){
for(int i=;i<=n;i+=){
swap(a[i],a[i+]);
}
for(int i=;i<n;i++){
printf("%d ",a[i]);
}
printf("%d\n",a[n]);
}else{
if(n==){
printf("%d\n",a[n]);
}else{
for(int i=;i<=n-;i+=){
swap(a[i],a[i+]);
}
swap(a[n-],a[n-]);
swap(a[n-],a[n]);
for(int i=;i<n;i++){
printf("%d ",a[i]);
}
printf("%d\n",a[n]);
}
}
}
return ;
}
分析:找出数列中出现过的数,然后暴力去构造A到Z就好了,注意有些数在数列中只出现过一次
#include "iostream"
#include "cstdio"
#include "cstring"
#include "string"
#include "set"
using namespace std;
const int maxn=1e5+;
const int maxm=;
int vis[maxn],f[maxm];
char s[maxn];
int T;
int main()
{
cin>>T;
getchar();
while(T--){
memset(s,,sizeof(s));
memset(vis,,sizeof(vis));
memset(f,,sizeof(f));
int n=;
char ch=getchar();
while(ch!='\n') s[++n]=ch,ch=getchar();
for(int i=;i<=n;i++){
int num=s[i]-'';
vis[num]++;
}
for(int i=;i<=;i++){
for(int j=;j<=;j++){
if(vis[i]&&vis[j]){
if(i==j&&vis[i]==) continue;
int num=i*+j;
if(num>='A'&&num<='Z'){
f[num]=;
}
}
}
}
for(char i='A';i<='Z';i++)
if(f[i]){
printf("%c",i);
}
printf("\n");
}
return ;
}
分析:非常好的一道题,感谢hzm教我怎么做,首先我们需要用线段树去维护每个操作出现的次数。这个地方首先我们倒着推,开始的时候我们初始化每个操作都执行1次,然后遇到2的时候,我们就把2所维护的区间[l,r]当中的每个数都加上当前这个操作执行的次数,这样我们可以求出每个1操作执行了多少次,最后在线段树区间修改就搞定了。
#include "iostream"
#include "cstdio"
#include "cstring"
#include "string"
#include "vector"
using namespace std;
const int maxn=1e5+;
const int mod=1e9+;
int T,n,m;
struct Node
{
int num,x,y;
};
Node p[maxn]; //typedef long long int;
struct T
{
int l, r;
int c;
} tree[maxn<<];
int add[maxn<<], mul[maxn<<]; void pushdown(int k, int d,int p)
{
if(mul[k]==&&add[k]==)
return ;
tree[k<<].c=tree[k<<].c*mul[k]%p;
tree[k<<|].c=tree[k<<|].c*mul[k]%p;
tree[k<<].c=(tree[k<<].c+add[k]*(d-(d>>)))%p;
tree[k<<|].c=(tree[k<<|].c+add[k]*(d>>))%p;
mul[k<<]=mul[k]*mul[k<<]%p;
mul[k<<|]=mul[k]*mul[k<<|]%p;
add[k<<]=(add[k<<]*mul[k]+add[k])%p;
add[k<<|]=(add[k]+add[k<<|]*mul[k])%p;
add[k]=;
mul[k]=;
return ;
}
void pushup(int k,int p)
{
tree[k].c=(tree[k<<].c+tree[k<<|].c)%p;
}
void build1(int l, int r, int k, int p)
{
tree[k].l=l;
tree[k].r=r;
tree[k].c=;
mul[k]=;
add[k]=;
if(l==r)
{
tree[k].c=;
return;
}
int mid=(tree[k].l+tree[k].r)>>;
build1(l, mid, k<<, p);
build1(mid+,r,k<<|, p);
pushup(k, p);
}
void build0(int l, int r, int k, int p)
{
tree[k].l=l;
tree[k].r=r;
tree[k].c=;
mul[k]=;
add[k]=;
if(l==r)
{
tree[k].c=;
return;
}
int mid=(tree[k].l+tree[k].r)>>;
build0(l, mid, k<<, p);
build0(mid+,r,k<<|, p);
pushup(k, p);
}
void update(int l, int r, int k, int c, int op, int p)
{
if(tree[k].l>=l&&tree[k].r<=r){
if(op==){
add[k]=add[k]*c%p;
mul[k]=mul[k]*c%p;
tree[k].c=tree[k].c*c%p;
}
else{
add[k]=(add[k]+c)%p;
tree[k].c=(tree[k].c+(tree[k].r-tree[k].l+)*c)%p;
}
return;
}
pushdown(k, tree[k].r-tree[k].l+, p);
int mid=(tree[k].l+tree[k].r)>>;
if(l<=mid)
update(l,r,k<<,c,op,p);
if(r>mid)
update(l,r,k<<|,c,op,p);
pushup(k,p);
}
int query(int l, int r, int k, int p)
{
if(tree[k].l>=l&&tree[k].r<=r)
return tree[k].c%p;
pushdown(k, tree[k].r-tree[k].l+, p);
int ans=;
int mid = (tree[k].l+tree[k].r)>>;
if(l<=mid)
ans=(ans+query(l,r,k<<,p))%p;
if(r>mid)
ans=(ans+query(l,r,k<<|, p))%p;
return ans%p;
} vector<int> Q;
int dp[maxn];
int main()
{
cin>>T;
while(T--){
memset(dp,,sizeof(dp));
scanf("%d%d",&n,&m);
int N=max(n,m);
Q.clear();
build1(,N,,mod);
for(int i=;i<=m;i++){
scanf("%d%d%d",&p[i].num,&p[i].x,&p[i].y);
if(p[i].num==){
Q.push_back(i);
}
}
if(Q.size()==m){
build0(,N,,mod);
for(int i=;i<=m;i++){
update(p[i].x,p[i].y,,,,mod);
}
for(int i=;i<n;i++)
printf("%d ",query(i,i,,mod));
printf("%d\n",query(n,n,,mod));
continue;
}
if(Q.size()==){
for(int i=;i<n;i++)
printf("0 ");
printf("0\n");
continue;
}
for(int i=m;i>=;i--){
if(p[i].num==){
continue;
}else{
int res=query(i,i,,mod);
update(p[i].x,p[i].y,,res,,mod);
}
}
for(int i=;i<Q.size();i++){
dp[Q[i]]=query(Q[i],Q[i],,mod);
//printf("%d ",dp[Q[i]]);
}
//printf("\n");
build0(,N,,mod);
for(int i=;i<Q.size();i++){
int tt=Q[i];
int num=dp[tt];
//cout<<tt<<endl;
//cout<<num<<endl;
update(p[tt].x,p[tt].y,,num,,mod);
//add1(p[tt].x,num);
//add1(p[tt].y+1,-num);
}
for(int i=;i<n;i++)
printf("%d ",query(i,i,,mod));
printf("%d\n",query(n,n,,mod));
}
return ;
}
September Challenge 2017的更多相关文章
- codechef September Challenge 2017 Fill The Matrix
这道题我们发现0就代表相同1代表少1或者大1 那么我们根据题目连边 如果存在1(边权只为或0)个数为奇数的环就是无解 #include<cstdio> #include<cstrin ...
- codechef September Challenge 2017 Sereja and Commands
———————————————————————————— 这道题维护一下原序列的差分以及操作的差分就可以了 记得倒着差分操作 因为题目保证操作2的l r 小与当前位置 #include<cstd ...
- Codechef September Challenge 2018 游记
Codechef September Challenge 2018 游记 Magician versus Chef 题目大意: 有一排\(n(n\le10^5)\)个格子,一开始硬币在第\(x\)个格 ...
- 【AtCoder】Mujin Programming Challenge 2017
Mujin Programming Challenge 2017 A - Robot Racing 如果每个数都是一个一个间隔开的,那么答案是\(n!\) 考虑把一个数挪到1,第二个数挪到3,以此类推 ...
- September 21st 2017 Week 38th Thursday
What fire does not destroy, it hardens. 烈火摧毁不了的东西,只会变得更坚固. The true gold can stand the test of fire, ...
- September 19th 2017 Week 38th Tuesday
Live boldly. Push yourself. Don't settle. 勇敢生活,突破自我,永不设限! Don't indulge in the past, whether it was ...
- September 10th 2017 Week 37th Sunday
Dream most deep place, only then the smile is not tired. 梦的最深处,只有微笑不累. Everyday I expect I can go to ...
- Codechef September Challenge 2019 Division 2
Preface 这确实应该是我打过的比较水的CC了(其实就打过两场) 但由于我太弱了打的都是Div2,所以会认为上一场更简单,其实上一场Div的数据结构是真的毒 好了废话不多说快速地讲一下 A Eas ...
- CodeChef June Challenge 2017
好气啊,本来以为比赛时间还有很多,结果回家养病两天回到学校怎么比赛就结束了(雾),大约是小高考弄错了时间? 挑3道有意思的写写题解吧. Cloning 题目大意:给一个序列,每次询问两个等长区间,问区 ...
随机推荐
- webpack3.0 环境搭建
额.备份一下总是好的 #为了避免某些国外镜像源安装失败,先设置淘宝镜像代理 yarn config set registry https://registry.npm.taobao.org # 初始化 ...
- 在windows下安装apidocjs
1. 下载Node.js官方Windows版程序: https://nodejs.org/download/ 从0.6.1开始,Node.js在Windows平台上提供了两种安装方式,一是.M ...
- 高性能HTTP加速器Varnish安装与配置(包含常见错误)
Varnish是一款高性能的开源HTTP加速器.挪威最大的在线报纸Verdens Gang使用3台Varnish取代了原来的12台Squid,性能竟然比曾经更好.Varnish 的作者Poul-Hen ...
- 说说我的web前端之路,分享些前端的好书(转)
WEB前端研发工程师,在国内算是一个朝阳职业,这个领域没有学校的正规教育,大多数人都是靠自己自学成才.本文主要介绍自己从事web开发以来(从大二至今)看过的书籍和自己的成长过程,目的是给想了解Java ...
- 【Selenium + Python】路径报错之OSError: [Errno 22] Invalid argument: './t/report/2018-03-23_11:03:12_report.html'
现象: 此问题真的是太痛苦了,查了好多资料是说路径的问题,结果还是报错,后来一点点的排查才发现原来是!!!!!! 废话不多说上原来代码: if __name__ == '__main__': star ...
- Python学习总结之二 -- 数据类型
带你走进数据类型 一:整数.浮点数 Python中整数和浮点数的定义以及运算和C++都是一样的,我在这里就不需多说了,我就说明一点:Python相对于C/C++而言,定义整数没有int 和 long ...
- 继承ViewGroup类
Android中,布局都是直接或间接的继承自ViewGroup类,其中,ViewGroup的直接子类目前有: AbsoluteLayout, AdapterView<T extends Adap ...
- c# 枚举返回字符串操作
//内部类public static class EnumHelper { public static string GetDescription(Enum value) { if (value == ...
- php总结7——文件函数库、序列化数据、文件包含
7.1 文件函数库 php用来操作文件的 1) fopen 代开文件或URL 格式:resource fopen(string $filename, string $mode) 'r' 只读方式 ...
- python使用记录
#2017-7-17 1.用len()函数可以获得list元素的个数; len()可以获取字符串长度 2. list正向0开始索引,,逆向-1开始索引; 也可以把元素插入到指定的位置,比如索引号为1的 ...