B. hxc写的

  AC code:

#pragma GCC optimize(2)
#include <cstdio>
#include <queue>
#include <string>
#include <cstring>
#include <algorithm>
#include <cstdlib>
#include <iostream>
#include <iomanip>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <fstream>
#include <cassert>
#define ll long long
#define R register int
#define I inline void
#define lc c[x][0]
#define rc c[x][1] using namespace std;
const int INF = 0x3f3f3f3f;
const int maxn = 1e6 + ;
int n,q; inline int read()
{
int x=,f=; char ch=;
while(!isdigit(ch)) {f|=ch=='-';ch=getchar();}
while(isdigit(ch)) x=(x<<)+(x<<)+(ch^),ch=getchar();
return f?-x:x;
} struct node
{
int num;
int typ;
int key;
int ans;
}pp[maxn]; vector<int> v; int getid(int x)
{
return lower_bound(v.begin(),v.end(),x) - v.begin();
} int con[maxn];
int nxt[maxn]; int cmp(node a,node b)
{
if(a.key != b.key)
return a.key > b.key;
return a.num < b.num;
} int cmp1(node a,node b)
{
return a.num < b.num;
} int find(int x)
{
if(x == nxt[x])
return x;
return nxt[x] = find(nxt[x]);
}
int u[maxn]; int main()
{
n = read();
q = read();
for(int i = ; i <= q; i++)
{
//pp[i].num = i;
int a,b;
a = read();
b = read();
pp[i].key = b;
pp[i].typ = a;
v.push_back(b);
}
sort(v.begin(),v.end());
v.erase(unique(v.begin(),v.end()),v.end());
int len = v.size(); //printf("len%d\n",len);
for(int i = ; i <= len; i++)
{
nxt[i] = i;
//printf("qwe%d\n",v[i - 1]);
} con[len - ] = ;
for(int i = ; i < len - ; i++)
{
if(v[i] + == v[i + ])
con[i + ] = ;
//printf("con%d\n",con[i]);
} /*for(int i = 1; i <= len; i++)
printf("%d %d\n",v[i - 1],con[i]);
printf("\n");*/ for(int i = ; i <= q; i++)
{
int key = getid(pp[i].key) + ;
//printf("key%d %d\n",pp[i].key,key);
if(pp[i].typ == )
{
if(con[key])
{
nxt[find(key)] = find(key + );
}
else
{
int temp = find(key);
//printf("qwe%d\n",find(key));
u[find(key)] = ;
//printf("qwe%d\n",find(key));
}
}
else
{
if(u[find(key)] == )
{
//printf("f%d\n",nxt[key]);
if(v[find(key) - ] + <= n)
//pp[i].ans = v[find(key)] + 1;
printf("%d\n",v[find(key) - ] + );
else
//pp[i].ans = -1;
printf("-1\n");
}
else
{
//printf("124252\n");
printf("%d\n",v[find(key) - ]);
}
}
} /*for(int i = 1; i <= q; i++)
if(pp[i].typ == 2)
{
printf("%d\n",pp[i].ans);
}*/
}

C. Buy Watermelon

  题意:将体积为w的西瓜切成两半,保证两半的重量均为偶数。

  思路:水题,题意含糊不清。

  AC code:

#include<cstdio>
#include<algorithm>
using namespace std; int w; int main(){
scanf("%d",&w);
if(w==||w%==) printf("NO\n");
else printf("YES\n");
return ;
}

D. Carnegion(kmp)

  题意:化简题意即判断是否为子串。

  思路:kmp查找子串,时间复杂度O(q*(S+T))。

  AC code:

