正文
增加 35 行删除 35 行
20 行未改动2122232425262728293031323334353637383940414243442 行未改动47484950515253545513 行未改动6970717273747576777879808182838485868 行未改动959697989910010110210322 行未改动12612712812913013113213313433 行未改动16816917017117217317417517620 行未改动1971981992002012022032042052062072082092102114 行未改动21621721821922022122222322422522622722822923023123223323423523648 行未改动28528628728828929029129229356 行未改动3503513523533543553563573583593603613623633643 行未改动36836937037137237337437537625 行未改动40240340440540640740840941030 行未改动20 行未改动```cpp#include <iostream>#include <cstdio>#include <cstdlib>2 行未改动using namespace std;#define MAXN 300000#define mx(x) t[x].mx#define mul(x) t[x].mul#define sz(x) t[x].sz#define fa(x) t[x].fa#define lc(x) t[x].c[0]#define rc(x) t[x].c[1]#define c(x,y) t[x].c[y]13 行未改动}void Push(int p){sz(p) = sz(lc(p)) + sz(rc(p)) + mul(p);return;}int New(int v, int p){mx(tot) = v, fa(tot) = p, lc(tot) = rc(tot) = 0, mul(tot) = sz(tot) = 1;return tot++;}void Rotate(int x, bool w) //0 for Zig 1 for Zag (Same as children relationship){int y = fa(x), z = fa(y), b = c(x,!w);if(b) //y with bfa(b) = y;c(y,w) = b;c(x,!w) = y, fa(y) = x; //x with y8 行未改动if((xy=(x==rc(y))) == (yz=(y==rc(z))) && z != goal)Rotate(y,yz);if(!goal)root = x;return;}int Find(int p, int v){while(mx(p)!=v && c(p,mx(p)<v))22 行未改动int p = Find(root,v), w = (mx(p)<v);if(mx(p) == v){mul(p)++, sz(p)++;return;}if(c(p,w))Splay(Adjnode(p,w),p), c(c(p,w),!w) = New(v,c(p,w)), Push(c(p,w)),Push(p), Splay(c(c(p,w),!w),0);33 行未改动k -= s+mul(p)-1, p = rc(p);elsebreak;Splay(p,0);return p;}};Splay_Tree T;inline int read()20 行未改动printf("%d\n",a); break;case 5 :x = read(), T.Find(T.root,x);if(mx(T.root) < x)a = mx(T.root);elsea = mx(T.Adjnode(T.root,0));printf("%d\n",a); break;case 6 :x = read(), T.Find(T.root,x);if(mx(T.root) > x)a = mx(T.root);elsea = mx(T.Adjnode(T.root,1));printf("%d\n",a); break;}return 0;4 行未改动```cpp#include <iostream>#include <cstdio>#include <cstdlib>48 行未改动inline void Push(int p){if(p)sz(p) = sz(lc(p)) + sz(rc(p)) + mul(p);return;}inline int New(int v, int p){mx(tot) = v, fa(tot) = p, lc(tot) = rc(tot) = 0, mul(tot) = sz(tot) = 1;56 行未改动if(fp > sz(root))Rebuild(root);return true;}inline int Rank(int v){int p = root, s = sz(lc(p))+1, ans = 1;for(; mx(p)!=v && c(p,mx(p)<v); p = c(p,mx(p)<v))if(mx(p) < v)ans += sz(lc(p))+mul(p);return ans+sz(lc(p))+(mx(p)<v ? mul(p):0);}inline int Select(int k){int p = root, s = sz(lc(p))+1;3 行未改动else if(s+mul(p)-1 < k)k -= s+mul(p)-1, p = rc(p);elsebreak;return p;}}T;int main(){25 行未改动#include <cstdlib>#include <cstring>#include <algorithm>#include <map>#include <ext/pb_ds/assoc_container.hpp>using namespace std;using namespace __gnu_pbds;#define Node pair<int,int>map <int,int> s;30 行未改动20 行未改动2122232425262728293031323334353637383940414243442 行未改动47484950515253545513 行未改动6970717273747576777879808182838485868 行未改动959697989910010110210322 行未改动12612712812913013113213313433 行未改动16816917017117217317417517620 行未改动1971981992002012022032042052062072082092102114 行未改动21621721821922022122222322422522622722822923023123223323423523648 行未改动28528628728828929029129229356 行未改动3503513523533543553563573583593603613623633643 行未改动36836937037137237337437537625 行未改动40240340440540640740840941030 行未改动20 行未改动```cpp#include <iostream>#include <cstdio>#include <cstdlib>2 行未改动using namespace std;#define MAXN 300000#define mx(x) t[x].mx#define mul(x) t[x].mul#define sz(x) t[x].sz#define fa(x) t[x].fa#define lc(x) t[x].c[0]#define rc(x) t[x].c[1]#define c(x,y) t[x].c[y]13 行未改动}void Push(int p){sz(p) = sz(lc(p)) + sz(rc(p)) + mul(p);return;}int New(int v, int p){mx(tot) = v, fa(tot) = p, lc(tot) = rc(tot) = 0, mul(tot) = sz(tot) = 1;return tot++;}void Rotate(int x, bool w) //0 for Zig 1 for Zag (Same as children relationship){int y = fa(x), z = fa(y), b = c(x,!w);if(b) //y with bfa(b) = y;c(y,w) = b;c(x,!w) = y, fa(y) = x; //x with y8 行未改动if((xy=(x==rc(y))) == (yz=(y==rc(z))) && z != goal)Rotate(y,yz);if(!goal)root = x;return;}int Find(int p, int v){while(mx(p)!=v && c(p,mx(p)<v))22 行未改动int p = Find(root,v), w = (mx(p)<v);if(mx(p) == v){mul(p)++, sz(p)++;return;}if(c(p,w))Splay(Adjnode(p,w),p), c(c(p,w),!w) = New(v,c(p,w)), Push(c(p,w)),Push(p), Splay(c(c(p,w),!w),0);33 行未改动k -= s+mul(p)-1, p = rc(p);elsebreak;Splay(p,0);return p;}};Splay_Tree T;inline int read()20 行未改动printf("%d\n",a); break;case 5 :x = read(), T.Find(T.root,x);if(mx(T.root) < x)a = mx(T.root);elsea = mx(T.Adjnode(T.root,0));printf("%d\n",a); break;case 6 :x = read(), T.Find(T.root,x);if(mx(T.root) > x)a = mx(T.root);elsea = mx(T.Adjnode(T.root,1));printf("%d\n",a); break;}return 0;4 行未改动```cpp#include <iostream>#include <cstdio>#include <cstdlib>48 行未改动inline void Push(int p){if(p)sz(p) = sz(lc(p)) + sz(rc(p)) + mul(p);return;}inline int New(int v, int p){mx(tot) = v, fa(tot) = p, lc(tot) = rc(tot) = 0, mul(tot) = sz(tot) = 1;56 行未改动if(fp > sz(root))Rebuild(root);return true;}inline int Rank(int v){int p = root, s = sz(lc(p))+1, ans = 1;for(; mx(p)!=v && c(p,mx(p)<v); p = c(p,mx(p)<v))if(mx(p) < v)ans += sz(lc(p))+mul(p);return ans+sz(lc(p))+(mx(p)<v ? mul(p):0);}inline int Select(int k){int p = root, s = sz(lc(p))+1;3 行未改动else if(s+mul(p)-1 < k)k -= s+mul(p)-1, p = rc(p);elsebreak;return p;}}T;int main(){25 行未改动#include <cstdlib>#include <cstring>#include <algorithm>#include <map>#include <ext/pb_ds/assoc_container.hpp>using namespace std;using namespace __gnu_pbds;#define Node pair<int,int>map <int,int> s;30 行未改动