-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfast_input.c
More file actions
54 lines (52 loc) · 1.25 KB
/
fast_input.c
File metadata and controls
54 lines (52 loc) · 1.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
/*
Fast Input templates
Author: Dan Shan
Last Updated: 2025-01-18
*/
// macro faster for small inputs and methods faster for larger inputs theoretically
// macro scan
#define mscan(x) do{while((x=getchar_unlocked())<'0'); for(x-='0'; '0'<=(_=getchar_unlocked()); x=(x<<3)+(x<<1)+_-'0');}while(0)
char _;
// scanner using pointers (fastest in this code)
#define bs 1<<20 // buffer size
char buf[bs];
char *ptr = buf;
void buff(){
fread(buf,1,bs,stdin);
}
long long fscan(){ // fast input template
long long num=0;
while(*ptr<'0'||*ptr>'9')++ptr; // Skip non-digit characters
while(*ptr>='0'&&*ptr<='9') {
num=num*10+(*ptr-'0');
++ptr;
}
return num;
}
// method scanner
int scan() {
int num = 0;
char c = getchar_unlocked();
while (c>'9'||c<'0') c = getchar_unlocked();
while (c>='0'&&c<='9') {
num=num*10+c-'0';
c=getchar_unlocked();
}
return num;
}
// method scanner with negatives
int nscan() {
int n = 0, a = 0;
char c = getchar_unlocked();
if (c == '-') n = 1, c = getchar_unlocked();
while('0' <= c && c <= '9') a = a * 10 + c - '0', c = getchar_unlocked();
return n ? -a : a;
}
// reference
int main(){
int a = fscan();
int b = scan();
int c;
scan(c);
int d=nscan();
}