#include<cstdio>
#include<algorithm>
#include<cstring>
#include<assert.h>
using namespace std; static int * GetNext(const char *sub)
{
int lensub = strlen(sub);
int *next = (int *)malloc(lensub*sizeof(int));
assert(next != NULL);
next[] = -;
next[] = ;
int j = ;
int k = ;
while(j+<lensub)
{
if((k==-) || (sub[k]==sub[j]))
next[++j] = ++k;
else
k = next[k];
}
return next;
} int KMP(const char *str,const char *sub,int pos)
{
assert(str!=NULL && sub!=NULL);
int lenstr = strlen(str);
int lensub = strlen(sub);
if(pos< || pos>=lenstr)
return -;
int *next = GetNext(sub);
int i = pos;
int j = ;
while(i<lenstr && j<lensub)
{
if(j==- || (str[i]==sub[j]))
i++,j++;
else
j = next[j];
}
free(next);
if(j >= lensub)
return i-j;
else
return -;
} const int maxn=1e5+;
int m,len1,len2;
char T[maxn],S[maxn]; int main(){
scanf("%s",T);
len1=strlen(T);
scanf("%d",&m);
while(m--){
scanf("%s",S);
len2=strlen(S);
if(len1>len2){
if(KMP(T,S,)>=) printf("my child!\n");
else printf("oh, child!\n");
}
else if(len1==len2){
if(strcmp(T,S)==) printf("jntm!\n");
else printf("friend!\n");
}
else{
if(KMP(S,T,)>=) printf("my teacher!\n");
else printf("senior!\n");
}
}
return ;
}

E. XKC‘s basketball(单调队列)

  题意:在长为5e5的数组中,对每一个a[i],求右边最后一个>=(a[i]+m)的下标。

  思路:lx写得。反向遍历,维护一个递增的队列,只进队不出队,如果当前a[i]<=que[end],那么不用进队,因为比a[i]大的数并且在i之后会屏蔽a[i]的作用; 当a[i]>que[end],则加入队尾。每次查询可以遍历得到que[begin]~que[end]中第一个>=a[i]+m的下标,当然也可以用二分加速。

  AC代码:

#include <iostream>
#include <cstdio>
#include <stack>
#include <map>
using namespace std; inline int read()
{
int x=,f=;
char ch = ;
while(!isdigit(ch))
{
if(ch=='-') f = -;
ch = getchar();
}
while(isdigit(ch))
{
x = x*+ch-'';
ch = getchar();
}
return x*f;
}
int n,m;
long long num[];
int ans[];
int dui[];
int ed;
int main()
{
n = read(), m = read();
for(int i=; i<=n; i++) num[i] = read();
for(int i=n; i>=; i--)
{
int you = ;
while(you<ed && num[i]+m>num[dui[you]]) you++;
if(you>=ed)
{
ans[i] = -;
if(num[i]>num[dui[ed-]])
{
dui[ed] = i;
ed++;
}
}
else
{
ans[i] = dui[you]-i-;
} }
for(int i=; i<=n; i++)
{
if(i>) putchar(' ');
printf("%d",ans[i]);
}
putchar('\n');
return ;
}

G. Colorful String(回文自动机)

  题意:求给定字串的所有回文子串的价值,字符串的价值定义为不同字符的个数。

  思路:回文自动机裸体。比赛现场学得回文自动机,用回文自动机求出所有种类的回文串的区间及其数量。然后用前缀记录计算得到所有回文子串的价值。

  AC code:

#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std; typedef long long LL;
const int maxn=3e5+;
char s[maxn],s1[maxn];
int n,p,q,fail[maxn],cnt[maxn],len[maxn],tot,last,ch[maxn][],l[maxn],r[maxn];
int pre[maxn][],leng;
LL ans; inline int newnode(int x){
len[++tot]=x;
return tot;
} inline int getfail(int x,int n){
while(s[n-len[x]-]!=s[n]) x=fail[x];
return x;
} int main(){
scanf("%s",s+);
leng=strlen(s+);
for(int i=;i<=leng;++i)
s1[i]=s[i];
s[]=-,fail[]=,last=;
len[]=,len[]=-,tot=;
for(int i=;s[i];++i){
s[i]-='a';
p=getfail(last,i);
if(!ch[p][s[i]]){
q=newnode(len[p]+);
l[q]=i-len[q]+,r[q]=i;
fail[q]=ch[getfail(fail[p],i)][s[i]];
ch[p][s[i]]=q;
}
++cnt[last=ch[p][s[i]]];
}
for(int i=tot;i;--i)
cnt[fail[i]]+=cnt[i];
for(int i=;i<=leng;++i){
for(int j=;j<;++j)
pre[i][j]=pre[i-][j];
++pre[i][s1[i]-'a'];
}
for(int i=tot;i;--i){
int tmp=;
for(int j=;j<;++j)
if(pre[r[i]][j]-pre[l[i]-][j]>) ++tmp;
ans+=1LL*tmp*cnt[i];
}
printf("%lld\n",ans);
return ;
}

