답안 #965591

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

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

ll segtree[4*mxN+1];
ll 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, ll 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]);
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    ll b;
    int p;
    cin >> m >> n >> b >> p;
    
    
    pii x[p];
    pii y[p];
    ll c[p];
    ll 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;
    ll 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;
            ll val = c[cur.s];
            if (vis[cur.s]) val *= -1;
            else vis[cur.s] = 1;
            upd(y[cur.s].f,min((ll) 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 2396 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2396 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 2396 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 4700 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 15 ms 6748 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 26 ms 31324 KB Output is correct
2 Correct 102 ms 35600 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 108 ms 35420 KB Output is correct
2 Correct 36 ms 31320 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 14 ms 5300 KB Output is correct
2 Correct 43 ms 5492 KB Output is correct
3 Correct 36 ms 5472 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 130 ms 8592 KB Output is correct
2 Correct 223 ms 8348 KB Output is correct
3 Correct 192 ms 8380 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 215 ms 33832 KB Output is correct
2 Correct 21 ms 5292 KB Output is correct
3 Correct 173 ms 38272 KB Output is correct
4 Correct 367 ms 38700 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 361 ms 38268 KB Output is correct
2 Correct 664 ms 39040 KB Output is correct
3 Correct 153 ms 34920 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 286 ms 34728 KB Output is correct
2 Correct 905 ms 39772 KB Output is correct
3 Correct 819 ms 39556 KB Output is correct
4 Correct 884 ms 39772 KB Output is correct
5 Correct 903 ms 39556 KB Output is correct
6 Correct 166 ms 35436 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 5040 ms 59192 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 5059 ms 74836 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 5040 ms 81040 KB Time limit exceeded
2 Halted 0 ms 0 KB -