跳到正文

个人记录

个人用火车头

bsdsdb约 7 分钟
原文
文章信息与版本

文章信息

发布
2025年3月15日
收录
2025年12月12日
更新
2026年10月20日
篇幅
约 7 分钟

版本

  1. v1当前

火车头

C++
#include <bits/stdc++.h>
//#define CODEFORCES
#ifdef CODEFORCES
#pragma GCC optimize(1,2,3,"Ofast","inline","unroll-loops")
#endif
bool memtest1;
using namespace std;
namespace heead {
	// types
	using i32 = int32_t;
	using i64 = int64_t;
	using i128 = __int128;
	using u32 = unsigned int;
	using u64 = unsigned long long;
	using f32 = float;
	using f64 = double;
	using f128 = __float128;
	using ll = i64;
	using ull = u64;
	using ldb = long double;
	#define umap unordered_map
	#define uset unordered_set
	#define prque priority_queue
	#define pi32 pair<i32, i32>
	#define pi64 pair<i64, i64>
	#define pll pair<ll, ll>
	// functions
	#define emp emplace
	#define empb emplace_back
	#define empf emplace_front
	#define mkp make_pair
//	mt19937_64 rd(chrono::high_resolution_clock().now().time_since_epoch().count());
	mt19937_64 rd(1);
	ldb randreal() {
		return ldb(rd()) / (1ll << 32) / (1ll << 32);
	}
	bool dice(ldb x) {
		return randreal() <= x;
	}
	// constants
	#define csep constexpr
	csep i64 inf = 0x3f3f3f3f3f3f3f3fll;
	csep f64 eps = 1e-8;
	csep f64 PI = 3.14159265358979323846264338327950288419716939937510582097;
	// non-std type io
	istream& operator>>(istream& in, i128& x) {
		string input;
		in >> input;
		x = 0;
		for (char c : input) {
			if (c == '-') {
				continue;
			}
			x = (x << 3) + (x << 1) + (c & 15);
		}
		if (input[0] == '-') {
			x *= -1;
		}
		return in;
	}
	ostream& operator<<(ostream& out, i128 x) {
		stack<char> output;
		if (x < 0) {
			out << '-';
			x *= -1;
		}
		if (!x) {
			out << '0';
			return out;
		}
		while (x) {
			output.emp((x % 10) | 48);
			x /= 10;
		}
		while (!output.empty()) {
			out << output.top();
			output.pop();
		}
		return out;
	}
	istream& operator>>(istream& in, f128& x) {
		string input;
		in >> input;
		f128 mul = 1;
		i64 id = (input.find('.') == string::npos ? input.length() : input.find('.')) - (input[0] == '-') - 1;
		for (ll i = 1; i <= id; ++i) {
			mul *= 10;
		}
		x = 0;
		for (char c : input) {
			if (c == '.' || c == '-') {
				continue;
			}
			x += mul * (c & 15);
			mul /= 10;
		}
		if (input[0] == '-') {
			x *= -1;
		}
		return in;
	}
	csep i64 F128ACC = 12;
	ostream& operator<<(ostream& out, f128 x) {
		// negative case
		if (x < 0) {
			out << '-';
			x *= -1;
		}
		// integer part
		out << i128(x);
		x -= i128(x);
		// fractional part
		for (ll i = 1; i <= F128ACC; ++i) {
			x *= 10;
		}
		if (!x) {
			return out;
		}
		out << '.';
		// prefix 0
		i128 y = x;
		i128 _y = y;
		for (ll i = 1; i <= F128ACC; ++i) {
			if (!_y) {
				out << '0';
			}
			_y /= 10;
		}
		// suffix 0
		while (y && y % 10 == 0) {
			y /= 10;
		}
		// out
		out << i128(y);
		return out;
	}
}
using namespace heead;

//#define DEBUG
//#define DEBUG_USAGE
void precalc();
void init();
int mian();

bool memtest2;
#define OFFSYNC
//#define MULTITEST
int main() {
	auto st = clock();
	#ifdef DEBUG_USAGE
	freopen("in.txt", "r", stdin);
	freopen("out.txt", "w", stdout);
	#endif
	#ifdef OFFSYNC
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	#endif
	precalc();
	#ifdef MULTITEST
	i32 T;
	cin >> T;
	while (T--) {
		#ifdef DEBUG
		cerr << "-------------------------------\n";
		#endif
		init();
		mian();
	}
	#else
	mian();
	#endif
	auto ed = clock();
	#ifdef DEBUG_USAGE
	cerr << "memory use: " << abs(&memtest2 - &memtest1) << " Bytes\n";
	cerr << "time use: " << f64(ed - st) / CLOCKS_PER_SEC * 1000 << " ms\n";
	#endif
	return 0;
}

void precalc() {}
void init() {}
int mian() {}
原文