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. Hibernate学习一----------Hibernate初实现

    © 版权声明:本文为博主原创文章,转载请注明出处 ORM(Object/Relationship Mapping):对象/关系映射 - 利用面向对象思想编写的数据库应用程序最终都是把对象信息保存在关系 ...

  2. Java 9 模块解耦的设计策略

    1. 概述 Java 平台模块系统 (Java Platform Module System,JPMS)提供了更强的封装.更可靠且更好的关注点分离. 但所有的这些方便的功能都需要付出代价.由于模块化的 ...

  3. Selenium学习(三)Selenium总是崩溃的解决办法

    在使用selenium打开浏览器总是崩溃,最近查资料获得可行的解决办法: import sys from selenium import webdriver p = __import__('selen ...

  4. Struts2 ModelDriven接口使用

    用户在做http请求时一般都有两种方式:get和post方式.get方式用来获取查询相关信息,既向服务器获得信息,而post方式用来更新信息既向服务器提交数据.通常情况下,用get方式向服务器获取信息 ...

  5. 五个知识体系之-SQL学习-第三天

    1. sql约束作用 主键约束作用:保证插入数据的有效性.比如性别列,只能是“男”“女”,输入“abc”就是无效的,所以你可以添加约束alter table 表名add constraint chk_ ...

  6. EasyPlayerPro(Windows)流媒体播放器开发之框架讲解

    EasyPlayerPro for Windows是基于ffmpeg进行开发的全功能播放器,开发过程中参考了很多开源的播放器,诸如vlc和ffplay等,其中最强大的莫过于vlc,但是鉴于vlc框架过 ...

  7. 九度OJ 1153:括号匹配问题 (DP)

    时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:5193 解决:2248 题目描述: 在某个字符串(长度不超过100)中有左括号.右括号和大小写字母:规定(与常见的算数式子一样)任何一个左括 ...

  8. 【题解】CF989C A Mist of Florescence

    [题解]CF989C A Mist of Florescence 题目大意: 让你构造一个\(n∗m\)矩阵,这个矩阵由4种字符填充构成,给定4个整数,即矩阵中每种字符构成的四联通块个数,\(n,m\ ...

  9. Java for LeetCode 118 Pascal's Triangle

    Given numRows, generate the first numRows of Pascal's triangle. For example, given numRows = 5, Retu ...

  10. POJ2443 Set Operation —— bitset

    题目链接:https://vjudge.net/problem/POJ-2443 Set Operation Time Limit: 3000MS   Memory Limit: 65536K Tot ...