涨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)的更多相关文章

  1. Multidimensional Queries(二进制枚举+线段树+Educational Codeforces Round 56 (Rated for Div. 2))

    题目链接: https://codeforces.com/contest/1093/problem/G 题目: 题意: 在k维空间中有n个点,每次给你两种操作,一种是将某一个点的坐标改为另一个坐标,一 ...

  2. 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 ...

  3. Educational Codeforces Round 56 (Rated for Div. 2) ABCD

    题目链接:https://codeforces.com/contest/1093 A. Dice Rolling 题意: 有一个号数为2-7的骰子,现在有一个人他想扔到几就能扔到几,现在问需要扔多少次 ...

  4. Educational Codeforces Round 56 (Rated for Div. 2) D

    给你一个无向图 以及点的个数和边  每个节点只能用1 2 3 三个数字 求相邻 两个节点和为奇数   能否构成以及有多少种构成方法 #include<bits/stdc++.h> usin ...

  5. 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 ], 这样 ...

  6. 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了这道题,但是感觉就算比赛再次遇到类似 ...

  7. Educational Codeforces Round 56 (Rated for Div. 2) F. Vasya and Array

    题意:长度为n的数组,数组中的每个元素的取值在1-k的范围内或者是-1,-1代表这个元素要自己选择一个1-k的数字去填写,然后要求填完的数组中不能出现连续长度大于len的情况,询问填空的方案数. 题解 ...

  8. Educational Codeforces Round 56 (Rated for Div. 2) D. Beautiful Graph (二分图染色)

    题意:有\(n\)个点,\(m\)条边的无向图,可以给每个点赋点权\({1,2,3}\),使得每个点连的奇偶不同,问有多少种方案,答案对\(998244353\)取模. 题解:要使得每个点所连的奇偶不 ...

  9. 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 ...

随机推荐

  1. if嵌套和elif的区别

    if嵌套的使用场景: 2个(多个)条件有前后关系,必须先满足条件1,再判断是否满足条件2. elif的使用场景: 2个(多个)条件是各自独立的平级关系,满足条件几就执行响应的代码. --------- ...

  2. fish shell 下gopath的设置问题

    GOPATH可以设置多个工程目录,linux下用冒号分隔(必须用冒号,fish shell的空格分割会出错),windows下用分号分隔,但是go get 只会下载pkg到第一个目录,但是编译的时候会 ...

  3. PHP + Ajax处理大数据查询并导出Excel

    思路:使用ajax多次请求服务器,分段生成多个Excel,然后打包压缩成zip,超链接指向下载的文件然后下载. [HTML部分] <input type="button" v ...

  4. vs2015 相关

    VS2015一共有3个版本,Visual Studio Community(社区版).Visual Studio Professional(专业版).Visual Studio Enterprise( ...

  5. 用户用户组管理:用户管理命令useradd

    添加玩用户后,其实改变的就是几个配置文件. 默认组一般设置成与用户名字,ID相同的.

  6. 不用中间变量交换a 和b的值

    // 不用中间变量的写法 ,假如 a=13, b=8; a=a+b =21; //此时 a=21; b=8; b=a-b=13; //此时a=21; b=13; a=a-b=8; //相当于 a=21 ...

  7. python服务器端、客户端的模型,客服端发送请求,服务端进行响应(web.py)

    服务器端.客户端的模型,客服端发送的请求,服务端的响应 相当于启动了一个web server install web.py 接口框架用到的包 http://webpy.org/tutorial3.zh ...

  8. 20165207 Exp2 后门原理与实践

    20165207 Exp2 后门原理与实践 〇.实验准备 两个虚拟机,一个kali一个win7.kali的ip是192.168.43.72,win7的ip是192.168.43.116,在win7关掉 ...

  9. MIPSsim使用说明

    MIPSsim下载:https://files.cnblogs.com/files/jiangxinnju/MIPSsim.zip 启动模拟器 双击MIPSsim.exe,即可启动该模拟器.MIPSs ...

  10. 发布QT exe

    https://blog.csdn.net/u014453443/article/details/85837138