답안 #914594

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
914594 2024-01-22T11:11:06 Z abcvuitunggio Pyramid Base (IOI08_pyramid_base) C++17
30 / 100
1081 ms 113356 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 (p<=30000){
        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]?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)
      |             ~~~~^~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 10 ms 37208 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 10 ms 37392 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 11 ms 37208 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 14 ms 37720 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 27 ms 46416 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 157 ms 105552 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 226 ms 101712 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 16 ms 37724 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 125 ms 47952 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 347 ms 110236 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 531 ms 113356 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 489 ms 110876 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 459 ms 87168 KB Output is correct
2 Correct 221 ms 48064 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 656 ms 90452 KB Output is correct
2 Correct 718 ms 88312 KB Output is correct
3 Correct 441 ms 81708 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 708 ms 86252 KB Output is correct
2 Correct 1081 ms 93720 KB Output is correct
3 Correct 1047 ms 93732 KB Output is correct
4 Correct 942 ms 91560 KB Output is correct
5 Correct 615 ms 87236 KB Output is correct