답안 #791916

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
791916 2023-07-24T12:32:12 Z Trent Growing Trees (BOI11_grow) C++17
0 / 100
1000 ms 46504 KB
#include "bits/stdc++.h"

using namespace std;
#define forR(i, a) for(int i=0; (i) < (a); ++(i))
#define REP(i, a, b) for(int i=(a); (i) < (b); ++(i))
#define open(x) freopen(((string) x + ".in").c_str(), "r", stdin); freopen(((string) x + ".out").c_str(), "w", stdout);
#define boost() cin.sync_with_stdio(0); cin.tie(0)
#define all(a) (a).begin(), (a).end()
typedef long long ll;

const int MN = 1e5 + 10, ME = 4 * MN, INF=1e8;

struct node{
    int l, r, lz;
};
node seg[ME];
int a[MN];
void push(int v){
    if(2*v+1 < ME){
        seg[2*v].l += seg[v].lz;
        seg[2*v+1].l += seg[v].lz;
        seg[2*v].r += seg[v].lz;
        seg[2*v+1].r += seg[v].lz;
        seg[2*v].lz += seg[v].lz;
        seg[2*v+1].lz += seg[v].lz;
        seg[v].lz = 0;
    }
}
void up(int v){
    seg[v].l = seg[2*v].l;
    seg[v].r = seg[2*v+1].r;
}
void build(int v, int nl, int nr){
    if(nl > nr) return;
    else if(nl == nr) seg[v] = {a[nl], a[nr], 0};
    else {
        int mid = (nl + nr) / 2;
        build(2*v, nl, mid);
        build(2*v+1, mid+1, nr);
        up(v);
    }
}
int las(int v, int nl, int nr, int val){
    push(v);
    if(seg[v].l >= val){
        throw;
    }
    if(nl == nr) return nl;
    else {
        int mid = (nl + nr) / 2;
        if(seg[2*v+1].l < val) return las(2*v+1, mid+1, nr, val);
        else return las(2*v, nl, mid, val);
    }
}
void upd(int v, int nl, int nr, int l, int r){
    push(v);
    if(l > r) return;
    else if(nl == l && nr == r){
        seg[v].l += 1;
        seg[v].r += 1;
        seg[v].lz += 1;
    } else {
        int mid = (nl + nr) / 2;
        upd(2*v, nl, mid, l, min(r, mid));
        upd(2*v+1, mid+1, nr, max(mid+1, l), r);
        up(v);
    }
}
int val(int v, int nl, int nr, int i){
    push(v);
    if(nl == i && nr == i) return seg[v].l;
    else {
        int mid = (nl + nr) / 2;
        if(i <= mid) return val(2*v, nl, mid, i);
        else return val(2*v+1, mid+1, nr, i);
    }
}

signed main(){
    int n, m; cin >> n >> m;
    REP(i, 1, n + 1) cin >> a[i];
    sort(a+1, a+n+1);
    a[0] = -INF;
    build(1,0,n);
    forR(g, m){
        char ins; int p, q;
        cin >> ins >> p >> q;
        if(ins == 'F'){
            int st=las(1,0,n,q)+1;
            if(st > n) continue;
            int fi=min(n, st+p-1);
            int fv=val(1,0,n,fi);
            int j=las(1,0,n,fv);
            // take st...j
            int ex = fi-j;
            int en=las(1,0,n,fv+1);
            // take en-ex+1...en
            upd(1,0,n,st,j);
            upd(1,0,n,en-ex+1,en);
        } else {
            int lef=las(1, 0, n, p)+1, rig=las(1,0,n, q+1);
            cout << rig - lef + 1 << '\n';
        }
        REP(i, 1, n + 1) cout << val(1,0,n,i) << ' ';
        cout << '\n';
    }
}
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1073 ms 33252 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 290 ms 6840 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1077 ms 28348 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1066 ms 24276 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1058 ms 30384 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1034 ms 31680 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1065 ms 24160 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1059 ms 46504 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1077 ms 32656 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1069 ms 45900 KB Time limit exceeded
2 Halted 0 ms 0 KB -