版权声明:本文为博主原创文章,禁止所有形式的未经博主允许的转载行为。 https://blog.csdn.net/qq_33330876/article/details/68488811
今天被读入优化坑惨了
因为一道随便水水就能过的屎题,调了一下午我一直以为是我STL的锅。
以后校OJ上读入量超过10mb的题目,不写这个优化,我名字倒着写…
版本1
#include<cstdio>
#include<iostream>
using namespace std;
const int maxx=40000008;
char Input[maxx+5],*ipos;
#define read() (strtol(ipos,&ipos,10))
int main() {
fread(Input,maxx,1,stdin);ipos=Input;
int n=read();
//Do something......
return 0;
}
版本2
const int STRSIZE=int(4e7);
char in1[STRSIZE];
char *in=in1, *tempend;
void Input() {
tempend=in+STRSIZE;
fread(in,1,STRSIZE,stdin);
}
inline void scan(int &x) {
char c=*(in++);
while(!(c>='0' && c<='9')) c=*(in++);
x=c-'0';
c=*(in++);
while(c>='0' && c<='9') {
x=x*10+c-'0';
c=*(in++);
}
}
打acm之后用的
#include <bits/stdc++.h>
using namespace std;
const int BUF=40000000;
char Buf[BUF], *buf=Buf;
inline void read(int& a) {for(a=0;*buf<48;buf++); while(*buf>47) a=a*10+*buf++-48;}
void work() {
}
int main() {
#ifndef ONLINE_JUDGE
freopen("input.txt","r",stdin);
#endif
fread(Buf,1,BUF,stdin);
int T;
for(read(T);T;T--)
work();
return 0;
}
打ACM用的二逼I/O
inline int read() {
register int val=0, sign=1; char ch;
while(~(ch=getchar()) && (ch<'0' || ch>'9') && ch!='-'); ch=='-'?sign=-1:val=ch-'0';
while(~(ch=getchar()) && (ch>='0' && ch<='9')) val=(val<<1)+(val<<3)+ch-'0';
return val*sign;
}