技巧汇总
1. 修改set里面的非键值。
用mutable来修饰这个非键值。
举例代码:
#include<bits/stdc++.h> using namespace std; #define Fopen freopen("_in.txt","r",stdin); freopen("_out.txt","w",stdout); #define LL long long #define ULL unsigned LL #define fi first #define se second #define pb push_back #define lson l,m,rt<<1 #define rson m+1,r,rt<<1|1 #define lch(x) tr[x].son[0] #define rch(x) tr[x].son[1] #define max3(a,b,c) max(a,max(b,c)) #define min3(a,b,c) min(a,min(b,c)) typedef pair<int,int> pll; const int inf = 0x3f3f3f3f; const int _inf = 0xc0c0c0c0; const LL INF = 0x3f3f3f3f3f3f3f3f; const LL _INF = 0xc0c0c0c0c0c0c0c0; const LL mod = (int)1e9+7; const int N = 2e5 + 100; struct Node{ int l; mutable int v; bool operator < (const Node & x) const{ return l < x.l; } Node(int a, int b): l(a), v(b){}; }; set<Node> st; int main(){ st.insert(Node(1, 2)); set<Node>::iterator it = st.lower_bound(Node(0, 0)); cout << (*it).l << " " << (*it).v << endl; (*it).v = 3; cout << (*it).l << " " << (*it).v << endl; return 0; }