제출 #119088

#제출 시각아이디문제언어결과실행 시간메모리
119088BruteforcemanCambridge (info1cup18_cambridge)C++11
100 / 100
132 ms10232 KiB
#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; }

컴파일 시 표준 에러 (stderr) 메시지

cambridge.cpp: In function 'int main(int, const char**)':
cambridge.cpp:61:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d %d", &n, &m);
  ~~~~~^~~~~~~~~~~~~~~~~
cambridge.cpp:63:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d %d", &t[i], &d[i]);
   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~
cambridge.cpp:81:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d %d", &p, &q);
   ~~~~~^~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...