跳到正文

休闲·娱乐

火车头

违规用户名1764483约 24 分钟
原文
文章信息与版本

文章信息

发布
2026年9月6日
收录
2026年9月12日
更新
2026年9月27日
篇幅
约 24 分钟

版本

  1. v2当前
  2. v1

兄弟们见过火车头吧,但一定没见过如此长的。

浪费你们五分钟时间。

C++
#pragma GCC optimize(3)
#pragma GCC target("avx")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("inline")
#pragma GCC optimize("-fgcse")
#pragma GCC optimize("-fgcse-lm")
#pragma GCC optimize("-fipa-sra")
#pragma GCC optimize("-ftree-pre")
#pragma GCC optimize("-ftree-vrp")
#pragma GCC optimize("-fpeephole2")
#pragma GCC optimize("-ffast-math")
#pragma GCC optimize("-fsched-spec")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("-falign-jumps")
#pragma GCC optimize("-falign-loops")
#pragma GCC optimize("-falign-labels")
#pragma GCC optimize("-fdevirtualize")
#pragma GCC optimize("-fcaller-saves")
#pragma GCC optimize("-fcrossjumping")
#pragma GCC optimize("-fthread-jumps")
#pragma GCC optimize("-funroll-loops")
#pragma GCC optimize("-fwhole-program")
#pragma GCC optimize("-freorder-blocks")
#pragma GCC optimize("-fschedule-insns")
#pragma GCC optimize("inline-functions")
#pragma GCC optimize("-ftree-tail-merge")
#pragma GCC optimize("-fschedule-insns2")
#pragma GCC optimize("-fstrict-aliasing")
#pragma GCC optimize("-fstrict-overflow")
#pragma GCC optimize("-falign-functions")
#pragma GCC optimize("-fcse-skip-blocks")
#pragma GCC optimize("-fcse-follow-jumps")
#pragma GCC optimize("-fsched-interblock")
#pragma GCC optimize("-fpartial-inlining")
#pragma GCC optimize("no-stack-protector")
#pragma GCC optimize("-freorder-functions")
#pragma GCC optimize("-findirect-inlining")
#pragma GCC optimize("-frerun-cse-after-loop")
#pragma GCC optimize("inline-small-functions")
#pragma GCC optimize("-finline-small-functions")
#pragma GCC optimize("-ftree-switch-conversion")
#pragma GCC optimize("-fexpensive-optimizations")
#pragma GCC optimize("-funsafe-loop-optimizations")
#pragma GCC optimize("inline-functions-called-once")
#pragma GCC optimize("-fdelete-null-pointer-checks")
#pragma GCC optimize("-foptimize-sibling-calls")
#include<cctype>
#include<cstdint>
#include<cstdio>
#include<string>
#include<tuple>
#include<type_traits>
#include<utility>
#include<limits>
namespace FastIO{
	constexpr int IOSIZE=1<<20;
	char ibuf[IOSIZE],obuf[IOSIZE];
	char*p1=ibuf,*p2=ibuf,*p3=obuf;
	inline char _gc(){if(p1==p2){p2=(p1=ibuf)+fread(ibuf,1,IOSIZE,stdin);if(p1==p2)return EOF;}return*p1++;}
	inline void _pc(char c){if(p3==obuf+IOSIZE){fwrite(obuf,1,p3-obuf,stdout);p3=obuf;}*p3++=c;}
	inline bool _isdigit(char c){return c>='0'&&c<='9';}
	inline bool _isspace(char c){return c<=' ';}
	template<typename T,bool IsSigned=std::is_signed<T>::value>struct IntReader{static void read(T&x){char c;while(!_isdigit(c=_gc()));x=c-'0';while(_isdigit(c=_gc()))x=x*10+(c-'0');}};
	template<typename T>struct IntReader<T,true>{static void read(T&x){char c;while(!_isdigit(c=_gc())&&c!='-');bool neg=(c=='-');if(neg)c=_gc();x=c-'0';while(_isdigit(c=_gc()))x=x*10+(c-'0');if(neg)x=-x;}};
	template<typename T,bool IsSigned=std::is_signed<T>::value>struct IntWriter{static void write(T x){if(x==0){_pc('0');return;}char buf[20];int n=0;do{buf[n++]=x%10+'0';x/=10;}while(x);while(n--)_pc(buf[n]);}};
	template<typename T>struct IntWriter<T,true>{static void write(T x){if(x==0){_pc('0');return;}if(x<0){_pc('-');x=-x;}char buf[20];int n=0;do{buf[n++]=x%10+'0';x/=10;}while(x);while(n--)_pc(buf[n]);}};
	inline void read(int&x){IntReader<int>::read(x);}
	inline void read(long long&x){IntReader<long long>::read(x);}
	inline void read(unsigned int&x){IntReader<unsigned int>::read(x);}
	inline void read(unsigned long long&x){IntReader<unsigned long long>::read(x);}
	inline void read(short&x){IntReader<short>::read(x);}
	inline void read(long&x){IntReader<long>::read(x);}
	inline void read(char&x){while(_isspace(x=_gc()));}
	inline void read(bool&b){char c;while(_isspace(c=_gc()));b=(c!='0'&&c!='f');}
	inline void read(std::string&s){char c;while(_isspace(c=_gc()));s.clear();do{s+=c;}while(!_isspace(c=_gc()));}
	template<typename T>typename std::enable_if<std::is_floating_point<T>::value,void>::type read(T&x){char c;while(!_isdigit(c=_gc())&&c!='-'&&c!='.');bool neg=(c=='-');if(c=='-'||c=='.')c=_gc();x=0;T base=1;while(_isdigit(c)){x=x*10+(c-'0');c=_gc();}if(c=='.'){c=_gc();while(_isdigit(c)){base*=0.1;x+=(c-'0')*base;c=_gc();}}if(neg)x=-x;}
	inline void write(int x){IntWriter<int>::write(x);}
	inline void write(long long x){IntWriter<long long>::write(x);}
	inline void write(unsigned int x){IntWriter<unsigned int>::write(x);}
	inline void write(unsigned long long x){IntWriter<unsigned long long>::write(x);}
	inline void write(short x){IntWriter<short>::write(x);}
	inline void write(long x){IntWriter<long>::write(x);}
	inline void write(char x){_pc(x);}
	inline void write(const char*x){while(*x)_pc(*x++);}
	inline void write(const std::string&s){for(char c:s)_pc(c);}
	inline void write(bool b){_pc(b?'1':'0');}
	template<typename T,typename...Args>inline void read(T&x,Args&...args){read(x);read(args...);}
	template<typename T,typename...Args>inline void write(const T&x,const Args&...args){write(x);write(args...);}
	struct FastIO{~FastIO(){if(p3>obuf)fwrite(obuf,1,p3-obuf,stdout);}template<typename T>FastIO&operator>>(T&x){read(x);return*this;}template<typename T>FastIO&operator<<(const T&x){write(x);return*this;}};
}using namespace FastIO;
#define cin FastIO::FastIO()
#define cout FastIO::FastIO()
#define endl '\n'

