N - String
Time Limit:1000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u
Submit Status
Description
There is a string S.S only contain lower case English character.(10 \leq length(S) \leq 1,000,000)
How many substrings there are that contain at least k(1 \leq k \leq 26) distinct characters?
Input
There are multiple test cases. The first line of input contains an integer T (1\leq T\leq 10) indicating the number of test cases. For each test case:
The first line contains string S.
The second line contains a integer k(1 \leq k \leq 26).
Output
For each test case, output the number of substrings that contain at least k dictinct characters.
Sample Input
2
abcabcabca
4
abcabcabcabc
3
Sample Output
0
55
4、.每次low移动都在ans+=len-top
#include<iostream> #include<cstdio> #include<string> #include<cstring> #include<cmath> #include<algorithm> #include<cctype> #include <fstream> #include <limits> #include <vector> #include <list> #include <set> #include <map> #include <queue> #include <stack> #include <cassert> using namespace std; bool v[20100]; int n,m; struct node { int x,y,f,t; friend bool operator < (node b,node c) { if(b.f!=c.f) return b.f>c.f; return b.t>c.t; } } a[200100]; int bfs(); int main() { int ci; scanf("%d",&ci); while(ci--) { scanf("%d%d",&n,&m); m=m<<1; for(int i=0; i<m; i++) { int x,y,t,f; scanf("%d%d%d%d",&x,&y,&t,&f); a[i].x=x,a[i].y=y,a[i].f=f,a[i].t=t; i++; a[i].x=y,a[i].y=x,a[i].f=f,a[i].t=t; } bfs(); } return 0; } //int dfs(int x) //{ // for(i=0;i<m;i++) // if(a[i].x==x) // //} int bfs() { priority_queue<node>pqu; node b,c; b.x=0,b.f=0,b.t=0; pqu.push(b); while(!pqu.empty()) { b=pqu.top(); pqu.pop(); int x=b.x,y,f=b.f,t=b.t; if(v[x]) continue; v[x]=1; n--; if(!n) break; for(int i=0; i<m; i++) //超限用vector优化 { if(a[i].x==x) y=a[i].y; if(v[y]) continue; b.x=y,b.f=a[i].f+f; b.t=a[i].t+t; pqu.push(b); } } printf("%d %d\n",b.f,b.t); return 0; }