Submission #914589

# Submission time Handle Problem Language Result Execution time Memory
914589 2024-01-22T11:06:36 Z abcvuitunggio Pyramid Base (IOI08_pyramid_base) C++17
45 / 100
849 ms 113408 KB
#include <bits/stdc++.h>
using namespace std;
const int M=1000001,P=400001;
int m,n,b,p,x[P],y[P],u[P],v[P],c[P];
unsigned int t[M*4],sum[M*4];
vector <int> ve[M+1];
void update(int node, int l, int r, int u, int v, int val){
    if (l>v||r<u)
        return;
    if (l>=u&&r<=v){
        t[node]+=val;
        sum[node]+=val;
        return;
    }
    int mid=(l+r)>>1;
    update(node<<1,l,mid,u,v,val);
    update(node<<1|1,mid+1,r,u,v,val);
    t[node]=min(t[node<<1],t[node<<1|1])+sum[node];
}
bool check(int sz){
    for (int i=1;i<=m+1;i++)
        ve[i].clear();
    for (int i=1;i<=n*4;i++)
        t[i]=sum[i]=0;
    for (int i=1;i<=p;i++){
        int X=max(x[i]-sz+1,1);
        ve[X].push_back(i);
        ve[u[i]+1].push_back(-i);
    }
    for (int i=1;i<=m-sz+1;i++){
        for (int j:ve[i])
            update(1,1,n-sz+1,max(y[abs(j)]-sz+1,1),v[abs(j)],c[abs(j)]*(j<0?-1:1));
        if (t[1]<=b)
            return true;
    }
    return false;
}
int st[M*4][4],lazy[M*4];
void build(int node, int l, int r){
    st[node][0]=st[node][1]=st[node][2]=r-l+1;
    if (l==r)
        return;
    int mid=(l+r)>>1;
    build(node<<1,l,mid);
    build(node<<1|1,mid+1,r);
}
void update2(int node, int l, int r, int u, int v, int val){
    if (l>v||r<u)
        return;
    if (l>=u&&r<=v){
        st[node][3]+=val;
        lazy[node]+=val;
        return;
    }
    int mid=(l+r)>>1;
    update2(node<<1,l,mid,u,v,val);
    update2(node<<1|1,mid+1,r,u,v,val);
    int x=node<<1,y=node<<1|1;
    st[node][3]=min(st[x][3],st[y][3])+lazy[node];
    if (st[x][3]!=st[y][3]){
        int z=(st[x][3]<st[y][3]?x:y);
        for (int i=0;i<3;i++)
            st[node][i]=st[z][i];
        if (z==x)
            st[node][2]=0;
        else
            st[node][1]=0;
    }
    else{
        st[node][0]=max(max(st[x][0],st[y][0]),st[x][2]+st[y][1]);
        st[node][1]=st[x][1]+(st[x][1]==mid-l+1)*st[y][1];
        st[node][2]=st[y][2]+(st[y][2]==r-mid)*st[x][2];
    }
}
int main(){
    ios_base::sync_with_stdio(NULL);cin.tie(nullptr);
    cin >> m >> n >> b >> p;
    for (int i=1;i<=p;i++){
        cin >> x[i] >> y[i] >> u[i] >> v[i] >> c[i];
        ve[x[i]].push_back(i);
        ve[u[i]].push_back(-i);
    }
    if (b){
        int l=1,r=min(m,n),kq=0;
        while (l<=r){
            int mid=(l+r)>>1;
            if (check(mid)){
                kq=mid;
                l=mid+1;
            }
            else
                r=mid-1;
        }
        cout << kq;
    }
    int r=0,mx=0;
    build(1,1,n);
    for (int i=1;i<=m;i++){
        while (r<=m&&!st[1][3]&&st[1][0]>=r-i+1){
            r++;
            for (int i:ve[r])
                if (i>0)
                    update2(1,1,n,y[i],v[i],1);
        }
        mx=max(mx,r-i);
        for (int j:ve[i])
            if (j<0)
                update2(1,1,n,y[-j],v[-j],-1);
    }
    cout << mx;
}

Compilation message

pyramid_base.cpp: In function 'bool check(int)':
pyramid_base.cpp:33:17: warning: comparison of integer expressions of different signedness: 'unsigned int' and 'int' [-Wsign-compare]
   33 |         if (t[1]<=b)
      |             ~~~~^~~
# Verdict Execution time Memory Grader output
1 Correct 10 ms 35160 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 10 ms 35340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 11 ms 35164 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 11 ms 35420 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 13 ms 41652 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 31 ms 76380 KB Output is correct
2 Correct 27 ms 76452 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 26 ms 72600 KB Output is correct
2 Correct 29 ms 75348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 19 ms 37724 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 124 ms 47800 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 371 ms 110480 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 597 ms 113408 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 467 ms 110896 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 528 ms 87168 KB Output is correct
2 Correct 285 ms 51908 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 678 ms 90460 KB Output is correct
2 Incorrect 582 ms 96632 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 770 ms 86128 KB Output is correct
2 Correct 834 ms 104864 KB Output is correct
3 Incorrect 849 ms 104776 KB Output isn't correct
4 Halted 0 ms 0 KB -