代码:
#include <bits/stdc++.h> using namespace std; const int maxn = 200050; int x[maxn]; int n, q; int main() { cin >> n >> q; for (int i = 1; i <= n; i++) { // 用scanf分解abc int a, b, c; scanf("%dx%d=%d", &a, &b, &c); x[i] = (c - b) / a; } sort(x + 1, x + n + 1); int nx = unique(x + 1, x + n + 1) - x - 1; // 去重 for (int j = 1; j <= q; j++) { int l, r; cin >> l >> r; // lower_bound 函数返回大于或等于给定值的第一个元素的迭代器(或者可以理解为下标地址)。 // upper_bound 函数返回大于给定值的第一个元素的迭代器(或者可以理解为下标地址) int l1 = lower_bound(x + 1, x + nx + 1, l) - x - 1; int r1 = upper_bound(x + 1, x + nx + 1, r) - x - 1; cout << r1 - l1 << endl; } }