제출 #106777

#제출 시각아이디문제언어결과실행 시간메모리
106777eriksuenderhaufTwo Antennas (JOI19_antennas)C++11
100 / 100
846 ms44312 KiB
#pragma GCC optimize("O3") #include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #define mem(a,v) memset((a), (v), sizeof (a)) #define enl printf("\n") #define case(t) printf("Case #%d: ", (t)) #define ni(n) scanf("%d", &(n)) #define nl(n) scanf("%lld", &(n)) #define nai(a, n) for (int i = 0; i < (n); i++) ni(a[i]) #define nal(a, n) for (int i = 0; i < (n); i++) nl(a[i]) #define pri(n) printf("%d\n", (n)) #define prl(n) printf("%lld\n", (n)) #define pii pair<int, int> #define pil pair<int, long long> #define pll pair<long long, long long> #define vii vector<pii> #define vil vector<pil> #define vll vector<pll> #define vi vector<int> #define vl vector<long long> #define pb push_back #define mp make_pair #define fi first #define se second using namespace std; using namespace __gnu_pbds; typedef long long ll; typedef cc_hash_table<int,int,hash<int>> ht; typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> oset; const double pi = acos(-1); const int MOD = 1e9 + 7; const ll INF = 2e9; const int MAXN = 2e5 + 5; const double eps = 1e-9; ll h[MAXN], ans[MAXN]; int a[MAXN], b[MAXN]; pair<pii,int> qr[MAXN]; pll seg1[MAXN*4], lazy[MAXN*4]; ll seg2[MAXN*4]; int n; vi arr[2][MAXN]; void build(int l, int r, int k) { seg1[k] = {INF, -INF}; lazy[k] = {INF, -INF}; seg2[k] = -1; if (l == r) return; int m = (l + r) / 2; build(l, m, k*2); build(m+1, r, k*2+1); } void prop(int l, int r, int k) { if (l != r) { lazy[k*2].fi = min(lazy[k*2].fi, lazy[k].fi); lazy[k*2].se = max(lazy[k*2].se, lazy[k].se); lazy[k*2+1].fi = min(lazy[k*2+1].fi, lazy[k].fi); lazy[k*2+1].se = max(lazy[k*2+1].se, lazy[k].se); } lazy[k] = {INF, -INF}; } void upd1(int l, int r, int k, int x, pll val) { if (lazy[k] != mp(INF, -INF)) { seg2[k] = max(seg2[k], max(lazy[k].se - seg1[k].fi, seg1[k].se - lazy[k].fi)); prop(l, r, k); } if (r < x || x < l) return; if (x <= l && r <= x) { seg1[k] = val; return; } int m = (l + r) / 2; upd1(l, m, k*2, x, val); upd1(m+1, r, k*2+1, x, val); seg1[k].fi = min(seg1[k*2].fi, seg1[k*2+1].fi); seg1[k].se = max(seg1[k*2].se, seg1[k*2+1].se); } void upd2(int l, int r, int k, int x, int y, ll val) { if (lazy[k] != mp(INF, -INF)) { seg2[k] = max(seg2[k], max(lazy[k].se - seg1[k].fi, seg1[k].se - lazy[k].fi)); prop(l, r, k); } if (r < x || y < l || y < x) return; if (x <= l && r <= y) { seg2[k] = max(seg2[k], max(val - seg1[k].fi, seg1[k].se - val)); lazy[k] = mp(val, val); prop(l, r, k); return; } int m = (l + r) / 2; upd2(l, m, k*2, x, y, val); upd2(m+1, r, k*2+1, x, y, val); seg2[k] = max(seg2[k*2], seg2[k*2+1]); } ll qry(int l, int r, int k, int x, int y) { if (r < x || y < l || y < x) return -1; if (lazy[k] != mp(INF, -INF)) { seg2[k] = max(seg2[k], max(lazy[k].se - seg1[k].fi, seg1[k].se - lazy[k].fi)); prop(l, r, k); } if (x <= l && r <= y) return seg2[k]; int m = (l + r) / 2; return max(qry(l, m, k*2, x, y), qry(m+1, r, k*2+1, x, y)); } void ins(int ind) { int lo = max(1, ind - b[ind]), hi = max(0, ind - a[ind]); for (int nx: arr[0][ind]) upd1(1, n, 1, nx, mp(h[nx], h[nx])); for (int nx: arr[1][ind]) upd1(1, n, 1, nx, mp(INF, -INF)); upd2(1, n, 1, lo, hi, h[ind]); lo = min(n + 1, ind + a[ind]); hi = min(n, ind + b[ind]); arr[0][lo].pb(ind); arr[1][hi + 1].pb(ind); } int main() { int q; ni(n); build(1, n, 1); for (int i = 1; i <= n; i++) scanf("%d %d %d", &h[i], &a[i], &b[i]); ni(q); for (int i = 1; i <= q; i++) { scanf("%d %d", &qr[i].fi.fi, &qr[i].fi.se); qr[i].se = i; } sort(qr+1, qr+1+ q, [](pair<pii,int> l, pair<pii,int> r) { return l.fi.se < r.fi.se; }); int cur = 1; for (int i = 1; i <= q; i++) { while (cur <= qr[i].fi.se) ins(cur++); ans[qr[i].se] = qry(1, n, 1, qr[i].fi.fi, qr[i].fi.se); } for (int i = 1; i <= q; i++) pri(ans[i]); return 0; }

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

antennas.cpp: In function 'int main()':
antennas.cpp:130:40: warning: format '%d' expects argument of type 'int*', but argument 2 has type 'll* {aka long long int*}' [-Wformat=]
   scanf("%d %d %d", &h[i], &a[i], &b[i]);
                     ~~~~~              ^
antennas.cpp:12:34: warning: format '%d' expects argument of type 'int', but argument 2 has type 'll {aka long long int}' [-Wformat=]
 #define pri(n) printf("%d\n", (n))
                               ~~~^
antennas.cpp:146:3: note: in expansion of macro 'pri'
   pri(ans[i]);
   ^~~
antennas.cpp:8:20: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
 #define ni(n) scanf("%d", &(n))
               ~~~~~^~~~~~~~~~~~
antennas.cpp:127:2: note: in expansion of macro 'ni'
  ni(n);
  ^~
antennas.cpp:130:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d %d %d", &h[i], &a[i], &b[i]);
   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
antennas.cpp:8:20: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
 #define ni(n) scanf("%d", &(n))
               ~~~~~^~~~~~~~~~~~
antennas.cpp:131:2: note: in expansion of macro 'ni'
  ni(q);
  ^~
antennas.cpp:133:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d %d", &qr[i].fi.fi, &qr[i].fi.se);
   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...