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. 【luogu1325】雷达安装--贪心

    题目描述 描述: 假设海岸线是一条无限延伸的直线.它的一侧是陆地,另一侧是海洋.每一座小岛是在海面上的一个点.雷达必须安装在陆地上(包括海岸线),并且每个雷达都有相同的扫描范围d.你的任务是建立尽量少 ...

  2. cyk追楠神系列一(SDUT3703)

    cyk追楠神系列一 Time Limit: 1000 ms Memory Limit: 65536 KiB Submit Statistic Problem Description 众所周知,cyk ...

  3. 北大ACM - POJ试题分类(转自EXP)

    北大ACM - POJ试题分类 -- By EXP 2017-12-03 转载请注明出处: by EXP http://exp-blog.com/2018/06/28/pid-38/ 相关推荐文: 旧 ...

  4. 简记乘法逆元(费马小定理+扩展Euclid)

    乘法逆元 什么是乘法逆元? 若整数 \(b,m\) 互质,并且\(b|a\) ,则存在一个整数\(x\) ,使得 \(\frac{a}{b}\equiv ax\mod m\) . 称\(x\) 是\( ...

  5. call()与构造函数的运用

    一.简介 call()和apply()方法是所有函数体的固有属性,可以在指定作用域下调用函数.这里面有两层意思:1.可以在另外的作用域下调用函数:2.当函数体是是构造函数时,call()方法能达到类之 ...

  6. 下板不动, 上板匀速平板间流动(Crank-Nicolson格式)【转载】

    摘自<FLUENT流体工程仿真计算实例与分析>,程序略有修改 两个间距为1cm水平平板,如下图所示: 上板匀速平板间流动(Crank-Nicolson格式)[转载]"> 充 ...

  7. 基于docker的sqli-labs搭建

    一键代码: curl https://files-cdn.cnblogs.com/files/kagari/sqli-labs.sh|bash https://files-cdn.cnblogs.co ...

  8. 删除顺序表L中下标为p(0<=p<=length-1)的元素,成功返回1,不成功返回0,并将删除元素的值赋给e

    原创:转载请注明出处. [天勤2-2]删除顺序表L中下标为p(0<=p<=length-1)的元素,成功返回1,不成功返回0,并将删除元素的值赋给e 代码: //删除顺序表L中下标为p(0 ...

  9. SOA(面向服务的架构)初识

    SOA是一种设计方法,其中包含多个服务,而服务之间通过配合最终会提供一系列功能.一个服务通常以独立的方式存在于操作系统中.服务之间通过网络调用(常见有http+xml.http+json等),而非进程 ...

  10. vue devtools无法使用

    vue devtools无法使用 一.总结 一句话总结: 没显示vue devtools调试工具的原因是用了生产环境的版本或是压缩的vue版本,或是没有勾选:允许访问文件网址 二.vue调试工具Dev ...