namespace fastio{
struct{char buf[1<<20],*l=buf,*r=l;
operator char(){return l==r&&(r=(l=buf)+fread(buf,1,1<<20,stdin),l==r)?0:*l++;}
template<typename T>operator T(){
T x=0;char f=0,c=*this;
while(c<'0'||c>'9'){if(c=='-')f=1;c=*this;}
while(c>='0'&&c<='9')x=x*10+(c^48),c=*this;
return f?-x:x;
}}in;signed stk[39],tp;
template<typename T>void out(T x,char c=0){
if(x<0)putchar('-'),x=-x;
do stk[tp++]=x%10;while(x/=10);
while(tp)putchar(stk[--tp]^48);
if(c)putchar(c);
}
}using fastio::in,fastio::out;
int main(){
int n = in;
for(int k=1;k<=n;k++)
out(100000000,' ');
return 0;
}
这是我的快读,把 signed 改成 long long 在 qoj 快了 35ms。
不理解,因为 putchar 参数是 int,我传得也是 int,long long 会发生转换,但是相反 int 发生了转换。
while(tp)putchar(stk[--tp]^48);
mov DWORD PTR fastio::tp[rip], eax
cdqe
mov edi, DWORD PTR fastio::stk[0+rax*4]
xor edi, 48
这里出现了 cdqe,神秘。
下面是汇编的主要差别
int 的:
.L16:
movsx rax, DWORD PTR fastio::tp[rip]
mov esi, 100000000
lea ecx, [rax+1]
lea rdi, [rax+10]
movsx rcx, ecx
.L14:
movsx rdx, esi
mov r8d, esi
mov eax, ecx
imul rdx, rdx, 1717986919
sar r8d, 31
sar rdx, 34
sub edx, r8d
lea r8d, [rdx+rdx*4]
add r8d, r8d
sub esi, r8d
mov DWORD PTR fastio::stk[-4+rcx*4], esi
add rcx, 1
mov esi, edx
cmp rcx, rdi
jne .L14
mov DWORD PTR fastio::tp[rip], eax
test eax, eax
je .L17
.L15:
sub eax, 1
mov rsi, QWORD PTR stdout[rip]
mov DWORD PTR fastio::tp[rip], eax
cdqe
mov edi, DWORD PTR fastio::stk[0+rax*4]
xor edi, 48
call putc
mov eax, DWORD PTR fastio::tp[rip]
test eax, eax
jne .L15
long long:
.L16:
mov r8, QWORD PTR fastio::tp[rip]
mov edi, 100000000
lea rax, [r8+1]
add r8, 10
.L14:
movsx rsi, edi
mov rcx, rax
sar edi, 31
mov rax, rsi
mul r12
shr rdx, 3
lea rax, [rdx+rdx*4]
mov rdx, rsi
imul rsi, rsi, 1717986919
add rax, rax
sub rdx, rax
lea rax, [rcx+1]
mov QWORD PTR fastio::stk[-8+rcx*8], rdx
sar rsi, 34
sub esi, edi
mov edi, esi
cmp r8, rax
jne .L14
mov QWORD PTR fastio::tp[rip], rcx
test rcx, rcx
je .L17
.L15:
sub rcx, 1
mov rsi, QWORD PTR stdout[rip]
mov rdi, QWORD PTR fastio::stk[0+rcx*8]
mov QWORD PTR fastio::tp[rip], rcx
xor edi, 48
call putc
mov rcx, QWORD PTR fastio::tp[rip]
test rcx, rcx
jne .L15