不考虑内存浪费的fastIO
1 #include<bits/stdc++.h> 2 using namespace std; 3 namespace IO 4 { 5 const int len=1<<25; 6 bool flag; 7 char ch,ibuf[len],wbuf[len]; 8 int il=0,wl=0,g,G[55]; 9 void in(){int x=fread(ibuf,1,len,stdin);} 10 inline void out(){int x=fwrite(wbuf,1,wl,stdout);} 11 inline void gc(char&c){c=ibuf[il++];} 12 template<typename T>void read(T&x) 13 { 14 flag=0;gc(ch); 15 if(ch=='-')flag=1; 16 while(!isdigit(ch)){if(ch=='-')flag=1;gc(ch);} 17 x=ch-'0';gc(ch); 18 while(isdigit(ch)){x=x*10+ch-'0';gc(ch);} 19 x=flag?-x:x; 20 } 21 template<typename T>void write(T x) 22 { 23 if(x<0)wbuf[wl++]='-',x=-x; 24 g=0; 25 do{G[++g]=x%10;x/=10;}while(x); 26 for(int i=g;i>=1;--i)wbuf[wl++]='0'+G[i]; 27 wbuf[wl++]='\n'; 28 } 29 } 30 int main() 31 { 32 ios::sync_with_stdio(false); 33 IO::in(); 34 IO::out(); 35 return 0; 36 }
若总共需要读入和输出len个字符,需占用len/1048576*2 Mb的内存。
自动清空的fastIO
1 #include<bits/stdc++.h> 2 using namespace std; 3 typedef long long int ll; 4 namespace IO 5 { 6 const int len=1<<10; 7 bool flag; 8 char ch,ibuf[len],wbuf[len]; 9 int il=len,wl=0,g,G[55]; 10 inline void in() 11 { 12 int x=fread(ibuf,1,len,stdin); 13 il=0; 14 } 15 inline void out() 16 { 17 int x=fwrite(wbuf,1,wl,stdout); 18 wl=0; 19 } 20 inline void gc(char&c) 21 { 22 if(il==len) 23 in(); 24 c=ibuf[il++]; 25 } 26 inline void wc(char c) 27 { 28 if(wl==len) 29 out(); 30 wbuf[wl++]=c; 31 } 32 template<typename T>void read(T&x) 33 { 34 flag=0;gc(ch); 35 if(ch=='-')flag=1; 36 while(!isdigit(ch)){if(ch=='-')flag=1;gc(ch);} 37 x=ch-'0';gc(ch); 38 while(isdigit(ch)){x=x*10+ch-'0';gc(ch);} 39 x=flag?-x:x; 40 } 41 template<typename T>void write(T x) 42 { 43 if(x<0)wc('-'),x=-x; 44 g=0; 45 do{G[++g]=x%10;x/=10;}while(x); 46 for(int i=g;i>=1;--i)wc(G[i]+'0'); 47 wc('\n'); 48 } 49 } 50 int main() 51 { 52 freopen("a.in","r",stdin); 53 freopen("a.out","w",stdout); 54 ios::sync_with_stdio(false); 55 int n; 56 IO::read(n); 57 ll sum=0; 58 for(int i=1;i<=n;++i) 59 { 60 int x; 61 IO::read(x); 62 sum+=x; 63 IO::write(sum); 64 } 65 IO::out(); 66 return 0; 67 }