快速读写(手写read、write函数)+ __int128的使用

洛谷数学题:考察异或知识(数据输入多所以拉过来当速读写模板)

#include<bits/stdc++.h>
#include<unordered_set>
#define mem(a,b) memset(a,b,sizeof a)
#define cinios (ios::sync_with_stdio(false),cin.tie(0),cout.tie(0))
#define sca scanf
#define pri printf
#define ul u << 1
#define ur u << 1 | 1
//#pragma GCC optimize(2)
using namespace std;
//inline void read(int& x) { x = 0; int f = 1; char ch = getchar(); while (ch < '0' || ch > '9') { if (ch == '-') f = -1; ch = getchar(); } while (ch >= '0' && ch <= '9') { x = x * 10 + (ch - '0'); ch = getchar(); } x *= f; }
//void write(int x) { if (x < 0) putchar('-'), x = -x; if (x >= 10) write(x / 10); putchar(x % 10 + '0'); }
//放上面不用占位置,write不开inline,因为并联函数里不要有递归或大的循环,自行百度

typedef long long ll;
typedef pair<int, int> PII;

const int N = 110, M = N * N * 2;
int INF = 0x3f3f3f3f, mod = 1e9;
int n, m, k, T, S;

void inline read(int& x) { //传入地址直接修改
	x = 0;
	int f = 1;//特判负数
	char c = getchar();
	while (c < '0' || c > '9') {
		if (c == '-')f = -1;//有负号即负数
		c = getchar();
	}
	while (c >= '0' && c <= '9')
		x = x * 10 + (c - '0'), c = getchar();
	x *= f;
}

void inline write(int x) {
	if (x < 0) putchar('-'), x = -x;//特判负数
	if (x > 9) write(x / 10);
	putchar(x % 10 + '0');
}

int main() {
	
	read(n);
	int ans = 0, t;
	for (int i = 0; i < n; i++) {
		read(t);
		ans ^= t;
	}
	write(ans);

	return 0;
}

scanf、printf的时间

神奇的快速读写(快了4、5倍)
爹!!!

__int128(超越long long的存储)

跟快读写非常相像,但__int128只能在Linux系统中编译,这意味着在大部分编程工具中是会编译失败的…

但,你只要在保证正确之后再更改类型不就好了吗

#include <bits/stdc++.h>
using namespace std;

void scan(__int128 &x)//输入
{
    x=0;int f=1;char ch=getchar();
    while (!isdigit(ch)){if (ch=='-')f=-1;ch=getchar();}
    while(isdigit(ch)){x=x*10+ch-48;ch=getchar();}
    x*=f;
}
void _print(__int128 x)
{
    if(x>9) _print(x/10);
    putchar(x%10 + '0');
}
void print(__int128 x)//输出
{
    if(x<0)
    {
        x=-x;
        putchar('-');
    }
    _print(x);
}
  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值