这是第一个,以下是第二个。

C++
#include <cstdint>
#include <cstdio>
#include <string>

namespace oi {
constexpr std::size_t IOBUFFER = 32 * 1024 + 1;
constexpr char endl = '\n';

[[gnu::always_inline]] inline bool isspace(unsigned char v) {
	static constexpr bool map[256] = {
		1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
		1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
		0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
		0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
		0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
		1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
		1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
		1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
		1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
	};
	return map[v];
}

class fastio {
  private:
	std::uint8_t __input_buffer[IOBUFFER];
	std::size_t __input_buffer_usage = 0, __input_buffer_point = 0;
	std::uint8_t __output_buffer[IOBUFFER];
	std::size_t __output_buffer_point = 0;

	std::FILE *__input = nullptr;
	std::FILE *__output = nullptr;

	static constexpr std::uint8_t __number_base = 10;

	[[gnu::always_inline]] inline std::int16_t get_char() {
		if (this->__input_buffer_point >= this->__input_buffer_usage) [[unlikely]] {
			this->__input_buffer_usage =
				std::fread(this->__input_buffer, sizeof(this->__input_buffer[0]),
						   sizeof(this->__input_buffer), this->__input);
			this->__input_buffer_point = 0;
		}
		if (this->__input_buffer_point >= this->__input_buffer_usage) [[unlikely]] {
			return -1;
		}
		std::uint8_t res = this->__input_buffer[this->__input_buffer_point];
		this->__input_buffer_point++;
		return res;
	}
	[[gnu::always_inline]] inline std::int16_t fetch_char() {
		if (this->__input_buffer_point >= this->__input_buffer_usage) [[unlikely]] {
			this->__input_buffer_usage =
				std::fread(this->__input_buffer, sizeof(this->__input_buffer[0]),
						   sizeof(this->__input_buffer), this->__input);
			this->__input_buffer_point = 0;
		}
		if (this->__input_buffer_point >= this->__input_buffer_usage) [[unlikely]] {
			return -1;
		}
		std::uint8_t res = this->__input_buffer[this->__input_buffer_point];
		return res;
	}

  public:
	[[gnu::always_inline]] inline void flush() {
		std::fwrite(this->__output_buffer, sizeof(this->__output_buffer[0]),
					this->__output_buffer_point, this->__output);
		this->__output_buffer_point = 0;
	}

