Submission #217866

#TimeUsernameProblemLanguageResultExecution timeMemory
217866arnold518Pyramid Base (IOI08_pyramid_base)C++14
51 / 100
5083 ms111520 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; const int MAXN = 1e6; const int MAXP = 4e5; const ll INF = 1e18; struct Rect { int x1, y1, x2, y2, w; }; struct Line { int x, y1, y2, w; bool operator < (const Line &p) const { return x<p.x; } }; int N, M, P; ll B; Rect A[MAXP+10]; struct SEG { ll tree[MAXN*4+10], lazy[MAXN*4+10]; void init() { memset(tree, 0, sizeof(tree)); memset(lazy, 0, sizeof(lazy)); } void busy(int node, int tl, int tr) { tree[node]+=lazy[node]; if(tl!=tr) lazy[node*2]+=lazy[node], lazy[node*2+1]+=lazy[node]; lazy[node]=0; } void update(int node, int tl, int tr, int l, int r, ll v) { busy(node, tl, tr); if(r<tl || tr<l) return; if(l<=tl && tr<=r) { lazy[node]+=v; busy(node, tl, tr); return; } int mid=tl+tr>>1; update(node*2, tl, mid, l, r, v); update(node*2+1, mid+1, tr, l, r, v); tree[node]=min(tree[node*2], tree[node*2+1]); } }seg; bool solve(int d) { int i, j; vector<Line> V; ll val=INF; for(i=1; i<=P; i++) { V.push_back({A[i].x1, A[i].y1, A[i].y2+d-1, A[i].w}); V.push_back({A[i].x2+d, A[i].y1, A[i].y2+d-1, -A[i].w}); } sort(V.begin(), V.end()); seg.init(); for(i=0; i<V.size();) { int x=V[i].x; for(; i<V.size() && V[i].x==x; i++) { seg.update(1, d, N, V[i].y1, V[i].y2, V[i].w); } seg.busy(1, d, N); if(x>=d && x<=M) val=min(val, seg.tree[1]); } if(val<=B) return true; return false; } int main() { int i, j; scanf("%d%d%lld%d", &M, &N, &B, &P); for(i=1; i<=P; i++) scanf("%d%d%d%d%d", &A[i].x1, &A[i].y1, &A[i].x2, &A[i].y2, &A[i].w); int lo=0, hi=min(N, M)+1; while(lo+1<hi) { int mid=lo+hi>>1; if(solve(mid)) lo=mid; else hi=mid; } printf("%d\n", lo); }

Compilation message (stderr)

pyramid_base.cpp: In member function 'void SEG::update(int, int, int, int, int, ll)':
pyramid_base.cpp:51:13: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   int mid=tl+tr>>1;
           ~~^~~
pyramid_base.cpp: In function 'bool solve(int)':
pyramid_base.cpp:71:12: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(i=0; i<V.size();)
           ~^~~~~~~~~
pyramid_base.cpp:74:10: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(; i<V.size() && V[i].x==x; i++)
         ~^~~~~~~~~
pyramid_base.cpp:60:9: warning: unused variable 'j' [-Wunused-variable]
  int i, j;
         ^
pyramid_base.cpp: In function 'int main()':
pyramid_base.cpp:95:13: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   int mid=lo+hi>>1;
           ~~^~~
pyramid_base.cpp:87:9: warning: unused variable 'j' [-Wunused-variable]
  int i, j;
         ^
pyramid_base.cpp:89:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d%d%lld%d", &M, &N, &B, &P);
  ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
pyramid_base.cpp:90:27: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  for(i=1; i<=P; i++) scanf("%d%d%d%d%d", &A[i].x1, &A[i].y1, &A[i].x2, &A[i].y2, &A[i].w);
                      ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...