【CodeChef - TANGLED】【Entangled Strings】后缀数组+并查集

该博客详细介绍了如何解决CodeChef上的TANGLED问题,即计算字符串AB中相同子串的对数。通过分析长度为K的相同子串,博主提出利用带权并查集来统计,并说明如何在找到第k+1个字符相同时,将结果合并,从而实现后缀数组的功能。
摘要由CSDN通过智能技术生成

题目链接

题目要求AB串相同子串的对数

我们可以知道对于长度为K的相同子串可以分为两个部分

  1. 第k+1个字符不相同的部分,我们可以用带权并查集合并实现统计。
  2. 第k+1个字符相同的部分,直接由k+1长度的结果合并过来。就是在一操作后实现一个后缀和。
#include<algorithm>
#include<vector>
#include<iostream>
#include<math.h>
#include<cstring>
#include<string>
#include<stack>
#define qcin; ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define pb push_back
using namespace std;

typedef long long ll;

typedef pair<ll,ll>pll;

const int maxn = 400100;

typedef int arr[maxn];

void file(int x){if(x&&fopen("in.txt","r")){freopen("in.txt","r",stdin);}}


struct ST{
    int mm[maxn],dp[maxn][22],k,sz;
    //const int&(*fun[2])(const int&,const int&)={max,min};
    void init(int n,int b[],int fl){
        mm[0]=-1;
   
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值