답안 #91891

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
91891 2018-12-31T10:02:47 Z easrui Growing Trees (BOI11_grow) C++14
100 / 100
652 ms 3704 KB
#include <bits/stdc++.h>
using namespace std;
const int MAX = 1e5+5;
int N,M,A[MAX],T[4*MAX];

void upt(int l, int r, int st, int en, int pos, int val){
    if(en<l || st>r) return;
    if(l<=st && en<=r){
        T[pos] += val;
        return;
    }
    upt(l,r,st,(st+en)/2,pos*2,val);
    upt(l,r,(st+en)/2+1,en,pos*2+1,val);
}

int get(int x, int st, int en, int pos){
    if(en<x || st>x) return 0;
    if(st==en) return T[pos];
    return T[pos]+get(x,st,(st+en)/2,2*pos)+get(x,(st+en)/2+1,en,2*pos+1);
}

int sear(int h, int st, int en){
    if(st==en) return st;
    if(get((st+en)/2,1,N,1)>=h) return sear(h,st,(st+en)/2);
    else return sear(h,(st+en)/2+1,en);
}

int main()
{
    cin >> N >> M;
    for(int i=1; i<=N; i++) cin >> A[i];
    sort(A+1,A+N+1);
    for(int i=1; i<=N; i++) upt(i,i,1,N,1,A[i]);
    for(int i=0; i<M; i++){
        char O;
        int x,y;
        cin >> O >> x >> y;
        if(O=='F'){
            int a = sear(y,1,N+1);
            if(a+x-1>N) upt(a,N,1,N,1,1);
            else{
                int h = get(a+x-1,1,N,1);
                int b = sear(h,1,N+1);
                upt(a,b-1,1,N,1,1);
                int d = sear(h+1,1,N+1);
                upt(d-a-x+b,d-1,1,N,1,1);
            }
        }
        if(O=='C'){
            cout << sear(y+1,1,N+1)-sear(x,1,N+1) << '\n';
        }
    }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 391 ms 2044 KB Output is correct
2 Correct 570 ms 3356 KB Output is correct
3 Correct 472 ms 3384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 376 KB Output is correct
2 Correct 12 ms 376 KB Output is correct
3 Correct 15 ms 376 KB Output is correct
4 Correct 10 ms 404 KB Output is correct
5 Correct 306 ms 1492 KB Output is correct
6 Correct 398 ms 1660 KB Output is correct
7 Correct 19 ms 504 KB Output is correct
8 Correct 260 ms 1144 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 363 ms 796 KB Output is correct
2 Correct 372 ms 1900 KB Output is correct
3 Correct 7 ms 412 KB Output is correct
4 Correct 306 ms 1400 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 348 ms 820 KB Output is correct
2 Correct 415 ms 1784 KB Output is correct
3 Correct 31 ms 504 KB Output is correct
4 Correct 373 ms 1784 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 398 ms 1540 KB Output is correct
2 Correct 557 ms 3064 KB Output is correct
3 Correct 102 ms 1016 KB Output is correct
4 Correct 366 ms 3136 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 460 ms 1912 KB Output is correct
2 Correct 550 ms 3076 KB Output is correct
3 Correct 466 ms 3420 KB Output is correct
4 Correct 100 ms 1144 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 440 ms 1912 KB Output is correct
2 Correct 405 ms 2992 KB Output is correct
3 Correct 468 ms 3476 KB Output is correct
4 Correct 97 ms 1016 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 589 ms 2068 KB Output is correct
2 Correct 556 ms 3116 KB Output is correct
3 Correct 107 ms 2424 KB Output is correct
4 Correct 460 ms 3064 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 520 ms 2284 KB Output is correct
2 Correct 567 ms 3320 KB Output is correct
3 Correct 643 ms 3704 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 652 ms 2424 KB Output is correct