Codeforces Manthan, Codefest 19 (open for everyone, rated, Div. 1 + Div. 2)
手玩三四项发现序列就是 $a,b,a\ xor\ b,a,b,...$,直接输出即可
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
using namespace std;
typedef long long ll;
inline int read()
{
int x=,f=; char ch=getchar();
while(ch<''||ch>'') { if(ch=='-') f=-; ch=getchar(); }
while(ch>=''&&ch<='') { x=(x<<)+(x<<)+(ch^); ch=getchar(); }
return x*f;
}
int T,a,b,n;
// a b ab a b
int main()
{
T=read();
while(T--)
{
a=read(),b=read(),n=read();
if(n%==) printf("%d\n",a);
if(n%==) printf("%d\n",b);
if(n%==) printf("%d\n",a^b);
}
return ;
}
$n$ 不大,直接枚举所有左端点,移动右端点并动态维护,数值比较大用 $map$ 即可
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<map>
using namespace std;
typedef long long ll;
inline int read()
{
int x=,f=; char ch=getchar();
while(ch<''||ch>'') { if(ch=='-') f=-; ch=getchar(); }
while(ch>=''&&ch<='') { x=(x<<)+(x<<)+(ch^); ch=getchar(); }
return x*f;
}
const int N=;
int n,a[N],tot,ans=N;
map <int,int> sum,cnt,vis;
int main()
{
n=read();
for(int i=;i<=n;i++)
a[i]=read(),sum[a[i]]++;
for(int i=;i<=n;i++)
if(sum[a[i]]>&&!vis[a[i]]) tot++,vis[a[i]]=;
if(!tot) { printf("0\n"); return ; }
for(int i=;i<=n;i++)
{
cnt.clear(); int now=;
for(int j=i;j<=n;j++)
{
cnt[a[j]]++; if(cnt[a[j]]==sum[a[j]]-) now++;
if(now==tot) { ans=min(ans,j-i+); break; }
}
}
printf("%d\n",ans);
return ;
}
又是构造题...
猜一下有规律,发现这样的矩阵横竖异或和都是 $0$:
......
发现 $n$ 一定是 $4$ 的倍数,所以把大矩形分成一些 $4*4$ 的矩形,然后把按上面的规律把矩阵一个个填入即可
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
using namespace std;
typedef long long ll;
inline int read()
{
int x=,f=; char ch=getchar();
while(ch<''||ch>'') { if(ch=='-') f=-; ch=getchar(); }
while(ch>=''&&ch<='') { x=(x<<)+(x<<)+(ch^); ch=getchar(); }
return x*f;
}
const int N=;
int n,a[N][N],tot;
int main()
{
n=read();
for(int i=;i<=n;i+=)
for(int j=;j<=n;j+=)
for(int k=;k<;k++)
for(int l=;l<;l++)
a[i+k][j+l]=tot++;
for(int i=;i<=n;i++)
{
for(int j=;j<=n;j++)
printf("%d ",a[i][j]);
printf("\n");
}
return ;
}
正难则反,考虑从后往前确定所有数,对于当前最后面的数,之前所有还没填的小于它的数都会产生贡献,发现当前位置的数越大,前面的贡献也越大
所以根据单调性直接二分最后一个位置的数,维护当前小于某个数的和用树状数组即可
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
using namespace std;
typedef long long ll;
inline ll read()
{
ll x=,f=; char ch=getchar();
while(ch<''||ch>'') { if(ch=='-') f=-; ch=getchar(); }
while(ch>=''&&ch<='') { x=(x<<)+(x<<)+(ch^); ch=getchar(); }
return x*f;
}
const int N=2e5+;
int n,b[N];
bool vis[N];
ll a[N],t[N];
inline void add(int x,int v) { while(x<=n) t[x]+=v,x+=x&-x; }
inline ll ask(int x) { ll res=; while(x) res+=t[x],x-=x&-x; return res; }
int main()
{
n=read();
for(int i=;i<=n;i++) a[i]=read(),add(i,i);
for(int i=n;i>=;i--)
{
int L=,R=n,mid,res;
while(L<=R)
{
mid=L+R>>;
if(ask(mid-)<=a[i])
{
L=mid+;
if(!vis[mid]) res=mid;
}
else R=mid-;
}
b[i]=res; vis[res]=; add(res,-res);
}
for(int i=;i<=n;i++) printf("%d ",b[i]);
printf("\n");
return ;
}
看一眼直接单调队列走起,然后被区间细节搞死,其实直接 $ST$ 表就可以了..
发现每一行可以分开处理,求出每一行每个位置的贡献加起来就行了
发现如果一行的数不多,那么中间一段位置的贡献都是最大的数,所以只要求出左右两边位置的最大值
发现左右两边的情况都差不多,先考虑左边
对于位置 $i$,在它之前的位置为 $j$ 的数要能够移动到 $i$ 的条件是 $i-j<=m-R$,其中 $m$ 是每一行最大长度,$R$ 是此行的数的数量
然后就可以单调队列维护,右边也同理,注意边界一段也可以没有数,即为 $0$,要记得处理
中间的话,维护一下差分标记即可,一些数组用完一定要记得还原!
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<vector>
using namespace std;
typedef long long ll;
inline int read()
{
int x=,f=; char ch=getchar();
while(ch<''||ch>'') { if(ch=='-') f=-; ch=getchar(); }
while(ch>=''&&ch<='') { x=(x<<)+(x<<)+(ch^); ch=getchar(); }
return x*f;
}
const int N=2e6+,INF=1e9+;
int n,m;
vector <int> V[N];
ll sum[N],tag[N]; int now[N];
int Q[N],l,r;
int main()
{
n=read(),m=read(); int a;
for(int i=;i<=n;i++)
{
a=read();
for(int j=;j<=a;j++) V[i].push_back(read());
}
memset(now,~0x3f,sizeof(now));//初始为-INF
for(int i=;i<=n;i++)
{
int R=V[i].size(),mx=; l=,r=;
for(int j=;j<=min(m-R,R);j++) now[j]=;
for(int j=m;j>max(m-R,R);j--) now[j]=;//边界可以没有数
for(int j=;j<=R;j++)
{
while(l<=r && j-Q[l]>m-R) l++;
while(l<=r && V[i][j-]>=V[i][Q[r]-]) r--;//记得vector下标从0开始
Q[++r]=j; now[j]=max(now[j],V[i][Q[l]-]); mx=max(mx,V[i][j-]);
}
if(R*<m) tag[R+]+=mx,tag[m-R+]-=mx;//打差分标记
l=,r=;
for(int j=R;j;j--)
{
int p=m-R+j;//当前位置
while(l<=r && Q[l]-j>m-R) l++;
while(l<=r && V[i][j-]>=V[i][Q[r]-]) r--;
Q[++r]=j; now[p]=max(now[p],V[i][Q[l]-]);
}
for(int j=;j<=R;j++) sum[j]+=now[j];//累计贡献
for(int j=max(R+,m-R+);j<=m;j++) sum[j]+=now[j];
for(int j=;j<=R;j++) now[j]=now[m-R+j]=-INF;//记得还原
}
ll S=;
for(int i=;i<=m;i++) S+=tag[i],sum[i]+=S;//处理差分标记
for(int i=;i<=m;i++) printf("%lld ",sum[i]);
printf("\n");
return ;
}
Codeforces Manthan, Codefest 19 (open for everyone, rated, Div. 1 + Div. 2)的更多相关文章
- Manthan, Codefest 19 (open for everyone, rated, Div. 1 + Div. 2)-D. Restore Permutation-构造+树状数组
Manthan, Codefest 19 (open for everyone, rated, Div. 1 + Div. 2)-D. Restore Permutation-构造+树状数组 [Pro ...
- Manthan, Codefest 19 (open for everyone, rated, Div. 1 + Div. 2)-C. Magic Grid-构造
Manthan, Codefest 19 (open for everyone, rated, Div. 1 + Div. 2)-C. Magic Grid-构造 [Problem Descripti ...
- Manthan, Codefest 19 (open for everyone, rated, Div. 1 + Div. 2)-E. Let Them Slide-思维+数据结构
Manthan, Codefest 19 (open for everyone, rated, Div. 1 + Div. 2)-E. Let Them Slide-思维+数据结构 [Problem ...
- Manthan, Codefest 19 (open for everyone, rated, Div. 1 + Div. 2) F. Bits And Pieces sosdp
F. Bits And Pieces 题面 You are given an array
- Manthan, Codefest 19 (open for everyone, rated, Div. 1 + Div. 2) G. Polygons 数论
G. Polygons Description You are given two integers
- Manthan, Codefest 19 (open for everyone, rated, Div. 1 + Div. 2) (1208F,1208G,1208H)
1208 F 大意: 给定序列$a$, 求$\text{$a_i$|$a_j$&$a_k$}(i<j<k)$的最大值 枚举$i$, 从高位到低位贪心, 那么问题就转化为给定$x$ ...
- RMQ+差分处理(Let Them Slide)Manthan, Codefest 19 (open for everyone, rated, Div. 1 + Div. 2)
题意:https://codeforc.es/contest/1208/problem/E 现有n行w列的墙,每行有一排连续方块,一排方块可以左右连续滑动,且每个方块都有一个价值,第i 列的价值定义为 ...
- 线段树维护最后一个0的位置(Restore Permutation)Manthan, Codefest 19 (open for everyone, rated, Div. 1 + Div. 2)
题意:https://codeforc.es/contest/1208/problem/D 给你长度为n的序列,s[i]的值为p[1]到p[i-1]中比p[i]小的数的和,让你求出p序列. 思路: 首 ...
- Manthan, Codefest 19 (open for everyone, rated, Div. 1 + Div. 2)E(多重集维护)
#define HAVE_STRUCT_TIMESPEC#include<bits/stdc++.h>using namespace std;long long ans[1000007]; ...
随机推荐
- iView栅格的使用
一般情况下栅格系统都会把每行row分为12列,但是iview是采用了24栅格系统,将区域进行24等分 基础用法 实例代码: <template> <Row> <Col s ...
- mybatis添加数据时返回主键 insert 返回主键值
insert 返回主键值 useGeneratedKeys=“true” parameterType=“USer” keyProperty=“id”, <insert id="inse ...
- 【bzoj1398】Vijos1382寻找主人 Necklace
*题目描述: 给定两个项链的表示,判断他们是否可能是一条项链. *输入: 输入文件只有两行,每行一个由0至9组成的字符串,描述一个项链的表示(保证项链的长度是相等的). *输出: 如果两条项链不可能同 ...
- django-rest-swagger 使用【转】
转自:https://www.cnblogs.com/delav/p/10242017.html Swagger是一个API开发者的工具框架,用于生成.描述.调用和可视化RESTful风格的Web服务 ...
- [BZOJ4205][FJ2015集训]卡牌配对
题目:卡牌配对 传送门:None 题目大意:有$n_1$张$X$类牌和$n_2$张$Y$类类牌,每张卡牌上有三个属性值:$A,B,C$.两张卡牌能够配对,当且仅当,存在至多一项属性值使得两张卡牌该项属 ...
- JavaScript export
export The export statement is used when creating JavaScript modules to export functions, objects, o ...
- 源码搭建mysql5.7.20
转载过来的文章,只是借用原文样式与框架,根据自己实验环境进行全面改动,仅供参考! 使用yum安装的MySQL一般版本比较旧,但是运行稳定.如果想要尝试最新的功能或者需要指定特殊的功能的话,就需要手工进 ...
- z-index的各种坑
z-index属性 z-index : auto | number z-index 属性设置元素的堆叠顺序,如果为正数,则离用户更近,为负数则表示离用户更远: 拥有更高堆叠顺序的元素总是会处于堆叠顺序 ...
- linux的find和grep区别?
为什么会把 grep和find 这两个命令拿在一起来讨论? 是因为他们之间有一个容易混淆的地方, [在我的记忆中] : -name ? 它是find的选项! 不是grep的选项! 实际上, find基 ...
- Vue知识整理4:v-html标签
可以在数据绑定中使用html标签,这样在变量里可以使用html标签输出结果,如下所示: