Submission #391096

# Submission time Handle Problem Language Result Execution time Memory
391096 2021-04-17T20:29:04 Z IloveN Pyramid Base (IOI08_pyramid_base) C++14
80 / 100
5000 ms 94584 KB
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("avx2")
#include<bits/stdc++.h>

using namespace std;
#define ll long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define all(vr) vr.begin(),vr.end()
#define vi vector<int>
#define vll vector<ll>
#define ui unsigned int
const int N=1e6+10;

struct segment_tree
{
    int t[N*2],d[N*2],n;

    void build(int p) {
      while (p > 1) p >>= 1, t[p] = min(t[p<<1], t[p<<1|1]) + d[p];
    }

    void upd(int l, int r, int value) {
      l += n - 1, r += n;
      int l0 = l, r0 = r;
      for (; l < r; l >>= 1, r >>= 1) {
        if (l&1) {
            t[l] += value;
            d[l++] += value;
        }
        if (r&1) {
            t[--r] += value;
            d[r] += value;
        }
      }
      build(l0);
      build(r0 - 1);
    }

    int get() { return t[1];}

    void init(int x)
    {
        n=x;
        memset(t,0,sizeof(t));
        memset(d,0,sizeof(d));
    }
} seg;

struct obs{int x1,x2,y1,y2,c;};
obs a[N];
int n,m,B,p;

struct event{int l,r,x;};
vector<event> vt[N];

bool check(int l)
{
    for (int i=1;i<=m;i++) vt[i].clear();
    for (int i=1;i<=p;i++)
    {
        int x1=max(a[i].x1-l+1,1);
        int y1=max(a[i].y1-l+1,1);
        int x2=min(a[i].x2,m-l+1);
        int y2=min(a[i].y2,n-l+1);
        if (x1>x2 || y1>y2) continue;
        int c=a[i].c;
        vt[x1].pb({y1,y2,c});
        vt[x2+1].pb({y1,y2,-c});
    }
    seg.init(n-l+1);
    for (int i=1;i<=m-l+1;i++)
    {
        for (event e : vt[i]) seg.upd(e.l,e.r,e.x);
        if (seg.get()<=B) return true;
    }
    return false;
}

int main()
{
    //freopen("ss.inp","r",stdin);
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin>>m>>n>>B>>p;
    for (int i=1;i<=p;i++) cin>>a[i].x1>>a[i].y1>>a[i].x2>>a[i].y2>>a[i].c,a[i].c=min(a[i].c,B+1);
    int l=1,r=min(m,n),ans=0;
    while (l<=r)
    {
        int mid=(l+r)/2;
        if (check(mid)) ans=mid,l=mid+1;
        else r=mid-1;
    }
    cout<<ans;
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 30 ms 39424 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 29 ms 39448 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 42 ms 39516 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 51 ms 40004 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 64 ms 39832 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 106 ms 39944 KB Output is correct
2 Correct 162 ms 40012 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 168 ms 39972 KB Output is correct
2 Correct 116 ms 39844 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 55 ms 40640 KB Output is correct
2 Correct 77 ms 40112 KB Output is correct
3 Correct 69 ms 40256 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 181 ms 43076 KB Output is correct
2 Correct 244 ms 42876 KB Output is correct
3 Correct 213 ms 43288 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 315 ms 47252 KB Output is correct
2 Correct 119 ms 44288 KB Output is correct
3 Correct 131 ms 42112 KB Output is correct
4 Correct 487 ms 49544 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 496 ms 49860 KB Output is correct
2 Correct 830 ms 51332 KB Output is correct
3 Correct 246 ms 47372 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 405 ms 50084 KB Output is correct
2 Correct 1057 ms 53752 KB Output is correct
3 Correct 995 ms 53320 KB Output is correct
4 Correct 1060 ms 54052 KB Output is correct
5 Correct 1129 ms 53764 KB Output is correct
6 Correct 227 ms 48220 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4507 ms 80480 KB Output is correct
2 Correct 1228 ms 74388 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 5044 ms 87684 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 5056 ms 94584 KB Time limit exceeded
2 Halted 0 ms 0 KB -