Little Chef and Sums

分析:水题,去维护一下前缀和以及后缀和就好,注意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 ;
}

Minimum Good Permutation

分析:水题,对于个数为偶数的交换任意两个就好,对于个数为奇数的,前面交换任意两个,后三个数做两次交换

 #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 ;
}

Chef and Pick Digit

分析:找出数列中出现过的数,然后暴力去构造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 ;
}

Sereja and Commands

分析:非常好的一道题,感谢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的更多相关文章

  1. codechef September Challenge 2017 Fill The Matrix

    这道题我们发现0就代表相同1代表少1或者大1 那么我们根据题目连边 如果存在1(边权只为或0)个数为奇数的环就是无解 #include<cstdio> #include<cstrin ...

  2. codechef September Challenge 2017 Sereja and Commands

    ———————————————————————————— 这道题维护一下原序列的差分以及操作的差分就可以了 记得倒着差分操作 因为题目保证操作2的l r 小与当前位置 #include<cstd ...

  3. Codechef September Challenge 2018 游记

    Codechef September Challenge 2018 游记 Magician versus Chef 题目大意: 有一排\(n(n\le10^5)\)个格子,一开始硬币在第\(x\)个格 ...

  4. 【AtCoder】Mujin Programming Challenge 2017

    Mujin Programming Challenge 2017 A - Robot Racing 如果每个数都是一个一个间隔开的,那么答案是\(n!\) 考虑把一个数挪到1,第二个数挪到3,以此类推 ...

  5. September 21st 2017 Week 38th Thursday

    What fire does not destroy, it hardens. 烈火摧毁不了的东西,只会变得更坚固. The true gold can stand the test of fire, ...

  6. September 19th 2017 Week 38th Tuesday

    Live boldly. Push yourself. Don't settle. 勇敢生活,突破自我,永不设限! Don't indulge in the past, whether it was ...

  7. September 10th 2017 Week 37th Sunday

    Dream most deep place, only then the smile is not tired. 梦的最深处,只有微笑不累. Everyday I expect I can go to ...

  8. Codechef September Challenge 2019 Division 2

    Preface 这确实应该是我打过的比较水的CC了(其实就打过两场) 但由于我太弱了打的都是Div2,所以会认为上一场更简单,其实上一场Div的数据结构是真的毒 好了废话不多说快速地讲一下 A Eas ...

  9. CodeChef June Challenge 2017

    好气啊,本来以为比赛时间还有很多,结果回家养病两天回到学校怎么比赛就结束了(雾),大约是小高考弄错了时间? 挑3道有意思的写写题解吧. Cloning 题目大意:给一个序列,每次询问两个等长区间,问区 ...

随机推荐

  1. Spark源码分析之七:Task运行(一)

    在Task调度相关的两篇文章<Spark源码分析之五:Task调度(一)>与<Spark源码分析之六:Task调度(二)>中,我们大致了解了Task调度相关的主要逻辑,并且在T ...

  2. 详解spring boot实现多数据源代码实战

    之前在介绍使用JdbcTemplate和Spring-data-jpa时,都使用了单数据源.在单数据源的情况下,Spring Boot的配置非常简单,只需要在application.propertie ...

  3. 利用树的先序和后序遍历打印 os 中的目录树

    [0]README 0.1)本代码均为原创,旨在将树的遍历应用一下下以加深印象而已:(回答了学习树的遍历到底有什么用的问题?)你对比下linux 中的文件树 和我的打印结果就明理了: 0.2)我们采用 ...

  4. Oracle 10g ORA-12154: TNS: could not resolve the connect identifier specified 问题解决! 我同事遇到的问题。 username/

    Oracle 10g ORA-12154: TNS: could not resolve the connect identifier specified 问题解决! 我同事遇到的问题. userna ...

  5. Linux将进程写入开机自启动

    只需将启动的命令写入/etc/rc.local 如让mongodb开机自启动: echo "/usr/local/mongodb/bin/mongod --dbpath=/usr/local ...

  6. python 基础 7.5 commands 模块

    一. commands 模块   1.commands 模块只使用与linxu 的shell 模式下 在我们平时码字时,经常需要调用系统脚本或者系统命令来解决很多问题,接下来,我们就介绍给大家一个很好 ...

  7. 几句话搞懂URI、URL、URN之间的关系

    1.URI,是uniform resource identifier,统一资源标识符,用来唯一的标识一个资源. 2.RL是uniform resource locator,统一资源定位器,它是一种具体 ...

  8. mysql系列之4.mysql字符集

    针对mysql语句的临时办法: 先查看下mysql的各种编码设置情况, 如果结果显示有几项的编码不一致, 请先调整linux的系统编码 mysql> show variables like 'c ...

  9. ubuntun下安装sublime text

    Sublime Text 3 是一款轻量级.跨平台的文本编辑器.可安装在ubuntu,Windows和MAC OS X上高级文本编辑软件,有一个专有的许可证,但该程序也可以免费使用,无需做逆向工程.如 ...

  10. jquery .html(),.text(),.val()用法

    .html()用为读取和修改元素的HTML标签 .text()用来读取或修改元素的纯文本内容 .val()用来读取或修改表单元素的value值. 这三个方法功能上的对比 .html(),.text() ...