K. Center(计算几何)

  题意:给n个点的点集,求最少加入多少个点使得所有点关于某个点成中心对称。

  思路:n^2枚举所有点对的中点,找到枚举次数最多的中心点,该点就是最合适的中心点,假设其出现次数为Max,该点为tmp,那么答案为(n-2*Max+mp1[tmp]),mp1用来记录原始点集中点的数量。为了方便处理,可以将初始点×2,这样中心点一定为整数点。

  AC code:

#include<cstdio>
#include<algorithm>
#include<cmath>
#include<cstdlib>
#include<map>
#include<utility>
using namespace std; typedef pair<int,int> PII;
const int maxn=;
int n,Max;
PII pt[maxn],tmp;
map<PII,int> mp1,mp2; int main(){
scanf("%d",&n);
for(int i=;i<=n;++i){
scanf("%d%d",&pt[i].first,&pt[i].second);
pt[i].first*=,pt[i].second*=;
++mp1[pt[i]];
}
for(int i=;i<=n;++i)
for(int j=i;j<=n;++j){
PII t=make_pair((pt[i].first+pt[j].first)/,(pt[i].second+pt[j].second)/);
++mp2[t];
if(mp2[t]>Max){
Max=mp2[t];
tmp=t;
}
else if(mp2[t]==Max){
if(mp1[t]<mp1[tmp])
tmp=t;
}
}
printf("%d\n",n-*Max+mp1[tmp]);
return ;
}

M. Longest subsequence(思维)

  题意:给定字符串s和t,求s中最长的子序列,且满足字典序大于t,输出子序列的长度,如果没有,输出-1。

  思路:比赛时没有思路。赛后补题。首先记录后缀,用aft[i][j]表示s[i]后面第一个j+’a‘的位置。然后对字符串t,枚举所求子序列从第j个字符开始大于t(前面j-1个字符与t保持一致)的情况,也就是找到pos右边第一个大于t[j]的下标x,从x开始全部选取,取答案最大值。注意子序列必须严格>t,前m个字符与t相同,之后再取后面的情况也可以。

  AC code:

#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std; const int maxn=1e6+;
const int inf=0x3f3f3f3f;
char s[maxn],t[maxn];
int n,m,ans,aft[maxn][],flag=; int main(){
scanf("%d%d",&n,&m);
scanf("%s%s",s+,t+);
for(int i=n-;i>=;--i){
for(int j=;j<;++j)
if(j==s[i+]-'a') aft[i][j]=i+;
else aft[i][j]=aft[i+][j];
}
int pos=;
for(int i=;i<=m;++i){
int tmp=t[i]-'a';
for(int j=tmp+;j<;++j)
if(aft[pos][j]) ans=max(ans,i+n-aft[pos][j]);
pos=aft[pos][tmp];
if(!pos){
flag=;
break;
}
}
if(flag&&pos!=n) ans=max(ans,m+n-pos);
if(!ans) printf("-1\n");
else printf("%d\n",ans);
return ;
}

