Smiling & Weeping

                  ----第一次见你的时候,

                    在我的心里已经炸成了烟花,

                    需要用一生来打扫灰炉。

题目链接:Problem - C - Codeforces

题目大意不难,就是把每种情况枚举,但是记录每种String需要想办法,简单的set<string>会MLE不可行,unordered_set<string>也不行,这就需要我吗使用类似于hashcode一般,用pair<int,int>的形式来记录每种不同的情况,题目解析在代码里:

 1 #include<bits/stdc++.h>
2 using namespace std;
3 int t , n , m;
4 int main()
5 {
6 scanf("%d",&t);
7 while(t--)
8 {
9 scanf("%d%d",&n,&m);
10 vector<int> lf(n+10) , rg(n+10);
11 string s;
12 cin >> s;
13 lf[0] = -1; //当s[0]=='1'的时候赋值-1,s[0]=='0'的时候赋值0,便于区分
14 for(int i = 0; i < n; i++)
15 {
16 if(i > 0) lf[i] = lf[i-1];
17 if(s[i] == '0') lf[i] = i;
18 }
19 rg[n-1] = n; //当s[n-1]=='1'时赋值n-1,s[n-1]=='0'的时候赋值n
20 for(int i = n-1; i >= 0; i--)
21 {
22 if(i < n-1) rg[i] = rg[i+1];
23 if(s[i] == '1') rg[i] = i;
24 }
25 // 如果不区分,这是两种不同的情况,比如:01101001011 , 11101001010就无法区分rg出现错误,lf[0]根本没区别
26 // 如果使用set<string> p必会MLE,ε=(´ο`*)))唉,数据结构好用,但是占用空间太大了
27 set<pair<int , int> > p;
28 while(m--)
29 {
30 int a , b;
31 scanf("%d%d",&a,&b);
32 if(a > b) swap(a,b); //不要问我从哪里得到的教训[○・`Д´・ ○]
33 int ll = rg[a-1] , rr = lf[b-1]; // 计算左端点标记1的历史索引,再求右端点0的历史索引
34 if(ll > rr)
35 {
36 p.insert(make_pair(-1,-1));
37 }
38 else
39 p.insert(make_pair(ll , rr));
40 }
41 cout << p.size() << endl;
42 }
43 return 0;
44 }

文章到此结束,我们下次再见,ヾ( ̄▽ ̄)Bye~Bye~

Binary String Copying的更多相关文章

  1. Binary String Matching

    问题 B: Binary String Matching 时间限制: 3 Sec  内存限制: 128 MB提交: 4  解决: 2[提交][状态][讨论版] 题目描述 Given two strin ...

  2. NYOJ之Binary String Matching

    Binary String Matching 时间限制:3000 ms  |  内存限制:65535 KB 难度:3 描述     Given two strings A and B, whose a ...

  3. ACM Binary String Matching

    Binary String Matching 时间限制:3000 ms  |  内存限制:65535 KB 难度:3   描述 Given two strings A and B, whose alp ...

  4. Binary String Matching(kmp+str)

    Binary String Matching 时间限制:3000 ms  |  内存限制:65535 KB 难度:3   描述 Given two strings A and B, whose alp ...

  5. encode_json 会对给定的Perl的数据结构转换为一个UTF-8 encoded, binary string.

    use JSON qw/encode_json decode_json/ ; use Encode; my $data = [ { 'name' => 'Ken' , 'age' => 1 ...

  6. perl encode_json 会产生 UTF-8 (binary) string decode_json 需要一个 UTF-8 (binary) string

    encode_json $json_text = encode_json $perl_scalar Converts the given Perl data structure to a UTF-8 ...

  7. NYOJ 5 Binary String Matching

    Binary String Matching 时间限制:3000 ms  |  内存限制:65535 KB 难度:3   描述 Given two strings A and B, whose alp ...

  8. [LeetCode] Special Binary String 特殊的二进制字符串

    Special binary strings are binary strings with the following two properties: The number of 0's is eq ...

  9. [Swift]LeetCode761. 特殊的二进制序列 | Special Binary String

    Special binary strings are binary strings with the following two properties: The number of 0's is eq ...

  10. [Swift]LeetCode1016. 子串能表示从 1 到 N 数字的二进制串 | Binary String With Substrings Representing 1 To N

    Given a binary string S (a string consisting only of '0' and '1's) and a positive integer N, return ...

随机推荐

  1. JS加载机制

    做开发多年后发现自己思维任然只定位在功能的实现:忽略了很多代码最终的实现,加载机制等 那我们接下来就借助几篇博客来理理天天看见的js:理理他究竟是怎么过执行的 一.代码检测 首先浏览器会对所有js 进 ...

  2. Doris(一) -- 简介和安装

    Doris 简介 Doris 概述 Apache Doris 由百度大数据部研发 (之前叫百度 Palo,2018 年贡献到 Apache 社区后,更名为 Doris), 在百度内部,有超过 200 ...

  3. Ubuntu22.04 安装单机版kubernetes

    前言 上期讲到要实现.net 6框架下的EF Core操作数据库基本增删改查,没有及时兑现.没有兑现的原因就是因为安装kubernetes.安装kubernetes的过程是灾难性的,也是十分顺利的.灾 ...

  4. Java实现猜拳小游戏

    Java实现猜拳游戏的核心在于电脑随机数的生成,Java中的随机数生成方法是:首先引入包   import java.util.*;  然后   int r=new Random().nextInt( ...

  5. Linux下程序时间消耗监控与统计

    良好的计时器可帮助程序开发人员确定程序的性能瓶颈,或对不同算法进行性能比较.但要精确测量程序的运行时间并不容易,因为进程切换.中断.共享的多用户.网络流量.高速缓存访问及转移预测等因素都会对程序计时产 ...

  6. 面试官问:kafka为什么如此之快?

    前言 天下武功,唯快不破.同样的,kafka在消息队列领域,也是非常快的,这里的块指的是kafka在单位时间搬运的数据量大小,也就是吞吐量,下图是搬运网上的一个性能测试结果,在同步发送场景下,单机Ka ...

  7. NameError: name 'List' is not defined

    当在python出现该问题是,使用from typing import List.

  8. Prometheus-2:blackbox_exporter黑盒监控

    黑盒监控blackbox_exporter 前边介绍有很多exporter可以直接将metrics暴露给Prometheus进行监控,这些称为"白盒监控",那些exporter无法 ...

  9. go web学习(五)

    跟着刘旭老师学go web做的笔记 [Go Web 编程快速入门[Golang/Go语言](完结)] https://www.bilibili.com/video/BV1Xv411k7Xn/?p=27 ...

  10. Windows下打开指定目录并定位到具体文件

    一.在Windows上,网上流传的几种方法可以打开目录并定位到指定文件: 1.使用系统调用: 使用system()函数执行操作系统的命令行命令. 在命令行命令中,使用explorer /select, ...