火车头
WangNONO
·
·
个人记录
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
// #include<bits/extc++.h>
#include<math.h>
//#include<windows.h>
#include<algorithm>
#include<unordered_map>
using namespace std;
namespace ftrees {
//the newest
namespace treapu {
#define it unsigned
it mod = 10007;
it las = 131;
inline it rnd() {
it out = las * 13 + 413;
out %= mod;
las = out;
return out;
}
#undef it
}
template<typename t, unsigned rn() = treapu::rnd>
class treap {
#define it unsigned
#define gll(x) (x->l==nullptr?0:x->l->len)
#define grl(x) (x->r==nullptr?0:x->r->len)
#define gsl(x) (x==nullptr?0:x->len)
private:
struct node {
t s;
it len, k;
node* l, * r;
};
mutable node* rt;
inline void pu(node*& x) const {
x->len = gll(x) + grl(x) + 1;
}
inline node* cr(const t& in) const {
node* out = new node;
out->s = in;
out->len = 1;
out->k = rn();
out->l = out->r = nullptr;
return out;
}
inline void fll(node* i, const t& x, node*& l, node*& r) const {
if (i == nullptr) {
l = r = nullptr;
return;
}
if (i->s < x) {
l = i;
fll(l->r, x, l->r, r);
pu(l);
}
else {
r = i;
fll(r->l, x, l, r->l);
pu(r);
}
}
inline void flr(node* i, const t& x, node*& l, node*& r) const {
if (i == nullptr) {
l = r = nullptr;
return;
}
if (x < i->s /* i->s > x */) {
r = i;
flr(r->l, x, l, r->l);
pu(r);
}
else {
l = i;
flr(l->r, x, l->r, r);
pu(l);
}
}
inline void fls(node* i, const it& x, node*& l, node*& r) const {
if (i == nullptr) {
l = r = nullptr;
return;
}
if (gll(i) < x) {
l = i;
fls(l->r, x - gll(i) - 1, l->r, r);
pu(l);
}
else {
r = i;
fls(r->l, x, l, r->l);
pu(r);
}
}
inline node* hb(node* l, node* r) const {
if (l == nullptr)return r;
if (r == nullptr)return l;
if (l->k > r->k) {
l->r = hb(l->r, r);
pu(l);
return l;
}
else {
r->l = hb(l, r->l);
pu(r);
return r;
}
}
inline node* ge(const it& w, node* x) const {
if (x == nullptr)return nullptr;
if (w == gll(x) + 1)return x;
if (w <= gll(x))return ge(w, x->l);
else return ge(w - gll(x) - 1, x->r);
}
inline void cl(node*& x) const {
if (x == nullptr)return;
cl(x->l), cl(x->r);
delete x;
x = nullptr;
}
inline const bool ch(const t& in, node* x) const {
if (x == nullptr)return 0;
if (x->s < in)return ch(in, x->l);
if (in < x->s)return ch(in, x->r);
return 1;
}
inline const it ub(const t& in, node* x) const {
if (x == nullptr)return 0;
if (in < x->s) return ub(in, x->l);
else return gll(x) + 1 + ub(in, x->r);
}
inline const it lb(const t& in, node* x) const {
if (x == nullptr)return 0;
if (x->s < in) return gll(x) + 1 + lb(in, x->r);
else return lb(in, x->l);
}
//inline void print(node* x) {
// if (x == nullptr)return;
// print(x->l);
// cout << x->s << ' ';
// print(x->r);
//}
inline node* cp(node* x) const {
if (x == nullptr)return nullptr;
node* out = new node;
out->k = x->k;
out->len = x->len;
out->s = x->s;
out->l = cp(x->l);
out->r = cp(x->r);
return out;
}
public:
treap() {
rt = nullptr;
}
treap(const treap<t, rn>& x) {
rt = cp(x.rt);
}
~treap() {
cl(rt);
}
inline void insert(const t& in) {
node* a = nullptr, * b = nullptr;
fll(rt, in, a, b);
rt = hb(hb(a, cr(in)), b);
}
inline void pop(const it& l, const it& len = 1) {
node* a = nullptr, * b = nullptr, * mid = nullptr;
fls(rt, l, a, b);
fls(b, len, mid, b);
rt = hb(a, b);
cl(mid);
}
inline const t& get(const it& x) const {
return ge(x + 1, rt)->s;
}
inline void rmall(const t& x) {
node* a = nullptr, * b = nullptr, * mid = nullptr;
fll(rt, x, a, b);
flr(b, x, mid, b);
rt = hb(a, b);
cl(mid);
}
inline void erase(const t& x, const it& len = 1) {
node* a = nullptr, * b = nullptr, * mid = nullptr;
fll(rt, x, a, b);
fls(b, len, mid, b);
rt = hb(a, b);
cl(mid);
}
inline const it find(const t& x) const {
const it w = lb(x, rt) + 1;
if (w <= gsl(rt) && ge(w, rt)->s == x)return w - 1;
return gsl(rt);
}
inline const it lower_bound(const t& x) const {
return lb(x, rt);
}
inline const it upper_bound(const t& x) const {
return ub(x, rt);
}
inline const it count(const t& x) const {
node* a = nullptr, * b = nullptr, * mid = nullptr;
fll(rt, x, a, b);
flr(b, x, mid, b);
const it out = gsl(mid);
rt = hb(hb(a, mid), b);
return out;
}
inline const bool isin(const t& x) const {
return ch(x, rt);
}
inline const it size() const {
return gsl(rt);
}
inline void clear() {
cl(rt);
}
inline void from(const treap<t, rn>& x) {
cl(rt);
rt = cp(x.rt);
}
inline void swap(treap<t, rn>& x) {
const node* ls = rt;
rt = x.rt;
x.rt = ls;
}
inline treap<t, rn> copy() {
treap<t, rn> out;
out.rt = cp(rt);
return out;
}
inline const t& operator[](const it& x) const {
return get(x);
}
inline treap& operator=(const treap<t, rn>& x) {
from(x);
return *this;
}
inline bool operator<(const treap<t, rn>& x) const {
return size() < x.size();
}
#undef it
#undef gll(x)
#undef grl(x)
#undef gsl(x)
};
}
using namespace ftrees;
#define LONG_LONG_MAX LLONG_MAX
#define LONG_LONG_MIN LLONG_MIN
#define int long long//__int128
//#define double long double
//#define sqrt sqrtl
#define getchar_unlocked() getchar()
#define putchar_unlocked(x) putchar(x)
//static inline int brand() {
// return (rand() << 15) + rand();
//}
static inline bool gb(const int& x, const int& w) {
return x & (1 << (w - 1));
}
static inline void wb(int& x, const int& w, const bool& z) {
if (z) {
x = x | (1 << (w - 1));
}
else {
x = x & ~(1 << (w - 1));
}
}
static inline int to_sum(const string& in, const int& x) {
int out = 0;
bool sf = 1;
for (int i = 0; i <= in.size(); i++) {
if (sf && in[i] == '-')sf = 0;
else if (in[i] < '0' || in[i]>'9')continue;
else out *= x, out += in[i] - '0';
}
return sf ? out : (~out + 1);
}
static inline string to_str(int in, const int& x) {
if (!in) return "0";
string out = "";
while (in) {
out += in % x + '0';
in /= x;
}for (int i = 0; i < out.size() / 2; i++) {
swap(out[i], out[out.size() - i - 1]);
}return out;
}
#define abs(x) ((x)<0?-(x):(x))
//#define min(x,y) ((x)<(y)?(x):(y))
//#define max(x,y) ((x)>(y)?(x):(y))
int _now = 1 << 16;
int _rma = 1 << 16;
char buff[1 << 16];
static inline char getch() {
if (_now == _rma) {
if (_rma != 1 << 16)return EOF;
_rma = fread(buff, 1, _rma, stdin);
_now = 0;
}
return buff[_now++];
}
static inline void write(const int& s, const bool& c = 1) {
if (!s) { if (c)putchar_unlocked('0'); }
else if (s < 0) putchar_unlocked('-'), write((~s + 1), 0);
else write(s / 10, 0), putchar_unlocked(s % 10 + '0');
}
static inline void writesp(const int& s) {
write(s), putchar_unlocked(' ');
}
static inline void writeln(const int& s, const bool& c = 1) {
write(s), putchar_unlocked('\n');
}
static inline void swrite(const char* in) {
while (*in != '\0')putchar_unlocked(*in++);
}
#define getch() getchar_unlocked()
static inline char getclr(const char& l, const char& r) {
char get = getch();
while (get<l || get>r)get = getch();
return get;
}
static inline int read() {
int out = 0;
bool sf = 0;
char get = getch();
while (get < '0' || get > '9') {
if (get == '-')sf = 1;
get = getch();
}
while (get >= '0' && get <= '9')out *= 10, out += get - '0', get = getch();
return sf ? (~out + 1) : out;
}
static inline void sread(string& in, const char& l, const char& r) {
in = "";
char get = getch();
while (get<l || get>r)get = getch();
while (get >= l && get <= r)in += get, get = getch();
}
static inline int _qpow(int a, int b, const int& m) {
int c = 1;
while (b) {
if (b & 1)c *= a, c %= m;
a *= a;
a %= m;
b >>= 1;
}return c;
}
static inline int _qpownm(int a, int b) {
int c = 1;
while (b) {
if (b & 1)c *= a;
a *= a;
b >>= 1;
}return c;
}
static inline int _qmul(int a, int b, const int& m) {
int c = 0;
while (b) {
if (b & 1)c += a, c %= m;
a += a;
a %= m;
b >>= 1;
}return c;
}
//---------------------------------------------------------------------------------------------------------------------------
//===========================================================================================================================
signed main() {
return 0;
}
#include<bits/stdc++.h>
// simple name
#define pii pair<int,int>
#define fir first
#define sec second
#define pb push_back
#define stop system("pause")
// function
#define ls(x) (x << 1)
#define rs(x) ((x << 1) | 1)
#define mid(l, r) ((l + r) >> 1)
#define debug(x) cerr << x << endl
#define dist(x, y, x2, y2) sqrt((x - x2) * (x - x2) + (y - y2) * (y - y2))
#define WA cerr << "Wrong Answer" << endl
// val
#define eps 1e-9
#define inf32 0x3f3f3f3f
#define inf64 0x3f3f3f3f3f3f3f3fll
#define mod1 (int)(1e9 + 7)
#define mod2 998255353
#define PI acos(-1.0)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int uint;
namespace OI{
inline string add(string a, string b){
string res;
int i = a.size() - 1, j = b.size() - 1;
int carry = 0;
while (i >= 0 || j >= 0 || carry) {
int num = carry;
if (i >= 0) num += a[i--] - '0';
if (j >= 0) num += b[j--] - '0';
carry = num / 10;
res.push_back(num % 10 + '0');
}
reverse(res.begin(), res.end());
return res;
}
inline string sub(string a, string b){
string res;
int i = a.size() - 1, j = b.size() - 1;
int borrow = 0;
while(i >= 0){
int num = (a[i--] - '0') - borrow;
if(j >= 0) num -= (b[j--] - '0');
if(num < 0){
borrow = 1;
num += 10;
}else borrow = 0;
res.push_back(num + '0');
}
reverse(res.begin(), res.end());
int pos = 0;
while(res[pos] == '0') ++pos;
return res.substr(pos);
}
inline string mul(string a, int b){
string res;
int carry = 0;
for(int i = a.size() - 1; i >= 0 || carry; i--){
int num = carry;
if (i >= 0) num += (a[i] - '0') * b;
carry = num / 10;
res.push_back(num % 10 + '0');
}
reverse(res.begin(), res.end());
int pos = 0;
while(res[pos] == '0') ++pos;
return res.substr(pos);
}
inline string mul1(string a, string b) {
int m = a.size(), n = b.size();
vector<int> res(m + n, 0);
for(int i = m - 1; i >= 0; i--)
for (int j = n - 1; j >= 0; j--){
int mul = (a[i] - '0') * (b[j] - '0');
int sum = mul + res[i + j + 1];
res[i + j + 1] = sum % 10;
res[i + j] += sum / 10;
}
string ans;
for(int num : res) if(!(ans.empty() && num == 0)) ans.push_back(num + '0');
return ans.empty() ? "0" : ans;
}
inline string div(string a, int b){
string res;
int rem = 0;
for(char c : a){
rem = rem * 10 + (c - '0');
res.push_back(rem / b + '0');
rem %= b;
}
int pos = 0;
while(res[pos] == '0') pos++;
return res.substr(pos);
}
inline int mod(string a, int b){
int rem = 0;
for(char c : a)rem = (rem * 10 + (c - '0')) % b;
return rem;
}
inline string operator*(string s, string s1){return mul1(s, s1);}
inline string operator*(string s, int s1){return mul(s, s1);}
inline string operator*(int s1, string s){return mul(s, s1);}
inline int operator%(string s, int s1){return mod(s, s1);}
inline string operator/(string s, int s1){return div(s, s1);}
inline ll pw(ll a, ll b){
ll ret = 0;
while(b){
if(b & 1)ret = ret * a % mod1;
a = a * a % mod1;
b >>= 1;
}
return ret;
}
};
using namespace OI;
mt19937 rnd(clock() ^ time(0));
signed main(){
ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
return 0;
}