답안 #965593

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
965593 2024-04-19T02:00:24 Z idiotcomputer Pyramid Base (IOI08_pyramid_base) C++11
100 / 100
4663 ms 26988 KB
#include <bits/stdc++.h>
using namespace std;
#define pii pair<int,int>
#define f first
#define s second 
#define ll long long int 

const int mxP = 4e5;
const int mxN = 1e6;
int n,m;

int segtree[4*mxN+1];
int laz[4*mxN+1];
int curr;

void build(int l = 0, int r = n-1, int idx = 0){
    if (r+1<curr){
        segtree[idx] = 2e9+1;
        laz[idx] = 0;
        return;
    }
    segtree[idx] = 0;
    laz[idx] = 0;
    if (l == r) return;
    int m = (l+r)/2;
    build(l,m,2*idx+1);
    build(m+1,r,2*idx+2);
}

void upd(int tl, int tr, int v, int l = 0, int r = n-1, int idx = 0){
    if (l > tr || r < tl || r+1<curr) return;
    if (l >= tl && r <= tr){
        laz[idx] += v;
        return;
    }
    int m = (l+r)/2;
    upd(tl,tr,v,l,m,2*idx+1);
    upd(tl,tr,v,m+1,r,2*idx+2);
    segtree[idx] = min(segtree[2*idx+1]+laz[2*idx+1],segtree[2*idx+2]+laz[2*idx+2]);
}

void build1(int l = 0, int r = n-1, int idx = 0){
    if (r+1<curr){
        segtree[idx] = m+1;
        laz[idx] = m+1;
        return;
    }
    segtree[idx] = 0;
    laz[idx] = 0;
    if (l == r) return;
    int m = (l+r)/2;
    build1(l,m,2*idx+1);
    build1(m+1,r,2*idx+2);
}
 
void upd1(int tl, int tr, int v, int l = 0, int r = n-1, int idx = 0){
    if (l > tr || r < tl || r+1<curr) return;
    if (l >= tl && r <= tr){
        laz[idx] = max(laz[idx],v);
        return;
    }
    laz[2*idx+1] = max(laz[idx],laz[2*idx+1]);
    laz[2*idx+2] = max(laz[idx],laz[2*idx+2]);
    laz[idx] = 0;
    int m = (l+r)/2;
    upd1(tl,tr,v,l,m,2*idx+1);
    upd1(tl,tr,v,m+1,r,2*idx+2);
    segtree[idx] = min(max(segtree[2*idx+1],laz[2*idx+1]),max(segtree[2*idx+2],laz[2*idx+2]));
}

void solve(int b, int p){
    int r[p];
    pii y[p];
    vector<pii> vals(p);
    int x1,y1,x2,y2,c1;
    for (int i =0; i < p; i++){
        cin >> x1 >> y1 >> x2 >> y2 >> c1;
        x1 -= 1;
        y1 -= 1;
        x2 -= 1;
        y2 -= 1;
        r[i] = x2;
        y[i] = {y1,y2};
        vals[i] = {x1,i};
    }
    sort(vals.begin(),vals.end());
    
    int start = 0;
    int end = min(n,m)+1;
    bool w;
    int best;
    while (end - start > 1){
        curr = (start+end)/2;
        build1();
        w = false;
        for (int i = 0; i < p; i++){
            best = max(laz[0],segtree[0]);
            if (vals[i].f-best >= curr){
                w = true;
                break;
            }
            upd1(y[vals[i].s].f,min(n-1,y[vals[i].s].s+curr-1),r[vals[i].s]+1);
        }
        best = max(laz[0],segtree[0]);
        if (m-best >= curr) w = true;
        if (w) start = curr;
        else end = curr;
    }
    cout << start << "\n";
    return;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    int b;
    int p;
    cin >> m >> n >> b >> p;
    if (b == 0){
        solve(b,p);
        return 0;
    }
    
    pii x[p];
    pii y[p];
    int c[p];
    int x1,y1,x2,y2,c1;
    for (int i =0; i < p; i++){
        cin >> x1 >> y1 >> x2 >> y2 >> c1;
        x1 -= 1;
        y1 -= 1;
        x2 -= 1;
        y2 -= 1;
        x[i] = {x1,x2};
        y[i] = {y1,y2};
        c[i] = c1;
    }

    int start = 0;
    int end = min(n,m)+1;
    bool w;
    int best;
    bool vis[p];
    int last;
    while (end - start > 1){
        curr = (start+end)/2;
        build();
        memset(vis,0,sizeof(vis));
        priority_queue<pii, vector<pii>, greater<pii>> queue;
        for (int i = 0; i < p; i++){
            queue.push({x[i].f,i});
            queue.push({x[i].s+curr,i});
        }
        w = false;
        last = -1;
        while (queue.size() > 0){
            pii cur = queue.top();
            queue.pop();
            if (cur.f >= m) break;
            
            best = laz[0]+segtree[0];
            if (last != cur.f && best <= b && cur.f >= curr){
                w = true;
                break;
            }
            last = cur.f;
            int val = c[cur.s];
            if (vis[cur.s]) val *= -1;
            else vis[cur.s] = 1;
            upd(y[cur.s].f,min(n-1,y[cur.s].s+curr-1),val);
        }
        best = laz[0]+segtree[0];
        if (best <= b) w = true;
        if (w) start = curr;
        else end = curr;
    }
    cout << start << "\n";
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2392 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2392 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2396 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 2652 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 13 ms 6748 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 23 ms 19032 KB Output is correct
2 Correct 89 ms 19036 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 94 ms 19100 KB Output is correct
2 Correct 36 ms 18780 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 2920 KB Output is correct
2 Correct 40 ms 2956 KB Output is correct
3 Correct 36 ms 3176 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 122 ms 7560 KB Output is correct
2 Correct 211 ms 7572 KB Output is correct
3 Correct 176 ms 7572 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 174 ms 20204 KB Output is correct
2 Correct 20 ms 3744 KB Output is correct
3 Correct 132 ms 20448 KB Output is correct
4 Correct 290 ms 20312 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 283 ms 20464 KB Output is correct
2 Correct 560 ms 20820 KB Output is correct
3 Correct 135 ms 20460 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 245 ms 20592 KB Output is correct
2 Correct 714 ms 20936 KB Output is correct
3 Correct 676 ms 20736 KB Output is correct
4 Correct 734 ms 20776 KB Output is correct
5 Correct 804 ms 20632 KB Output is correct
6 Correct 121 ms 20572 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1859 ms 23188 KB Output is correct
2 Correct 180 ms 10760 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2857 ms 25108 KB Output is correct
2 Correct 2679 ms 24960 KB Output is correct
3 Correct 1945 ms 24772 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3291 ms 26960 KB Output is correct
2 Correct 4411 ms 26964 KB Output is correct
3 Correct 4663 ms 26912 KB Output is correct
4 Correct 3798 ms 26880 KB Output is correct
5 Correct 2937 ms 26988 KB Output is correct