2019icpc-徐州网络赛的更多相关文章

  1. 2019icpc徐州网络赛_I_query

    题意 给定一个序列,多次询问区间\([l,r]\)中满足\(min(a[i],a[j])==gcd(a[i],a[j])\)的数对\((i,j)\)数. 分析 其实就是求区间有倍数关系的数对数. 由于 ...

  2. 2019ICPC徐州网络赛 A.Who is better?——斐波那契博弈&&扩展中国剩余定理

    题意 有一堆石子,两个顶尖聪明的人玩游戏,先取者可以取走任意多个,但不能全取完,以后每人取的石子数不能超过上个人的两倍.石子的个数是通过模方程组给出的. 题目链接 分析 斐波那契博弈有结论:当且仅当石 ...

  3. 2019icpc徐州网络赛

    A Who is better? 题意 excrt+斐波那契博弈 分析 Java的BigInteger对象默认为null,不能直接比较. 代码 import java.math.BigInteger; ...

  4. 2018 ICPC 徐州网络赛

    2018 ICPC 徐州网络赛 A. Hard to prepare 题目描述:\(n\)个数围成一个环,每个数是\(0\)~\(2^k-1\),相邻两个数的同或值不为零,问方案数. solution ...

  5. 线段树+单调栈+前缀和--2019icpc南昌网络赛I

    线段树+单调栈+前缀和--2019icpc南昌网络赛I Alice has a magic array. She suggests that the value of a interval is eq ...

  6. 计蒜客 41391.query-二维偏序+树状数组(预处理出来满足情况的gcd) (The Preliminary Contest for ICPC Asia Xuzhou 2019 I.) 2019年徐州网络赛)

    query Given a permutation pp of length nn, you are asked to answer mm queries, each query can be rep ...

  7. 2019ICPC南京网络赛A题 The beautiful values of the palace(三维偏序)

    2019ICPC南京网络赛A题 The beautiful values of the palace https://nanti.jisuanke.com/t/41298 Here is a squa ...

  8. ICPC 2019 徐州网络赛

    ICPC 2019 徐州网络赛 比赛时间:2019.9.7 比赛链接:The Preliminary Contest for ICPC Asia Xuzhou 2019 赛后的经验总结 // 比赛完才 ...

  9. [徐州网络赛]Longest subsequence

    [徐州网络赛]Longest subsequence 可以分成两个部分,前面相同,然后下一个字符比对应位置上的大. 枚举这个位置 用序列自动机进行s字符串的下标转移 注意最后一个字符 #include ...

  10. 徐州网络赛B-BE,GE or NE【记忆化搜索】【博弈论】

    In a world where ordinary people cannot reach, a boy named "Koutarou" and a girl named &qu ...

随机推荐

  1. PHP mysqli_commit() 函数

    关闭自动提交,做一些查询,然后提交查询: <?php // 假定数据库用户名:root,密码:123456,数据库:RUNOOB $con=mysqli_connect("localh ...

  2. vue 内容增加滚动条自动定位至底部

    this.$nextTick(() => { document.body.scrollTop = document.body.scrollHeight; console.log(document ...

  3. 在Android中使用OpenGL ES进行开发第(一)节:概念先行

    一.前期基础是知识储备笔者计划写三篇文章来详细分析OpenGL ES基础的同时也是入门关键的三个点: ①OpenGL ES是什么?与OpenGL的关系是什么?——概念部分 ②使用OpenGL ES绘制 ...

  4. 在centos7上使用packstack安装openstack

    简介 Packstack主要是由Redhat推出的用于概念验证(PoC)环境快速部署的工具.Packstack是一个命令行工具,它使用Python封装了Puppet模块,通过SSH在服务器上部署Ope ...

  5. 2019.7.9 校内测试 T2 极值问题

    这一次是交流测试?边交流边测试(滑稽 极值问题 乍一看这是一道数学题,因为1e9的数据让我暴力的心退却. 数学又不好,不会化简式子嘞,咋办? 不怕,咱会打表找规律.(考场上真的是打表找出了规律,打表打 ...

  6. 数据分析之numpy使用

    使用numpy生成数字 生成的类型是ndarray类型 t1 = np.array([1,2,3,4,5]) print(t1,type(t1)) # 类型为ndarray t2 = np.array ...

  7. Ubuntu14.04 dd命令克隆系统镜像安装到另一台机器上

    linux系统如果想做备份还原,使用ghost的时候经常出现问题,后来发现可以直接使用dd命令完成硬盘的克隆和还原.当拷贝完硬盘后,就可以拿这个硬盘放到其它设备上跑了.也就是完成了“烧写”了. 用U盘 ...

  8. ie和vuex的兼容

    vuex requires a Promise polyfill in this browser. 在ie中的报错 需要安卓babel-polyfill,  然后在webpack.base.confi ...

  9. overflow妙用--去除默认滚动条,内容仍可滚动

    在开发中我们往往要去除默认滚动条,但是其在竖直方向的滚动效果仍然需要. <div id="parent"> <div id="child"&g ...

  10. 动态规划——区间DP,计数类DP,数位统计DP

    本博客部分内容参考:<算法竞赛进阶指南> 一.区间DP 划重点: 以前所学过的线性DP一般从初始状态开始,沿着阶段的扩张向某个方向递推,直至计算出目标状态. 区间DP也属于线性DP的一种, ...