想问问若用结构体中某一关键字进行二分,具体的重载函数该应该怎么写,或者说有更简单的方法,求解答
#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
template<typename T> void re(T&x){x = 0; int sign = 1; char c;do{c = getchar(); if (c == '-') sign = -1;}while(!isdigit(c)); do{x = x * 10 + c - '0'; c = getchar();}while(isdigit(c)); x *= sign;}
void write(int x){if (x < 0) x = -x, putchar('-'); if (x < 10) putchar(x + '0'); else write(x / 10), putchar(x % 10 + '0');}
const int N = 4e5 + 1000;
struct node{
int x, val;
bool operator < (const node &p) const {
return p.x < x;
}
};
vector<node> alls;
int n, sum[N], a[N], b[N];
bool cmp(node a, node b){
return a.x < b.x;
}
int main(){
re(n);
for (int i = 1; i <= n; i ++) re(a[i]);
for (int i = 1; i <= n; i ++) re(b[i]), sum[i] = sum[i - 1] + b[i];
for (int i = 1; i <= n; i ++) alls.push_back((node){a[i], sum[i]});
sort(alls.begin(), alls.end(), cmp);
int q, x, y;
re(q);
while (q --){
re(x), re(y);
node *it1 = lower_bound(alls.begin(), alls.end(), x);
node *it2 = upper_bound(alls.begin(), alls.end(), y);
}
return 0;
}
以上是错误代码,还是求问结构体重载写法