# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
119088 | Bruteforceman | Cambridge (info1cup18_cambridge) | C++11 | 132 ms | 10232 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "bits/stdc++.h"
using namespace std;
typedef pair <int, int> pii;
int t[100010], d[100010];
int opt[100010];
int order[100010];
int pos[100010];
long long sum[100010 * 4];
long long ans[100010 * 4];
const long long inf = 1e18;
int n;
bool cmp(int p, int q) {
if(d[p] == d[q]) {
return t[p] < t[q];
}
return d[p] < d[q];
}
void add(int x, int c = 1, int b = 1, int e = n) {
if(b == e) {
sum[c] = t[order[b]];
ans[c] = d[order[b]] - t[order[b]];
return ;
}
int m = (b + e) >> 1;
int l = c << 1;
int r = l + 1;
if(x <= m) {
add(x, l, b, m);
} else {
add(x, r, m + 1, e);
}
sum[c] = sum[l] + sum[r];
ans[c] = min(ans[l], ans[r] - sum[l]);
}
void del(int x, int c = 1, int b = 1, int e = n) {
if(b == e) {
sum[c] = 0;
ans[c] = inf;
return ;
}
int m = (b + e) >> 1;
int l = c << 1;
int r = l + 1;
if(x <= m) {
del(x, l, b, m);
} else {
del(x, r, m + 1, e);
}
sum[c] = sum[l] + sum[r];
ans[c] = min(ans[l], ans[r] - sum[l]);
}
int main(int argc, char const *argv[])
{
int m;
scanf("%d %d", &n, &m);
for(int i = 1; i <= n; i++) {
scanf("%d %d", &t[i], &d[i]);
order[i] = i;
del(i);
}
sort(order + 1, order + n + 1, cmp);
for(int i = 1; i <= n; i++) {
pos[order[i]] = i;
}
int cur = n;
for(int i = n; i >= 1; i--) {
add(pos[i]);
while(cur >= i && ans[1] <= 0) {
del(pos[cur--]);
}
opt[i] = cur;
}
while(m--) {
int p, q;
scanf("%d %d", &p, &q);
printf("%d\n", (opt[p] >= q));
}
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |