2022.10.3 闲话

是不是因为没推流所以我昨天的模拟赛题解只有 1 阅读量 .

密码就是比赛密码啊,也就是 x****i20*2 .


本来今天是没有闲话的 .

放一下以前 JC 用的工程:<streamer> .

Eafoo 也写过,我写了一个类似的 .

<streamer>

2022/6/21 最新修订版

给您最舒心的 cin/cout .

注意:必须在 <iostream> 前引入(或者不引入也行,<streamer> 会帮你引入的)

// Standard streamer objects -*- C++ -*-
// Copyright (C) 1997-2019 Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library.  This library is free
// software; you can redistribute it and/or modify it under the
// terms of the GNU General Public License as published by the
// Free Software Foundation; either version 3, or (at your option)
// any later version.

// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.

// Under Section 7 of GPL version 3, you are granted additional
// permissions described in the GCC Runtime Library Exception, version
// 3.1, as published by the Free Software Foundation.

// You should have received a copy of the GNU General Public License and
// a copy of the GCC Runtime Library Exception along with this program;
// see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
// <http://www.gnu.org/licenses/>.

/** @file include/streamer
 *  This is a Standard C++ Library header.
 */

//
// ISO C++ 14882: 27.3  Standard iostream objects
//

#ifndef _GLIBCXX_STREAMER
#define _GLIBCXX_STREAMER 1

#pragma GCC system_header

#ifdef _GLIBCXX_IOSTREAM 
# error You must not include <iostream> before <streamer> 
#endif

#if __cplusplus < 201103L
# include <bits/c++0x_warning.h>
#endif

#undef buffer
#undef moving_copy

#include <iostream>
#include <random>
#include <chrono>
#include <_mingw.h>

#define _GLIBCXX_INPUT_FLOWER_ cin
#define _GLIBCXX_OUTPUT_FLOWER_ cout

#ifdef _GLIBCXX_DEBUG
# warning STREAMER is not suitable for DEBUG MODE
#endif

#ifdef _GLIBCXX_PROFILE
# warning STREAMER is not suitable for PROFILE MODE
#endif

namespace std _GLIBCXX_VISIBILITY(default)
{
_GLIBCXX_BEGIN_NAMESPACE_VERSION
#define buffer_flusher mt19937
#define moving_copy uniform_int_distribution 
	namespace __basic_stream
	{
		using namespace std;
		buffer_flusher location(std::chrono::system_clock::now().time_since_epoch().count());
		class buffer
		{
		public:
			inline size_t find()
			{
				auto get_stack = moving_copy<size_t>(0, 32767), get_stack_seven = moving_copy<size_t>(0, 7);
				return (get_stack_seven(location) < 2) ? get_stack(location) : 0;
			}
			buffer()  = default;
			~buffer() = default;
		private:
		};
		class basic_stream
		{
		public:
		 	template <typename T>
		 	basic_stream& operator << (const T x){_GLIBCXX_OUTPUT_FLOWER_ << x; return *this;}
		 	template <typename T>
		 	basic_stream& operator >> (T& x){_GLIBCXX_INPUT_FLOWER_ >> x; return *this;}
		 	basic_stream()  = default;
		 	~basic_stream() = default;
		};
	}
#define endl "\n" 
#define std::endl "\n" 
	class istream_override : public __basic_stream :: basic_stream{}standard_cin; 
	class ostream_override : public __basic_stream :: basic_stream
	{
	public:
		template <typename T>
		ostream_override& operator << (const T x)
		{
			if (__basic_stream :: buffer().find() > 16384) _GLIBCXX_OUTPUT_FLOWER_ << "-";
			_GLIBCXX_OUTPUT_FLOWER_ << x; 
			if (32768 - __basic_stream :: buffer().find() < 64){abort(); throw "streamer throws error XD";}
			return *this;
		}
		ostream_override& operator << (const int x){_GLIBCXX_OUTPUT_FLOWER_ << (x ^ __basic_stream :: buffer().find()); return *this;}
	}standard_cout; 
#undef buffer_flusher
#undef moving_copy
_GLIBCXX_END_NAMESPACE_VERSION
} // namespace std

#if __cplusplus >= 201703L

inline void abort_streamer(){abort();}

#if __cplusplus > 201703L

#warning [TODO] do not use C++20 streamer

#endif // C++20

#endif // C++11

namespace std _GLIBCXX_VISIBILITY(default)
{
_GLIBCXX_BEGIN_NAMESPACE_VERSION
	
_GLIBCXX_END_NAMESPACE_VERSION
} // namespace std

#define cin standard_cin
#define cout standard_cout

#endif /* _GLIBCXX_STREAMER */

Appendix

为了避免这篇鲜花太无聊,放个水题:


近日,园长发现动物园中好吃懒做的动物越来越多了 . 例如企鹅,只会卖萌向游客要吃的 . 为了整治动物园的不良风气,让动物们凭自己的真才实学向游客要吃的,园长决定开设算法班,让动物们学习算法 .

某天,园长给动物们讲解 KMP 算法 .

\(\mathbf{园长}\):对于一个字符串 \(S\),它的长度为 \(L\) . 我们可以在 \(O(L)\) 的时间内,求出一个名为 next 的数组。有谁预习了 next 数组的含义吗?

\(\mathbf{熊猫}\):对于字符串 \(S\) 的前 \(i\) 个字符构成的子串,既是它的后缀又是它的前缀的字符串中(它本身除外),最长的长度记作 \(next_i\) .

园长表扬了认真预习的熊猫同学 . 随后,他详细讲解了如何在 \(O(L)\) 的时间内求出 next 数组 .

\(\mathbf{园长}\):KMP 算法只能求出 next 数组。我现在希望求出一个更强大 num 数组 一 对于字符串 \(S\) 的前 \(i\) 个字符构成的子串,既是它的后缀同时又是它的前缀,并且该后缀与该前缀不重叠,将这种字符串的数量记作 \(num_i\) .

最后,园长给出了奖励条件,第一个做对的同学奖励巧克力一盒。听了这句话,睡了一节课的企鹅立刻就醒过来了!

然而企鹅学过打过 NOI2014,于是秒掉了它 .
\(\mathbf{企鹅}\):这不是 sb 题吗,考虑构建 Border 树,balabala ...

\(\mathbf{园长}\):……虽然你答对了,但是你不能拿到巧克力!因为你没有预习!你需要解决加强版 — 求对于字符串 \(S\) 的前 \(i\) 个字符构成的子串,既是它的后缀同时又是它的前缀,并且该后缀与该前缀不重叠的字符串长度平方和!!

\(\mathbf{熊猫}\):这题我会!只需要拉格朗日插值即可!

\(\mathbf{园长}\):熊猫同学解决了这题,那么让我们给熊猫同学发巧克……

\(\mathbf{企鹅}\):等会!我会子串查询这玩意!

\(\mathbf{园长}\):???

这下是园长不会做了,因为园长没有打过 NOI2014,所以请打过 NOI2014 的你来做这道题 .


形式化题意:

给定一个字符串 \(S\) . 对于所有满足如下条件的 \(T\)

  • 既是 \(S\) 的前缀又是 \(S\) 的后缀 .
  • \(2|T|\le|S|\) .

\(Q\) 组询问,对于 \(S\) 的一个子串 \(S[l:r]\),求满足条件的 \(T\) 的长度平方和 .

posted @ 2022-10-03 17:53  Jijidawang  阅读(92)  评论(5编辑  收藏  举报
😅​