测了下读取5*10^6规模数据的时间 cin要8500ms, cin关同步流后也要2600ms, scanf要860ms, 读写挂只要170ms, 读写挂对于卡常数的题还是非常有优势的
#include <bits/stdc++.h> //打表代码
using namespace std;
int main(){
freopen("1.out", "w", stdout);
for(int i = 1; i <= 5000000; i++)
printf("%d\n", i);
for(int i = 1; i <= 5000000; i++)
printf("%d\n", i);
for(int i = 1; i <= 5000000; i++)
printf("%d\n", i);
for(int i = 1; i <= 5000000; i++)
printf("%d\n", i);
return 0;
}
#include <bits/stdc++.h> //测速代码
using namespace std;
inline int read(){
int x=0; bool f=0; char ch=getchar();
while (ch<'0' || '9'<ch) f|=ch=='-', ch=getchar();
while ('0'<=ch && ch<='9') x=x*10+ch-'0', ch=getchar();
return f?-x:x;
}
int main(){
int tmp;
clock_t start, end;
freopen("1.out", "r", stdin);
tmp = 0; start = clock();
while(tmp != 5000000) cin >> tmp;
end = clock();
printf("(sync_with_stdio(true)) cin time: %d ms\n", end-start);
ios::sync_with_stdio(false);
cin.tie(0);
tmp = 0; start = clock();
while(tmp != 5000000) cin >> tmp;
end = clock();
printf("(sync_with_stdio(false)) cin time: %d ms\n", end-start);
tmp = 0; start = clock();
while(tmp != 5000000) scanf("%d", &tmp);
end = clock();
printf("scanf time: %d ms\n", end-start);
tmp = 0; start = clock();
while(tmp != 5000000) tmp = read();
end = clock();
printf("read time: %d ms\n", end-start);
return 0;
}