题目链接:http://codeforces.com/contest/779/problem/D

题意:给你一段操作序列,按顺序依次删掉字符串1中相应位置的字符,问你最多能按顺序删掉多少个字符,使得s2是剩下的字符构成的字符串的子列。

字符串长度为2e5每次查询的时间复杂度为n如果直接暴力那么复杂度就是n*n

如果二分一下答案的话复杂度就是n*logn再加上修改的复杂度总的复杂度是

(n+n)* logn

#include <iostream>
#include <cstring>
#include <string>
using namespace std;
const int M = 2e5 + 10;
string p , t;
int a[M] , l , r , mid;
bool vis[M];
bool find(int pos) {
int len = t.size() , len2 = p.size();
int count = 0;
for(int i = 0 ; i < len ; i++) {
if(i <= mid) {
vis[a[i] - 1] = false;
}
else {
vis[a[i] - 1] = true;
}
}
for(int i = 0 ; i < len ; i++) {
if(vis[i]) {
if(t[i] == p[count]) {
count++;
}
}
if(count == len2)
return true;
}
return false;
}
int main() {
cin >> t >> p;
int len = t.size();
for(int i = 0 ; i < len ; i++) {
cin >> a[i];
vis[i] = true;
}
l = 0 , r = len - 1;
while(l <= r) {
mid = (l + r) >> 1;
int flag = find(mid);
if(flag) {
l = mid + 1;
}
else {
r = mid - 1;
}
}
cout << r + 1 << endl;
return 0;
}

codeforces 779 D. String Game(二分)的更多相关文章

  1. Codeforces 799D. String Game 二分

    D. String Game time limit per test:2 seconds memory limit per test:512 megabytes input:standard inpu ...

  2. codeforces D. Mahmoud and Ehab and the binary string(二分)

    题目链接:http://codeforces.com/contest/862/submission/30696399 题解:这题一看操作数就知道是二分答案了.然后就是怎么个二分法,有两种思路第一种是找 ...

  3. Codeforces Round #402 D String Game(二分)

    [题目类型]二分答案 &题解: 只要你想到二分答案就不是难题了,但我当时确实是想不到. [时间复杂度]\(O(nlogn)\) &代码: #include <cstdio> ...

  4. Codeforces 778A:String Game(二分暴力)

    http://codeforces.com/problemset/problem/778/A 题意:给出字符串s和字符串p,还有n个位置,每一个位置代表删除s串中的第i个字符,问最多可以删除多少个字符 ...

  5. Codeforces 862D. Mahmoud and Ehab and the binary string 【二分】(交互)

    <题目链接> 题目大意: 有一个长度为n(n<1000)的01串,该串中至少有一个0和一个1,现在由你构造出一些01串,进行询问,然后系统会给出你构造的串与原串的   Hamming ...

  6. Codeforces.862D.Mahmoud and Ehab and the binary string(交互 二分)

    题目链接 \(Description\) 有一个长为\(n\)的二进制串,保证\(01\)都存在.你可以询问不超过\(15\)次,每次询问你给出一个长为\(n\)的二进制串,交互库会返回你的串和目标串 ...

  7. Codeforces 825D Suitable Replacement - 贪心 - 二分答案

    You are given two strings s and t consisting of small Latin letters, string s can also contain '?' c ...

  8. Codeforces 672D Robin Hood(二分好题)

    D. Robin Hood time limit per test 1 second memory limit per test 256 megabytes input standard input ...

  9. Codeforces 645C Enduring Exodus【二分】

    题目链接: http://codeforces.com/contest/645/problem/C 题意: 给定01串,将k头牛和农夫放进, 0表示可以放进,1表示不可放进,求农夫距离其牛的最大距离的 ...

随机推荐

  1. solr 新建core

    D:\tomcat\webapps\solr\solr_home 在该路径下创建一个新的core,所需文件和层级如下 test_core |-- conf |-- schema.xml |-- sol ...

  2. 神奇的 SQL 之子查询,细节满满 !

    前言 开心一刻 有一天,麻雀遇见一只乌鸦. 麻雀问:你是啥子鸟哟 ? 乌鸦说:我是凤凰. 麻雀说:哪有你龟儿子这么黢黑的凤凰 ? 乌鸦说:你懂个铲铲,老子是烧锅炉的凤凰. 子查询 讲子查询之前,我们先 ...

  3. [NUnit]No results

    Results (nunit3) saved as TestResult.xmlCommitting...No results, this could be for a number of reaso ...

  4. Go中的文件读写

    在 Go 语言中,文件使用指向 os.File 类型的指针来表示的,也叫做文件句柄 .我们来看一下os包的使用方式. 1.读取文件 os包提供了两种打开文件的方法: Open(name string) ...

  5. RE最全面的正则表达式----终结篇 特殊处理

    三.特殊需求表达式 Email地址:^w+([-+.]w+)*@w+([-.]w+)*.w+([-.]w+)*$域名:[a-zA-Z0-9][-a-zA-Z0-9]{0,62}(/.[a-zA-Z0- ...

  6. (三)c#Winform自定义控件-有图标的按钮

    前提 入行已经7,8年了,一直想做一套漂亮点的自定义控件,于是就有了本系列文章. 开源地址:https://gitee.com/kwwwvagaa/net_winform_custom_control ...

  7. python(自用手册)导图

  8. mysql根据逗号将一行数据拆分成多行数据

    mysql根据逗号将一行数据拆分成多行数据 原始数据 处理结果展示 DDL CREATE TABLE `company` ( `id` ) DEFAULT NULL, `name` ) DEFAULT ...

  9. Python模块之pysnooper

    一.简介 调试程序时,很多人喜欢直接用print来代替断点调试,而pysnooper模块比print更方便,以装饰器的形式存在 二.实验环境 操作系统:win10 python版本:python3.6 ...

  10. spring-boot-plus项目打包(七)

    spring-boot-plus项目打包 项目打包 spring-boot-plus项目使用maven assembly插件进行打包 根据不同环境进行打包部署 包含启动.重启命令,配置文件提取到外部c ...