首页 > 其他分享 >我的板子

我的板子

时间:2024-08-16 19:37:49浏览次数:4  
标签:10 ch putchar void 板子 define getchar

读写优化

优化一
#ifdef _WIN32
	#define getchar _getchar_nolock
	#define putchar _putchar_nolock
#else
	#define getchar getchar_unlocked
	#define putchar putchar_unlocked
#endif
template <typename T> inline void rd(T &x){
	x = 0; int f = 1; char ch = getchar();
	while(!isdigit(ch)){ if(ch == '-') f = -1; ch = getchar();}
	while(isdigit(ch)) x = (x<<1) + (x<<3) + (ch^48), ch = getchar();
	x *= f;
}
template <typename T> inline void wt(T x){
	if(x < 0) putchar('-'), x = -x;
	if(x / 10 > 0) wt(x / 10); putchar(x % 10 + '0');
}
优化二
#define B 1 << 23
char buf[B], *p1 = buf, *p2 = buf;
#define g() (p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, B, stdin), p1 == p2) ? EOF : *p1++)
template <typename T> inline void rd(T &x) {
    x = 0; int f = 0; char c = g();
    for (; c < '0' || c > '9'; c = g())
        f ^= c == '-';
    for (; c >= '0' && c <= '9'; c = g())
        x = (x << 3) + (x << 1) + (c ^ '0');
    x = f ? -x : x;
}
char obuf[B], *O = obuf;
#define p(c) (O - obuf == B && (fwrite(obuf, 1, B, stdout), O = obuf), *O++ = (c))
template <typename T> void wt(T x) {
    if (x < 0) x = -x, p('-');
    if (x >= 10) wt(x / 10);
    p(x % 10 ^ '0');
}

注意在代码末尾加上

fwrite(obuf, 1, O - obuf, stdout)

标签:10,ch,putchar,void,板子,define,getchar
From: https://www.cnblogs.com/xiaolemc/p/18363531

相关文章

  • 随用随取的无旋Treap板子!
    使用说明及注意事项:使用命名空间+结构体进行封装,使用时只需jser::Treap或usingnamespacejser即可。例如:/*way1*/usingnamespacejser;Treaptree;/*way2*/jser::Treaptree;随机数生成采用random_device和mt19937,在某些评测姬上可能不适用,可以换用rand(注意数......
  • 李超线段树板子
    点击查看代码#include<bits/stdc++.h>usingnamespacestd;constintN=1e6+5;constintmod=1e9;constintp=39989;constdoubleeps=1e-9;intn,m;intans,ansid;inttcnt,rt;structlmy{ doublek,b;}a[N];structTree{ intls,rs,id;}tr[N];boolc......
  • xilinx ZCU106板子运行AMP多核双CPU
    一开始的是需要在xilinx板子上HDMI直通,经过在xilinx官网上的寻找,最终发现两种办法,第一种是hdmi_rx_ss---->vpss-scaler---->axis-broadcaster---->FrameBufferWrite---->Gstreamer---->FrameBufferRead---->v_mix---->hdmi_tx_ss,最终缩减到hdmi_rx_ss---->Fr......
  • 洛谷 CF896C Willem, Chtholly and Seniorious之珂朵莉树板子
    洛谷CF896C题解传送锚点摸鱼环节Willem,ChthollyandSeniorious题面翻译【题面】请你写一种奇怪的数据结构,支持:\(1\)\(l\)\(r\)\(x\):将\([l,r]\)区间所有数加上\(x\)\(2\)\(l\)\(r\)\(x\):将\([l,r]\)区间所有数改成\(x\)\(3\)\(l\)\(r\)\(x\):输出将\(......
  • 算法板子:最短路问题——包含朴素Dijkstra算法、堆优化版的Dijkstra算法、SPFA算法、Fl
    目录1.几种算法的用途2.Dijkstra算法——求源点到其他所有点的最短路径(不能处理负边权)(1)朴素Dijkstra算法——适用于稠密图(2)堆优化版的Dijkstra算法——适用于稀疏图4.SPFA算法——求源点到其他所有点的最短路径、判断是否存在负环(可以处理负边权)(1)求有负边权的图......
  • 算法板子:质数——判定质数、分解质因数、筛质数
    目录一、判定质数1.代码二、分解质因数1.质因数的概念2.代码三、筛质数——获取1~n中所有质数的个数1.合数的概念2.代码一、判定质数1.代码#include<iostream>usingnamespacestd;boolis_prime(intx){//1不是质数,需要特判if(x==1)r......
  • 洛谷 P2731 骑马修栅栏 Riding the Fences之欧拉路径板子
    洛谷P2731题解传送锚点摸鱼环节[USACO3.3]骑马修栅栏RidingtheFences题目背景FarmerJohn每年有很多栅栏要修理。他总是骑着马穿过每一个栅栏并修复它破损的地方。题目描述John是一个与其他农民一样懒的人。他讨厌骑马,因此从来不两次经过一个栅栏。John的农场上......
  • 洛谷 P3870 开关之线段树板子
    洛谷P3870题解传送锚点摸鱼环节[TJOI2009]开关题目描述现有\(n\)盏灯排成一排,从左到右依次编号为:\(1\),\(2\),……,\(n\)。然后依次执行\(m\)项操作。操作分为两种:指定一个区间\([a,b]\),然后改变编号在这个区间内的灯的状态(把开着的灯关上,关着的灯打开);指定一个区间......
  • 8.9 线段树板子+三分补题+三维的bfs
    nowcoder训练区间线段树板子题,我们只需要把区间每一个点设置成1,然后修改的时候直接改点,然后查区间就行线段树维护最大字段和/01串最大连续1的个数模板题。把白色和黑色看成1/0两个数就行了。#include<bits/stdc++.h>usingnamespacestd;usingi64=longlon......
  • 点分治板子
    #define_CRT_SECURE_NO_WARNINGS#include<iostream>#include<vector>#include<algorithm>#include<math.h>#include<sstream>#include<string>#include<string.h>#include<iomanip>#include<stdlib.h>#inc......