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. 快速了解AMD、CMD、CommonJS、ESM

    1.ES6 Module javascript在ES2015(ES6)中出现了语言层面的模块(module). ES6的模块既可以用于浏览器端,也可以用于服务器端(nodeJS). ES6模块是静态化 ...

  2. word黏贴图片显示不出来

    word图片转存,是指UEditor为了解决用户从word中复制了一篇图文混排的文章粘贴到编辑器之后,word文章中的图片数据无法显示在编辑器中,也无法提交到服务器上的问题而开发的一个操作简便的图片转 ...

  3. Codeforces 1221 E Game With String

    题面 第一眼以为是SG函数找规律题,然后发现并不是公平游戏.... 不过后来想了想,其实这样反而更好做. 这个游戏的一个显然的特性是,任何时候当场上存在长度 ∈[b,a)的块时,Bob必胜.(考虑贪心 ...

  4. Grafana +Zabbix 系列二

    Grafana +Zabbix 系列二 Grafana 简介补充 Grafana自身并不存储数据,数据从其他地方获取.需要配置数据源 Grafana支持从Zabbix中获取数据 Grafana优化图形 ...

  5. create-react-app 构建的项目使用代理 proxy

    1. 正常运行 npm run eject (前三个步骤可省略,最好的是按照第四步操作) 2. create-react-app 的版本在低于 2.0 的时候可以在 package.json 增加 p ...

  6. [python]字典的直接赋值、浅拷贝和深拷贝解析

    1.赋值引用 b = a: a 和 b 都指向同一个对象. 2.浅拷贝 b = a.copy():  a 和 b父对象是一个独立的对象,但他们的子对象还是指向统一对象(是引用). 3.深拷贝 b = ...

  7. JAVA基础知识|Socket

    一.什么是Socket? Socket本身并不是协议,是一套完成TCP.UDP协议的调用接口(API),通过socket我们才能使用TCP/IP协议(JAVA基础知识|TCP/IP协议).Socket ...

  8. 一个数据库操作类,适用于Oracle,ACCESS,SQLSERVER

    最近做了一个数据诊断的项目,里面自己写了一个数据库的操作类,包含:连接数据库.读数据表.执行SQL操作,释放数据库等组成,希望对大家有用,由于水平有限,若有错误或者代码不足地方欢迎指正,谢谢. ADO ...

  9. 获得数据源和路径desc.catalogPath

    workspace:C:\Users\dell\Documents\ArcGIS\Default.gdb\ddf inPath:c:\users\dell\documents\arcgis\defau ...

  10. Oracle常用操作表结构的语句

    首先,一起来认识几个单词. alter (改变) rename(重命名) column(柱子,用来表示列) modify(修改) comment on (评论) truncate (删减,截断) 1. ...