Submission #914595

# Submission time Handle Problem Language Result Execution time Memory
914595 2024-01-22T11:11:28 Z abcvuitunggio Pyramid Base (IOI08_pyramid_base) C++17
100 / 100
1149 ms 93768 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;
        return 0;
    }
    int r=0,mx=0;
    build(1,1,n);
    for (int i=1;i<=m;i++){
        while (r<=m&&(st[1][3]?0:st[1][0])>=r-i+1){
            r++;
            if (r>m)
                break;
            for (int i:ve[r])
                if (i>0)
                    update2(1,1,n,y[i],v[i],1);
        }
        mx=max(mx,max(r-i,(r>m||st[1][3]?0:st[1][0])));
        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 9 ms 35164 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 10 ms 35160 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 35164 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 11 ms 35516 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 13 ms 41732 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 31 ms 76380 KB Output is correct
2 Correct 27 ms 76380 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 25 ms 72540 KB Output is correct
2 Correct 29 ms 75356 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 16 ms 35420 KB Output is correct
2 Correct 37 ms 35656 KB Output is correct
3 Correct 38 ms 35688 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 97 ms 39656 KB Output is correct
2 Correct 190 ms 40528 KB Output is correct
3 Correct 150 ms 40312 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 316 ms 67572 KB Output is correct
2 Correct 83 ms 41216 KB Output is correct
3 Correct 132 ms 62916 KB Output is correct
4 Correct 522 ms 71896 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 487 ms 70136 KB Output is correct
2 Correct 937 ms 73232 KB Output is correct
3 Correct 230 ms 66388 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 405 ms 68556 KB Output is correct
2 Correct 1061 ms 75516 KB Output is correct
3 Correct 1041 ms 75176 KB Output is correct
4 Correct 1058 ms 75796 KB Output is correct
5 Correct 1149 ms 76068 KB Output is correct
6 Correct 204 ms 66168 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 475 ms 87168 KB Output is correct
2 Correct 211 ms 47700 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 583 ms 90456 KB Output is correct
2 Correct 667 ms 88648 KB Output is correct
3 Correct 421 ms 81596 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 703 ms 86292 KB Output is correct
2 Correct 1062 ms 93720 KB Output is correct
3 Correct 1049 ms 93768 KB Output is correct
4 Correct 940 ms 91656 KB Output is correct
5 Correct 584 ms 86992 KB Output is correct