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. P2461 [SDOI2008]递归数列 矩阵乘法+构造

    还好$QwQ$ 思路:矩阵快速幂 提交:1次 题解: 如图: 注意$n,m$如果小于$k$就不要快速幂了,直接算就行... #include<cstdio> #include<ios ...

  2. Mysql建表+创建索引

    创建表时可以直接创建索引,这种方式最简单.方便.其基本形式如下: CREATE TABLE 表名( 属性名 数据类型[完整性约束条件], 属性名 数据类型[完整性约束条件], ...... 属性名 数 ...

  3. parents()和parent()

    $("").parent().parent()  //父元素的父元素 $("").parents("tr")  // 祖先元素 找到tr

  4. trie树的应用;

    链接:https://ac.nowcoder.com/acm/contest/920/B来源:牛客网 定义一张图的生成链是原图的一棵生成树,且这棵树退化成一条链.我们称一条生成链是原图的最小生成链,当 ...

  5. 图论——最小生成树:Prim算法及优化、Kruskal算法,及时间复杂度比较

    最小生成树: 一个有 n 个结点的连通图的生成树是原图的极小连通子图,且包含原图中的所有 n 个结点,并且有保持图连通的最少的边.简单来说就是有且仅有n个点n-1条边的连通图. 而最小生成树就是最小权 ...

  6. Nginx中配置非英文域名

    前两天遇到个配置越南语的域名的情况.域名和ip解析完成后,直接ping域名也不通,还以为是解析问题.研究了半天,nginx配置非英文域名时,需要有其他操作. 非英文域名转换成punycode编码才可以 ...

  7. 单词拼接(dfs/回溯/递归)

    单词拼接传送门 //单词拼接 #include<stdio.h> #include<string.h> #include<algorithm> using name ...

  8. 课下选做作业MyOD

    2019-2020-1 20175227 <信息安全系统设计基础> 课下选做作业MyOD 要求 复习c文件处理内容 编写myod.c 用myod XXX实现Linux下od -tx -tc ...

  9. python 数字转字符保留几位小数 by gisoracle

    #数字转字符保留几位小数 by gisoracle #数字转字符保留几位小数 by gisoracle def floattostr(num,xsnum): if xsnum==0: return s ...

  10. 图像模糊C均值聚类分割代码

    转自:直觉模糊C均值聚类与图像阈值分割 - liyuefeilong的专栏 - CSDN博客 https://blog.csdn.net/liyuefeilong/article/details/43 ...