  private:
	[[gnu::always_inline]] inline void put_char(std::uint8_t v) {
		if (this->__output_buffer_point == sizeof(this->__output_buffer)) {
			this->flush();
		}
		this->__output_buffer[this->__output_buffer_point] = v;
		this->__output_buffer_point++;
	}

	[[gnu::always_inline]] inline std::uint8_t __char_cast(std::uint8_t v) const {
		if (v <= 9)
			return '0' + v;
		else
			return 'a' + (v - 10);
	}

	[[gnu::always_inline]] inline void __skip_empty() {
		while (true) {
			std::uint8_t ch = this->fetch_char();
			if (!oi::isspace(static_cast<unsigned char>(ch))) {
				return;
			}
			this->__input_buffer_point++;
		}
	}

  public:
	fastio(const char *in, const char *out) {
		__input = std::fopen(in, "r");
		__output = std::fopen(out, "w");
	}
	fastio(std::FILE *in, std::FILE *out) {
		__input = in;
		__output = out;
	}
	fastio() : fastio(stdin, stdout) {}
	fastio(const fastio &) = delete;
	fastio &operator=(const fastio &) = delete;
	~fastio() { this->flush(); }
	fastio &operator<<(unsigned long long p) {
		std::uint8_t tmp[70], cnt = 0;
		do {
			tmp[cnt] = this->__char_cast(p % this->__number_base);
			cnt++;
			p /= this->__number_base;
		} while (p != 0);
		for (int i = cnt - 1; i >= 0; --i)
			this->put_char(tmp[i]);
		return *this;
	}
	fastio &operator<<(long long p) {
		if (p < 0) {
			put_char('-');
			return this->operator<<(static_cast<unsigned long long>(-(p + 1)) + 1ULL);
		} else {
			return this->operator<<(static_cast<unsigned long long>(p));
		}
	}
	fastio &operator<<(short p) { return this->operator<<(static_cast<long long>(p)); }
	fastio &operator<<(int p) { return this->operator<<(static_cast<long long>(p)); }
	fastio &operator<<(long p) { return this->operator<<(static_cast<long long>(p)); }
	fastio &operator<<(unsigned short p) {
		return this->operator<<(static_cast<unsigned long long>(p));
	}
	fastio &operator<<(unsigned int p) {
		return this->operator<<(static_cast<unsigned long long>(p));
	}
	fastio &operator<<(unsigned long p) {
		return this->operator<<(static_cast<unsigned long long>(p));
	}
	fastio &operator<<(char p) {
		this->put_char(p);
		return *this;
	}
	fastio &operator<<(const char *p) {
		if (!p)
			return *this;
		while (*p) {
			this->put_char(*p);
			p++;
		}
		return *this;
	}
	fastio &operator<<(const std::string &p) { return this->operator<<(p.c_str()); }
	fastio &operator<<(std::nullptr_t) { return *this; }

	fastio &operator>>(unsigned long long &p) {
		p = 0;
		this->__skip_empty();
		while (true) {
			std::uint8_t ch = this->get_char();
			if (oi::isspace(static_cast<unsigned char>(ch)))
				return *this;
			p *= 10;
			p += (ch - '0');
		}
	}
	fastio &operator>>(long long &p) {
		bool neg = false;
		p = 0;
		this->__skip_empty();
		std::uint8_t ch = this->get_char();
		if (ch == '-') {
			neg = true;
			ch = this->get_char();
		}
		while (true) {
			if (oi::isspace(static_cast<unsigned char>(ch))) {
				if (neg)
					p = -p;
				return *this;
			}
			p *= 10;
			p += (ch - '0');
			ch = this->get_char();
		}
	}
	fastio &operator>>(char &c) {
		c = this->get_char();
		return *this;
	}
	fastio &operator>>(char *c) {
		this->__skip_empty();
		for (int i = 0;; i++) {
			std::int16_t ch = this->get_char();
			if (ch == -1 || oi::isspace(static_cast<unsigned char>(ch))) {
				c[i] = '\0';
				return *this;
			}
			c[i] = ch;
		}
	}

	fastio &operator>>(short &p) {
		long long tmp;
		*this >> tmp;
		p = tmp;
		return *this;
	}
	fastio &operator>>(int &p) {
		long long tmp;
		*this >> tmp;
		p = tmp;
		return *this;
	}
	fastio &operator>>(long &p) {
		long long tmp;
		*this >> tmp;
		p = tmp;
		return *this;
	}
	fastio &operator>>(unsigned short &p) {
		unsigned long long tmp;
		*this >> tmp;
		p = tmp;
		return *this;
	}
	fastio &operator>>(unsigned int &p) {
		unsigned long long tmp;
		*this >> tmp;
		p = tmp;
		return *this;
	}
	fastio &operator>>(unsigned long &p) {
		unsigned long long tmp;
		*this >> tmp;
		p = tmp;
		return *this;
	}
};
}

火车头由 AI 生成。

原文