| # | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
|---|---|---|---|---|---|---|---|
| 1092556 | Sunbae | Growing Trees (BOI11_grow) | C++17 | 89 ms | 3364 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define z exit(0)
using namespace std;
const int N = 1e5 + 5;
int bit[N], a[N], n;
void upd(int i, int v){ for(; i<=n; i+=i&-i) bit[i] += v;}
int qry(int i){ int r = 0; for(; i; i-=i&-i) r += bit[i]; return r;}
void UPD(int l, int r){ upd(l, +1); upd(r+1, -1);}
signed main(){
int q; scanf("%d %d", &n, &q);
for(int i = 1; i<=n; ++i) scanf("%d", a+i);
//1 2 2 3 5
sort(a+1, a+1+n);
for(int i = 0; i<q; ++i){
char op; scanf(" %c", &op);
if(op == 'F'){
int c, h; scanf("%d %d", &c, &h);
int low = 1, high = n, st = -1;
while(low <= high){
int mid = low + ((high-low)>>1);
if(a[mid] + qry(mid) >= h) st = mid, high = mid-1;
else low = mid+1;
}
if(st < 0) continue;
int j = min(n, st+c-1), val = a[j] + qry(j), idx[2] = {-1, -1};
low = st; high = n;
while(low <= high){
int mid = low + ((high-low)>>1);
if(a[mid] + qry(mid) >= val) idx[0] = mid, high = mid-1;
else low = mid+1;
}
low = idx[0]; high = n;
while(low <= high){
int mid = low + ((high-low)>>1);
if(a[mid] + qry(mid) <= val) idx[1] = mid, low = mid+1;
else high = mid-1;
}
if(max(idx[0], idx[1]) < 0 || a[idx[0]] + qry(idx[0]) != val) continue;
if(st <= idx[0]-1) UPD(st, idx[0]-1);
int rem = c-(idx[0]-st);
if(idx > 0 && rem > 0 && idx[1]-rem+1 <= idx[1]) UPD(idx[1]-rem+1, idx[1]);
}else{
int l, r; scanf("%d %d", &l, &r);
int low = 1, high = n, L = n+1, R = -1;
while(low <= high){
int mid = low + ((high-low)>>1);
if(a[mid] + qry(mid) >= l) L = mid, high = mid-1;
else low = mid+1;
}
low = 1; high = n;
while(low <= high){
int mid = low + ((high-low)>>1);
if(a[mid] + qry(mid) <= r) R = mid, low = mid+1;
else high = mid-1;
}
if(L <= R) printf("%d\n", R-L+1);
else puts("0");
}
}
}
컴파일 시 표준 에러 (stderr) 메시지
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
