版本比较
题解:CF1566G Four Vertices
正文
增加 9 行删除 9 行
23 行未改动24252627282930313235 行未改动686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211334 行未改动23 行未改动#endifusing ll = long long;const int N = 1e5+5;using namespace std;int T,n,q,m,u,v,w,op; map<pair<int,int>,int> mp;set<tuple<int,int,int>> s,ss[N],st[N];multiset<ll> tp;struct info{int x,y; bool operator <(const info&a)const{return x < a.x;}};struct S{info a,b,c;}t[N*4];35 行未改动}upd(1,1,n,u,t);}inline void ins(int u,int v,int w){if(u > v) swap(u,v); mp[{u,v}] = w;if(st[u].size() >= 3){auto it = st[u].begin(); ll t = 0;t += get<0>(*it ++),t += get<0>(*it ++),t += get<0>(*it ++);tp.erase(tp.find(t));}if(st[v].size() >= 3){auto it = st[v].begin(); ll t = 0;t += get<0>(*it ++),t += get<0>(*it ++),t += get<0>(*it ++);tp.erase(tp.find(t));}s.emplace(w,u,v),ss[u].emplace(w,u,v),upd(u);st[u].emplace(w,u,v),st[v].emplace(w,u,v);if(st[u].size() >= 3){auto it = st[u].begin(); ll t = 0;t += get<0>(*it ++),t += get<0>(*it ++),t += get<0>(*it ++);tp.insert(t);}if(st[v].size() >= 3){auto it = st[v].begin(); ll t = 0;t += get<0>(*it ++),t += get<0>(*it ++),t += get<0>(*it ++);tp.insert(t);}}inline void del(int u,int v){if(u > v) swap(u,v);if(st[u].size() >= 3){auto it = st[u].begin(); ll t = 0;t += get<0>(*it ++),t += get<0>(*it ++),t += get<0>(*it ++);tp.erase(tp.find(t));}if(st[v].size() >= 3){auto it = st[v].begin(); ll t = 0;t += get<0>(*it ++),t += get<0>(*it ++),t += get<0>(*it ++);tp.erase(tp.find(t));}int w = mp[{u,v}];s.erase({w,u,v}),ss[u].erase({w,u,v}),st[u].erase({w,u,v}),st[v].erase({w,u,v}),upd(u);if(st[u].size() >= 3){auto it = st[u].begin(); ll t = 0;t += get<0>(*it ++),t += get<0>(*it ++),t += get<0>(*it ++);tp.insert(t);}if(st[v].size() >= 3){auto it = st[v].begin(); ll t = 0;t += get<0>(*it ++),t += get<0>(*it ++),t += get<0>(*it ++);tp.insert(t);}}inline ll qry(int u,int v){34 行未改动23 行未改动24252627282930313235 行未改动686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211334 行未改动23 行未改动#endifusing ll = long long;const int N = 1e5+5;using namespace std;int T,n,q,m,u,v,w,op; map<pair<int,int>,int> mp;set<tuple<int,int,int>> s,ss[N],st[N];multiset<ll> tp;struct info{int x,y; bool operator <(const info&a)const{return x < a.x;}};struct S{info a,b,c;}t[N*4];35 行未改动}upd(1,1,n,u,t);}inline void ins(int u,int v,int w){if(u > v) swap(u,v); mp[{u,v}] = w;if(st[u].size() >= 3){auto it = st[u].begin(); ll t = 0;t += get<0>(*it ++),t += get<0>(*it ++),t += get<0>(*it ++);tp.erase(tp.find(t));}if(st[v].size() >= 3){auto it = st[v].begin(); ll t = 0;t += get<0>(*it ++),t += get<0>(*it ++),t += get<0>(*it ++);tp.erase(tp.find(t));}s.emplace(w,u,v),ss[u].emplace(w,u,v),upd(u);st[u].emplace(w,u,v),st[v].emplace(w,u,v);if(st[u].size() >= 3){auto it = st[u].begin(); ll t = 0;t += get<0>(*it ++),t += get<0>(*it ++),t += get<0>(*it ++);tp.insert(t);}if(st[v].size() >= 3){auto it = st[v].begin(); ll t = 0;t += get<0>(*it ++),t += get<0>(*it ++),t += get<0>(*it ++);tp.insert(t);}}inline void del(int u,int v){if(u > v) swap(u,v);if(st[u].size() >= 3){auto it = st[u].begin(); ll t = 0;t += get<0>(*it ++),t += get<0>(*it ++),t += get<0>(*it ++);tp.erase(tp.find(t));}if(st[v].size() >= 3){auto it = st[v].begin(); ll t = 0;t += get<0>(*it ++),t += get<0>(*it ++),t += get<0>(*it ++);tp.erase(tp.find(t));}int w = mp[{u,v}];s.erase({w,u,v}),ss[u].erase({w,u,v}),st[u].erase({w,u,v}),st[v].erase({w,u,v}),upd(u);if(st[u].size() >= 3){auto it = st[u].begin(); ll t = 0;t += get<0>(*it ++),t += get<0>(*it ++),t += get<0>(*it ++);tp.insert(t);}if(st[v].size() >= 3){auto it = st[v].begin(); ll t = 0;t += get<0>(*it ++),t += get<0>(*it ++),t += get<0>(*it ++);tp.insert(t);}}inline ll qry(int u,int v){34 行未改动