#30589: C++ 2ms, 76KB with LIS & I/O optimization


hugochu712@gmail.com (HugoChu)

學校 : 國立臺灣大學
編號 : 168241
來源 : [140.112.238.225]
最後登入時間 :
2023-08-29 19:30:14
a676. 00111 - History Grading -- UVa111 | From: [114.34.93.75] | 發表日期 : 2022-05-30 16:41

Example
3 1 2 4 9 5 10 6 8 7
4 7 2 3 10 6 9 1 5 8
-> (3,4), (1,7), ..., (7,8)
 
it means
put 4 to index 3
put 7 to index 1 ...
-> 7 2 4 3 6 1 8 5 10 9
 
LIS algorithm
7
2
2 4
2 3
2 3 6
1 3 6
1 3 6 8
1 3 5 8
1 3 5 8 10
1 3 5 8 9
-> LIS = 5
 
 
I/O optimization package:
 
#pragma GCC optimize("Ofast,unroll-loops,no-stack-protector,fast-math")

#define gc readchar
#define pc putchar_unlocked

inline char readchar() {
    static char buf[1<<20], *p = buf, *q = buf;
    if(p == q && (q = (p=buf)+fread(buf,1,1<<20,stdin)) == buf) return EOF;
    return *p++;
}

unsigned int scanInt()
{
    register char ch;
    register unsigned int x = 0;
    while ((ch = gc()) >= '0')
        x = x * 10 + ch - '0';
 
    return x;
}

void printInt(int n) {
    if (n/10) printInt(n/10);
    pc((n%10) + '0');
}
 
ZeroJudge Forum