Submission #520829

#TimeUsernameProblemLanguageResultExecution timeMemory
520829byunjaewooPyramid Base (IOI08_pyramid_base)C++17
70 / 100
1331 ms37216 KiB
/// B>0 #include <bits/stdc++.h> using namespace std; using ll=long long; const int Nmax=30010, S=(1<<20); int N, M, B, P, ans; int C[Nmax]; struct Rectangle {int sx, ex, sy, ey;}A[Nmax], t[Nmax]; struct Line {int x, sy, ey, k;}; class LazyPropagation { public: void Update(int l, int r, ll v) {Update(1, 1, S, l, r, v);} ll Query(int l, int r) {return Query(1, 1, S, l, r);} void init() {fill(Tree, Tree+2*S, 0); fill(Lazy, Lazy+2*S, 0);} private: ll Tree[2*S], Lazy[2*S]; void Propagate(int node, int s, int e) { Tree[node]+=Lazy[node]; if(s!=e) { Lazy[2*node]+=Lazy[node]; Lazy[2*node+1]+=Lazy[node]; } Lazy[node]=0; return; } void Update(int node, int s, int e, int l, int r, int v) { Propagate(node, s, e); if(l>e || s>r) return; if(l<=s && e<=r) { Lazy[node]+=v; Propagate(node, s, e); return; } int lch=2*node, rch=lch+1, m=s+e>>1; Update(lch, s, m, l, r, v); Update(rch, m+1, e, l, r, v); Tree[node]=min(Tree[lch], Tree[rch]); } ll Query(int node, int s, int e, int l, int r) { Propagate(node, s, e); if(l>e || s>r) return INT_MAX; if(l<=s && e<=r) return Tree[node]; int lch=2*node, rch=lch+1, m=s+e>>1; return min(Query(lch, s, m, l, r), Query(rch, m+1, e, l, r)); } }T; bool chk(int x) { vector<Line> V; for(int i=1; i<=P; i++) { t[i]=A[i]; t[i].sx=max(1, A[i].sx-x+1); t[i].sy=max(1, A[i].sy-x+1); V.push_back({t[i].sx, t[i].sy, t[i].ey, C[i]}); V.push_back({t[i].ex+1, t[i].sy, t[i].ey, -C[i]}); } V.push_back({1, 0, 0, 0}); sort(V.begin(), V.end(), [](Line a, Line b) {return a.x<b.x;}); T.init(); for(int i=0; i<V.size(); i++) { if(V[i].x>N-x+1) break; T.Update(V[i].sy, V[i].ey, V[i].k); int j; for(j=i+1; j<V.size() && V[i].x==V[j].x; j++) T.Update(V[j].sy, V[j].ey, V[j].k); if(T.Query(1, M-x+1)<=B) return true; i=j-1; } return false; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cin>>N>>M>>B>>P; for(int i=1; i<=P; i++) { cin>>A[i].sx>>A[i].sy>>A[i].ex>>A[i].ey>>C[i]; } for(int s=1, e=1000000; s<=e;) { int mid=(s+e)/2; if(chk(mid)) ans=mid, s=mid+1; else e=mid-1; } cout<<ans; return 0; }

Compilation message (stderr)

pyramid_base.cpp: In member function 'void LazyPropagation::Update(int, int, int, int, int, int)':
pyramid_base.cpp:36:39: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   36 |         int lch=2*node, rch=lch+1, m=s+e>>1;
      |                                      ~^~
pyramid_base.cpp: In member function 'll LazyPropagation::Query(int, int, int, int, int)':
pyramid_base.cpp:44:39: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   44 |         int lch=2*node, rch=lch+1, m=s+e>>1;
      |                                      ~^~
pyramid_base.cpp: In function 'bool chk(int)':
pyramid_base.cpp:61:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<Line>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   61 |     for(int i=0; i<V.size(); i++) {
      |                  ~^~~~~~~~~
pyramid_base.cpp:65:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<Line>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   65 |         for(j=i+1; j<V.size() && V[i].x==V[j].x; j++)
      |                    ~^~~~~~~~~
#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...