QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#164877 | #6883. Noblesse Code | Nyans | AC ✓ | 740ms | 30220kb | C++14 | 1.1kb | 2023-09-05 14:21:16 | 2023-09-05 14:21:16 |
Judging History
answer
#include <cstdio>
#include <algorithm>
struct pr {
long long a, b, c;
bool operator < (const pr &rhs) const {
if (a != rhs.a) return a < rhs.a;
if (b != rhs.b) return b < rhs.b;
return c < rhs.c;
}
}c[5000010];
int T, n, m, q;
int main() {
scanf("%d", &T);
while (T--) {
scanf("%d%d", &n, &q);
m = 0;
for (int i = 1; i <= n; ++i) {
long long a, b;
scanf("%lld%lld", &a, &b);
while (a && b) {
if (a >= b) {
c[++m] = {a % b, b, a / b};
a %= b;
} else {
c[++m] = {a, b % a, b / a};
b %= a;
}
}
}
std::sort(c + 1, c + m + 1);
for (int i = 1; i <= q; ++i) {
long long a, b;
scanf("%lld%lld", &a, &b);
int ans = 0;
if (a >= b) {
pr P = {a % b, b, a / b};
pr *pos = std::lower_bound(c + 1, c + m + 1, P);
P.c = 2e18;
ans = std::lower_bound(c + 1, c + m + 1, P) - pos;
}
if (b >= a) {
pr P = {a, b % a, b / a};
pr *pos = std::lower_bound(c + 1, c + m + 1, P);
P.c = 2e18;
ans += std::lower_bound(c + 1, c + m + 1, P) - pos;
}
printf("%d\n", ans);
}
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 740ms
memory: 30220kb
input:
54 1000 1000 437949642385872929 860965504436928836 549207725345251140 807757620153191620 595135374173197122 535841165330085586 284216015123638122 991606310035186132 380255965462330700 718440783553992066 600098959546211922 568697564089219926 561489079983301188 490903512830837710 917947220777629314 45...
output:
1 1 1 0 1 1 1 1 1 1 1 1 1 0 1 1 1 0 1 1 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 1 1 1 1 1 0 1 1 1 0 1 1 1 1 1 1 1 1 1 1 1 1 1 0 1 1 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 1 1 1 1 1 1 0 1 1 1 1 1 1 0 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ...
result:
ok 495000 lines