题目链接 本来准备自己yy一个倍增来着,然而一看要求O1查询就怂了. ST表模板.放上代码. #include<cstdio> #include<cstdlib> #include<cctype> #include<cmath> inline long long max(long long a,long long b){ return a>b?a:b; } inline long long read(){ ,f=; char ch=getchar();…
Problem Description 在每年的校赛里,全部进入决赛的同学都会获得一件非常美丽的t-shirt.可是每当我们的工作人员把上百件的衣服从商店运回到赛场的时候,却是非常累的!所以如今他们想要寻找最短的从商店到赛场的路线,你能够帮助他们吗? Input 输入包含多组数据.每组数据第一行是两个整数N.M(N<=100,M<=10000),N表示成都的大街上有几个路口,标号为1的路口是商店所在地,标号为N的路口是赛场所在地,M则表示在成都有几条路.N=M=0表示输入结束.接下来M行,…
Description The little cat is so famous, that many couples tramp over hill and dale to Byteland, and asked the little cat to give names to their newly-born babies. They seek the name, and at the same time seek the fame. In order to escape from such b…
Problem I. Count Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 524288/524288 K (Java/Others)Total Submission(s): 42 Accepted Submission(s): 16 Problem Description Multiple query, for each n, you need to getn i-1∑ ∑ [gcd(i + j, i - j) = 1…
题意:给你一组数,询问\(q\)次,问所给区间内的最大值和最小值的差. 题解:经典RMQ问题,用st表维护两个数组分别记录最大值和最小值然后直接查询输出就好了 代码: int n,q; int a[N]; int dp1[N][30],dp2[N][30]; int lg[N]; void lg_Init(){ for(int i=1;i<=n;++i){ int k=0; while(1<<(k+1)<=i) k++; lg[i]=k; } } void RMQ_Init1(){…
kmp: const int maxn=1e5+5; char s[maxn],p[maxn]; int nex[maxn]; int KmpSearch(char* s, char* p) { int i = 0; int j = 0; int sLen = strlen(s); int pLen = strlen(p); while (i < sLen && j < pLen) { //①如果j = -1,或者当前字符匹配成功(即S[i] == P[j]),都令i++,j+…