Educational Codeforces Round 56 (Rated for Div. 2)
涨rating啦。。
不过话说为什么有这么多数据结构题啊,难道是中国人出的?
A - Dice Rolling
傻逼题,可以用一个三加一堆二或者用一堆二,那就直接。。
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<queue>
#include<set>
#include<map>
#include<vector>
#include<cmath>
#include<cctype>
using namespace std;
typedef long long ll;
const int Maxn=610000;
int main() {
int t,x;
scanf("%d",&t);
while(t--) {
scanf("%d",&x);
printf("%d\n",x>>1);
}
return 0;
}
B - Letters Rearranging
统计一下如果全部相同输出-1,否则排个序就好了。
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<queue>
#include<set>
#include<map>
#include<vector>
#include<cmath>
#include<cctype>
using namespace std;
typedef long long ll;
const int Maxn=610000;
char s[Maxn];
int b[110];
int main() {
int t,x;
scanf("%d",&t);
while(t--) {
scanf("%s",s);
memset(b,0,sizeof(b));
int lens=strlen(s);
for(int i=0;i<lens;i++)
b[s[i]-'a']++;
int temp=0;
for(int i=0;i<26;i++) if(b[i]) temp++;
if(temp==1) {
puts("-1");
}
else {
for(int i=0;i<26;i++)
while(b[i]--) putchar('a'+i);
putchar('\n');
}
}
return 0;
}
C - Mishka and the Last Exam
大概就是让前面的尽量小,让后面的尽量大,那就直接扫就好了。
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<queue>
#include<set>
#include<map>
#include<vector>
#include<cmath>
#include<cctype>
using namespace std;
typedef long long ll;
const int Maxn=610000;
int n;
ll b[Maxn],a[Maxn];
int main() {
scanf("%d",&n);
for(int i=1;i<=n/2;i++) scanf("%I64d",&b[i]);
ll temp=0,tempp=0x7fffffffffffffff;
for(int i=1;i<=n/2;i++) {
ll x=b[i]-temp;
if(x>tempp)
x=tempp;
temp=a[i]=b[i]-x;
tempp=a[n-i+1]=x;
}
for(int i=1;i<=n;i++) printf("%I64d ",a[i]);
return 0;
}
D - Beautiful Graph
二分图染个色就好了。。
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<queue>
#include<set>
#include<map>
#include<vector>
#include<cmath>
#include<cctype>
using namespace std;
typedef long long ll;
const int Maxn=610000;
const ll mod=998244353;
ll powp(ll a,ll b) {
ll ans=1;
while(b) {
if(b&1) ans=ans*a%mod;
a=a*a%mod;
b>>=1;
}
return ans;
}
int vis[Maxn],col[Maxn],to[Maxn],nxt[Maxn],first[Maxn],tot;
int t,n,m,u,v,flag;
ll bj0,bj1;
void work(int root) {
vis[root]=1;
for(int i=first[root];i;i=nxt[i])
if(!vis[to[i]]) {
col[to[i]]=col[root]^1;
if(col[to[i]]) bj1++;
else bj0++;
work(to[i]);
}
else if(col[to[i]]==col[root]) flag=1;
}
inline void add(int u,int v) {
to[tot]=v;
nxt[tot]=first[u];
first[u]=tot++;
to[tot]=u;
nxt[tot]=first[v];
first[v]=tot++;
}
int main() {
scanf("%d",&t);
while(t--) {
scanf("%d%d",&n,&m);
for(int i=1;i<=n;i++) first[i]=0,vis[i]=0;
tot=1;
for(int i=1;i<=m;i++) {
scanf("%d%d",&u,&v);
add(u,v);
}
ll ans=1;flag=0;
for(int i=1;i<=n;i++)
if(!vis[i]) {
bj0=bj1=0;bj0++;col[i]=0;
work(i);
if(flag) {
ans=0;
break;
}
ans=ans*(powp(2,bj0)+powp(2,bj1))%mod;
}
printf("%d\n",ans);
}
return 0;
}
G - Multidimensional Queries
大概就是有n个k维空间上的点,每次修改一个点或查找区间内选两个点的曼哈顿距离最大值。
首先如果k==2,那就可以转切比雪夫距离。
考虑转切比雪夫的时候,把原来的坐标\((x,y)\)变成了\((x+y,x-y)\),这么做的原因就是x与y的大小关系相同或不同。那么如果扩展到k维,那就是k个坐标的大小关系相同或不同。比如三维的情况:\((x,y,z)\)转成\((x+y+z,x+y-z,x-y+z,x-y-z)\)。那么k维的就可以转成\(2^{k-1}\)维,那就直接开这些线段树就好了。
时空复杂度:\(O(2^{k-1}n\log n)\)
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<queue>
#include<set>
#include<map>
#include<vector>
#include<cmath>
#include<cctype>
using namespace std;
typedef long long ll;
const int Maxn=610000;
const int inf=0x7fffffff;
int n,k,tmp[10],tot,b[110][10];
void dfs(int now) {
if(now==k) {
tot++;
for(int i=1;i<k;i++) b[tot][i]=tmp[i];
return;
}
tmp[now]=1;
dfs(now+1);
tmp[now]=-1;
dfs(now+1);
}
int tl[Maxn],tr[Maxn];
void build(int root,int l,int r) {
tl[root]=l;tr[root]=r;
if(l==r) return;
int mid=l+r>>1;
build(root<<1,l,mid);
build((root<<1)|1,mid+1,r);
}
struct segtree {
int tn[Maxn],tm[Maxn];
int update(int root) {
tn[root]=min(tn[root<<1],tn[(root<<1)|1]);
tm[root]=max(tm[root<<1],tm[(root<<1)|1]);
}
void change(int root,int x,int y) {
int l=tl[root],r=tr[root];
if(l==r) {
tn[root]=tm[root]=y;
return;
}
int mid=l+r>>1;
if(x<=mid) change(root<<1,x,y);
else change((root<<1)|1,x,y);
update(root);
}
int qmin(int root,int l,int r) {
int lc=tl[root],rc=tr[root];
int mid=lc+rc>>1;
if(l<=lc&&r>=rc)
return tn[root];
int ans=inf;
if(l<=mid) ans=min(ans,qmin(root<<1,l,r));
if(r>mid) ans=min(ans,qmin((root<<1)|1,l,r));
return ans;
}
int qmax(int root,int l,int r) {
int lc=tl[root],rc=tr[root];
int mid=lc+rc>>1;
if(l<=lc&&r>=rc)
return tm[root];
int ans=-inf;
if(l<=mid) ans=max(ans,qmax(root<<1,l,r));
if(r>mid) ans=max(ans,qmax((root<<1)|1,l,r));
return ans;
}
}t[21];
int main() {
scanf("%d%d",&n,&k);
dfs(1);build(1,1,n);
for(int i=1;i<=n;i++) {
for(int j=1;j<=k;j++) scanf("%d",&tmp[j]);
for(int j=1;j<=tot;j++) {
int temp=tmp[1];
for(int l=1;l<k;l++)
temp+=b[j][l]*tmp[l+1];
t[j].change(1,i,temp);
}
}
scanf("%d",&n);int opt,x,l,r;
while(n--) {
scanf("%d",&opt);
if(opt==1) {
scanf("%d",&x);
for(int i=1;i<=k;i++) scanf("%d",&tmp[i]);
for(int j=1;j<=tot;j++) {
int temp=tmp[1];
for(int l=1;l<k;l++)
temp+=b[j][l]*tmp[l+1];
t[j].change(1,x,temp);
}
}
else {
scanf("%d%d",&l,&r);
int ans=0;
for(int i=1;i<=tot;i++)
ans=max(ans,t[i].qmax(1,l,r)-t[i].qmin(1,l,r));
printf("%d\n",ans);
}
}
return 0;
}
Educational Codeforces Round 56 (Rated for Div. 2)的更多相关文章
- Multidimensional Queries(二进制枚举+线段树+Educational Codeforces Round 56 (Rated for Div. 2))
题目链接: https://codeforces.com/contest/1093/problem/G 题目: 题意: 在k维空间中有n个点,每次给你两种操作,一种是将某一个点的坐标改为另一个坐标,一 ...
- Educational Codeforces Round 56 (Rated for Div. 2) D. Beautiful Graph 【规律 && DFS】
传送门:http://codeforces.com/contest/1093/problem/D D. Beautiful Graph time limit per test 2 seconds me ...
- Educational Codeforces Round 56 (Rated for Div. 2) ABCD
题目链接:https://codeforces.com/contest/1093 A. Dice Rolling 题意: 有一个号数为2-7的骰子,现在有一个人他想扔到几就能扔到几,现在问需要扔多少次 ...
- Educational Codeforces Round 56 (Rated for Div. 2) D
给你一个无向图 以及点的个数和边 每个节点只能用1 2 3 三个数字 求相邻 两个节点和为奇数 能否构成以及有多少种构成方法 #include<bits/stdc++.h> usin ...
- Educational Codeforces Round 56 (Rated for Div. 2) F - Vasya and Array dp好题
F - Vasya and Array dp[ i ][ j ] 表示用了前 i 个数字并且最后一个数字是 j 的方案数. dp[ i ][ j ] = sumdp [i - 1 ][ j ], 这样 ...
- Educational Codeforces Round 56 (Rated for Div. 2) E(1093E) Intersection of Permutations (树套树,pb_ds)
题意和分析在之前的链接中有:https://www.cnblogs.com/pkgunboat/p/10160741.html 之前补题用三维偏序的cdq的分治A了这道题,但是感觉就算比赛再次遇到类似 ...
- Educational Codeforces Round 56 (Rated for Div. 2) F. Vasya and Array
题意:长度为n的数组,数组中的每个元素的取值在1-k的范围内或者是-1,-1代表这个元素要自己选择一个1-k的数字去填写,然后要求填完的数组中不能出现连续长度大于len的情况,询问填空的方案数. 题解 ...
- Educational Codeforces Round 56 (Rated for Div. 2) D. Beautiful Graph (二分图染色)
题意:有\(n\)个点,\(m\)条边的无向图,可以给每个点赋点权\({1,2,3}\),使得每个点连的奇偶不同,问有多少种方案,答案对\(998244353\)取模. 题解:要使得每个点所连的奇偶不 ...
- Educational Codeforces Round 60 (Rated for Div. 2) - C. Magic Ship
Problem Educational Codeforces Round 60 (Rated for Div. 2) - C. Magic Ship Time Limit: 2000 mSec P ...
随机推荐
- 正则表达式(三):Unicode诸问题下篇(转)
原文:http://www.infoq.com/cn/news/2011/04/regular-expressions-4 我们使用正则表达式,熟练掌握各种功能和结构只是手段,解决实际的问题才是真正的 ...
- javaScript高级教程(五) Event Flow
1.两个阶段三个模型:Netscape支持事件捕获,IE支持事件冒泡,w3c是先捕获后冒泡 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 S ...
- easyUi引入方法
1:创建一个动态web工程: 去官网http://www.jeasyui.net/download/下载官网文档 我去官网下载的最新版本,个人根据自己的需求下载即可.2:在webConte ...
- 十天精通CSS3(8)
变形--旋转 rotate() 旋转rotate()函数通过指定的角度参数使元素相对原点进行旋转.它主要在二维空间内进行操作,设置一个角度值,用来指定旋转的幅度.如果这个值为正值,元素相对原点中心顺时 ...
- shell date 获取昨天日期
使用date -d 选项: date +"%Y%m%d" -d "+n days" 今天的后n天日期 date +" ...
- PHPExcel 基本用法详解
.header header("Content-Type:application/vnd.ms-excel"); header("Content-Disposition: ...
- Here we take a closer look at the Jordans Unveil
Here we take a closer look at the Jordans Unveil. This Mens release is both unique and striking. The ...
- vue项目打包后css背景图路径不对的问题
问题描述: 自己在自学vue做项目的过程中,遇到一个有关背景图片路径的问题,就是css代码中背景图片是根据相对路径来写的,如下图: 当使用npm run dev命令本地访问的时候,背景图片是正常显示的 ...
- zw版【转发·台湾nvp系列Delphi例程】HALCON ZoomImageFactor
zw版[转发·台湾nvp系列Delphi例程]HALCON ZoomImageFactor procedure TForm1.Button1Click(Sender: TObject);var ima ...
- jquery ajax基本用法
<script src="http://libs.baidu.com/jquery/2.1.1/jquery.min.js"></script> <s ...