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. 36:字符串排序SortString

    题目描述:编写一个程序,将输入字符串中的字符按如下规则排序. 规则1:英文字母从A到Z排列,不区分大小写. 如,输入:Type 输出:epTy 规则2:同一个英文字母的大小写同时存在时,按照输入顺序排 ...

  2. Hibernate学习四----------Blob

    © 版权声明:本文为博主原创文章,转载请注明出处 实例 1.项目结构 2.pom.xml <project xmlns="http://maven.apache.org/POM/4.0 ...

  3. hdu 2063过山车

    二分匹配 #include<iostream> #include<cstring> using namespace std; int k,m,n; int rem[500+5] ...

  4. 用GetTickCount()计算一段代码执行耗费的时间的小例子

    var aNow,aThen,aTime:Longint; begin aThen := GetTickCount(); Sleep();//代码段 aNow := GetTickCount(); a ...

  5. php解码“&#”编码的中文用函数html_entity_decode()

    遇到类似 ' 这种编码的字,我们可以用html_entity_decode()函数来解码. html_entity_decode() 函数把 HTML 实体转换为字符. 语法 html_entity_ ...

  6. 小tip: DOM appendHTML实现及insertAdjacentHTML

    一.无人不识君 据说今天是邓丽君奶奶会见马克思的日子,所谓“无人不识君”就多了份“无人不识邓丽君”之意. JS中有很多基本DOM方法,例如createElement, parentNode等,其中,a ...

  7. [转]浅谈Flash Socket通信安全沙箱

    用过Flash socket的同学都知道,Flash socket通讯有安全沙箱问题.就是在Flash Player发起socket通信时,会向服务端获取安全策略,如果得不到服务端响应,flash将无 ...

  8. php部分:网页中报表的打印,并用CSS样式控制打印的部分;

    网页中报表的打印,是通过调用window对象中的print()方法实现打印功能的: 调用浏览器本身的打印功能实现打印 <a href="#" onclick="wi ...

  9. 【BZOJ3451】Tyvj1953 Normal 点分治+FFT+期望

    [BZOJ3451]Tyvj1953 Normal Description 某天WJMZBMR学习了一个神奇的算法:树的点分治!这个算法的核心是这样的:消耗时间=0Solve(树 a) 消耗时间 += ...

  10. detached HEAD state

    1 detached HEAD state指的是什么 正常情况下,HEAD指向一个branch,而branch又指向一个commit. detached HEAD state指的是HEAD指针没有指向 ...