超级大模板
Eason_618
·
·
科技·工程
#include<bits/stdc++.h>
#define pc putchar
#define _getchar_nolock getchar
#define _putchar_nolock putchar
using namespace std;
namespace bigtemp{
inline int read_int(){int res = 0;char c=_getchar_nolock();bool q=0;while(!isdigit(c)){if(c=='-')q=1;c=_getchar_nolock();}res=(c^48);while((isdigit(c=_getchar_nolock())))res=(res<<3)+(res<<1)+(c^48);if(q)res=-res;return res;}
inline double read_double(){double x = 0, y = 1.0;int f = 0, dec = 0;char ch = getchar();while (ch < '0' || ch > '9') {if (ch == '-') f = 1;ch = getchar();}while ((ch >= '0' && ch <= '9') || ch == '.') {if (ch == '.') dec = 1;else if (!dec) x = x * 10 + (ch - '0');else x += (y /= 10) * (ch - '0');ch = getchar();}return f ? -x : x;}
inline char read_char(){char res;while((res = getchar()) != EOF && isspace(res));return res;}
inline char* read_chars(){char* s;int sum=0;char ch = getchar();while (isspace(ch)) ch = getchar();while (!isspace(ch) && ch != EOF) {s[++sum]=ch;ch = getchar();}return s;}
inline string read_string(){string s;char ch = getchar();while (isspace(ch)) ch = getchar();while (!isspace(ch) && ch != EOF) {s.push_back(ch);ch = getchar();}return s;}
template<typename T>inline void write_int(T x){if(x < 0)putchar('-'), x = -x;if(x > 9)write_int(x / 10);_putchar_nolock(x % 10 + '0');}
inline void write_chars(const char* s){while(*s)fputc(*s++, stdout);}
void write_double(double x, int precision = 6){if (x < 0) {putchar('-');x = -x;}x += 5 * pow(10, -precision - 1);long long integer = (long long)x;double decimal = x - integer;if (integer == 0) {putchar('0');} else {char buffer[20];int pos = 0;while (integer > 0) {buffer[pos++] = '0' + integer % 10;integer /= 10;}while (--pos >= 0) putchar(buffer[pos]);}if (precision > 0) {putchar('.');while (precision--) {decimal *= 10;int digit = (int)decimal;putchar('0' + digit);decimal -= digit;}}}
#define forr(l, r) for(int i = l; i <= r; i++)
void cin_list(int l, int r, int *a){for(int i = l; i <= r; i++)a[i]=read_int();}
void cout_list(int l, int r, int *a, char sep=' ', char end='\n'){for(int i = l; i <= r; i++)write_int(a[i]),putchar(sep);putchar(end);}
void Merge_Sort(int l, int r, int *a, int *t){if(l>=r)return;int mid=(l+r)/2;Merge_Sort(l, mid, a, t);Merge_Sort(mid+1, r, a, t);int i=l, j=mid+1, s=l;while(i<=mid&&j<=r){if(a[i]<=a[j])t[s++]=a[i++];else t[s++]=a[j++];}while(i<=mid)t[s++]=a[i++];while(j<=r)t[s++]=a[j++];for(int i = l; i <= r; i++)a[i]=t[i];}
void qsort(int l, int r, int *a){int x = a[(l + r) / 2];int i = l, j = r;while(i <= j){while(a[i] < x)i++;while(a[j] > x)j--;if(i <= j){swap(a[i], a[j]);i++;j--;}}if(l < j)qsort(l, j, a);if(i < r)qsort(i, r, a);}
#define pc putchar
#define gcd(x, y) __gcd(x, y);
#define lcm(x, y) __lcm(x, y);
struct p{
vector<int>p, size;
void resize(int x){
p.resize(x+1);
for(int i = 1; i <= x; i++)p[i]=i;
size.resize(x+1, 1);
}
int find(int x){
return p[x]==x?x:p[x]=find(p[x]);
}
inline bool is_same(int xx, int yy){
return xx==yy;
}
void merge(int x, int y){
int xx=find(x), yy=find(y);
if(is_same(xx, yy))return;
if(size[xx]<size[yy]){
p[xx]=yy;
size[yy]+=size[xx];
}else{
p[yy]=xx;
size[xx]+=size[yy];
}
}
void clean(){
p.clear();
size.clear();
}
}p;
struct bigint{
vector<short>arr;
bool f = 0;
bool operator < (bigint b){
if(this->arr.size()<b.arr.size())return true;
if(this->arr.size()>b.arr.size())return false;
for(int i = 0; i < b.arr.size(); i++){
if(this->arr[i]<b.arr[i])return true;
else return false;
}
return false;
}
bool operator > (bigint b){
if(this->arr.size()>b.arr.size())return true;
if(this->arr.size()<b.arr.size())return false;
for(int i = 0; i < b.arr.size(); i++){
if(this->arr[i]>b.arr[i])return true;
else return false;
}
return false;
}
bool operator == (bigint b){
if(this->arr.size()!=b.arr.size())return false;
for(int i = 0; i < b.arr.size(); i++){
if(this->arr[i]<b.arr[i])return false;
}
return true;
}
bool operator <= (bigint b){
if(*this<b||*this==b)return true;
return false;
}
bool operator >= (bigint b){
return !(*this<b);
}
bool operator != (bigint b){
return !(*this==b);
}
void operator = (int b){
while(!arr.empty())arr.pop_back();
while(b){
arr.push_back(b%10);
b/=10;
}
}
void operator = (bigint b){
arr=b.arr;
}
bigint operator + (bigint b){
bool ff=0;
bigint c;
if(*this<b)swap(*this, b),ff=1;
c.arr.resize(this->arr.size()+1);
for(int i = 0; i < max(this->arr.size(), b.arr.size()); i++){
if(i<b.arr.size())c.arr[i]+=this->arr[i]+b.arr[i];
else c.arr[i]+=this->arr[i];
c.arr[i+1]+=c.arr[i]/10;
c.arr[i]%=10;
}
if(ff)swap(b, *this);
while(c.arr.size()>1&&c.arr.back()==0)c.arr.pop_back();
return c;
}
bigint operator - (bigint b){
f=0;
bigint c;
if(*this<b)swap(*this, b),c.f=1;
c.arr.resize(this->arr.size());
for(int i = 0; i < max(this->arr.size(), b.arr.size()); i++){
if(i<b.arr.size())c.arr[i]+=this->arr[i]-b.arr[i];
else c.arr[i]+=this->arr[i];
if(c.arr[i]<0)c.arr[i+1]--,c.arr[i]+=10;
}
if(c.f==1)swap(b, *this);
while(c.arr.size()>1&&c.arr.back()==0)c.arr.pop_back();
return c;
}
bigint operator * (bigint b){
bool ff=0;
bigint c;
if(*this<b)swap(*this, b),ff=1;
c.arr.resize(this->arr.size()+b.arr.size()+1);
for(int i = 0; i < this->arr.size(); i++){
for(int j = 0; j < b.arr.size(); j++){
c.arr[i+j]+=(this->arr[i]*b.arr[j]);
c.arr[i+j+1]+=c.arr[i+j]/10;
c.arr[i+j]%=10;
}
}
if(ff)swap(b, *this);
while(c.arr.size()>1&&c.arr.back()==0)c.arr.pop_back();
return c;
}
void operator += (bigint b){
*this=*this+b;
}
void operator -= (bigint b){
*this=*this-b;
}
void operator *= (bigint b){
*this=*this*b;
}
bigint operator [] (int b){
bigint c;
while(!c.arr.empty())c.arr.pop_back();
while(b){
c.arr.push_back(b%10);
b/=10;
}
return c;
}
bigint in(){
bigint c;
char cc=_getchar_nolock();
while(cc<'0'||cc>'9'){
if(cc='-')c.f=1;
cc=_getchar_nolock();
}
c.arr.push_back(cc^48);
while((cc=_getchar_nolock())>='0'&&cc<='9'){
c.arr.push_back(cc^48);
}
reverse(c.arr.begin(), c.arr.end());
return c;
}
void out(){
reverse(arr.begin(), arr.end());
if(f)_putchar_nolock('-');
for(int i = 0; i < arr.size(); i++)_putchar_nolock(arr[i]+'0');
}
void clean(){
while(!arr.empty())arr.pop_back();
}
int to_int(){
int c = 0;
for(int i = arr.size()-1; i >= 0; i--)c=(c<<3)+(c<<1)+arr[i];
return c;
}
int to_long_long(){
long long c = 0;
for(int i = arr.size()-1; i >= 0; i--)c=(c<<3)+(c<<1)+arr[i];
return c;
}
string to_string(){
string c = "";
for(int i = arr.size()-1; i >= 0; i--)c+=arr[i]+'0';
return c;
}
}turn;
bool bigint_cmp(bigint a, bigint b){
return a < b;
}
struct inout{
//1.(>>)部分
inout& operator>>(int& res){
res=read_int();
return *this;
}
inout& operator>>(unsigned int& res){
res=read_int();
return *this;
}
inout& operator>>(unsigned long& res){
res=read_int();
return *this;
}
inout& operator>>(long long& res){
res=read_int();
return *this;
}
inout& operator>>(unsigned long long& res){
res=read_int();
return *this;
}
inout& operator>>(float& res){
res=read_double();
return *this;
}
inout& operator>>(double& res){
res=read_double();
return *this;
}
inout& operator>>(long double& res){
res=read_double();
return *this;
}
inout& operator>>(char& res){
res = getchar();
return *this;
}
inout& operator>>(char*& res){
res = read_chars();
return *this;
}
inout& operator>>(string& res){
res = read_string();
return *this;
}
inout& operator>>(bigint& a){
a=a.in();
return *this;
}
//2.(<<)部分
inout& operator<<(const int& res){
write_int(res);
return *this;
}
inout& operator<<(const unsigned int& res){
write_int(res);
return *this;
}
inout& operator<<(const unsigned long& res){
write_int(res);
return *this;
}
inout& operator<<(const long long& res){
write_int(res);
return *this;
}
inout& operator<<(const unsigned long long& res){
write_int(res);
return *this;
}
inout& operator<<(const float& res){
write_double(res); //注:默认六位
return *this;
}
inout& operator<<(const double& res){
write_double(res); //注:默认六位
return *this;
}
inout& operator<<(const long double& res){
write_double(res, 10); //注:默认十位
return *this;
}
inout& operator<<(const char& res){
putchar(res);
return *this;
}
inout& operator<<(const char*& res){
write_chars(res);
return *this;
}
inout& operator<<(const string& res){
write_chars(res.c_str());
return *this;
}
inout& operator<<(bigint a){
a.out();
return *this;
}
}cinn, coutt;
}
using namespace bigtemp;
#define cin cinn
#define cout coutt
#define intt long long
#define int bigint
signed main(){
return 0;
}