# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
1092574 | 2024-09-24T12:41:05 Z | Sunbae | Growing Trees (BOI11_grow) | C++17 | 89 ms | 3664 KB |
#include <bits/stdc++.h> #define z exit(0) typedef long long ll; using namespace std; const int N = 1e5 + 5; ll bit[N], a[N]; int n; void upd(int i, ll v){ for(; i<=n; i+=i&-i) bit[i] += v;} int qry(int i){ ll 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);} ll A(int i){ return a[i] + qry(i);} bool V(int i){ return 1 <= i && i <= n;} signed main(){ int q; scanf("%d %d", &n, &q); for(int i = 1; i<=n; ++i) scanf("%lld", a+i); sort(a+1, a+1+n); for(int i = 0, c, h, l, r, L, R; i<q; ++i){ char op; scanf(" %c", &op); if(op == 'F'){ scanf("%d %d", &c, &h); int low = 1, high = n, st = n+1, ed = -1; while(low <= high){ int mid = low + ((high-low)>>1); if(A(mid) >= h) high = mid-1, st = mid; else low = mid+1; } if(st > n) continue; ed = min(n, st+c-1); c = ed-st+1; ll val = A(ed); low = 1; high = ed; l = n+1; r = -1; while(low <= high){ int mid = low + ((high-low)>>1); if(A(mid) < val) low = mid+1; else if(A(mid) == val) high = mid-1, l = mid; } low = ed; high = n; while(low <= high){ int mid = low + ((high-low)>>1); if(A(mid) > val) high = mid-1; else if(A(mid) == val) low = mid+1, r = mid; } if(l > r) continue; L = st; R = l-1; if(V(L) && V(R) && L <= R) UPD(L, R); int rem = c-l+st; L = r - rem + 1; R = r; if(V(L) && V(R) && L <= R) UPD(L, R); }else{ 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) >= l) high = mid-1, L = mid; else low = mid+1; } low = 1; high = n; while(low <= high){ int mid = low + ((high-low)>>1); if(A(mid) <= r) low = mid+1, R = mid; else high = mid-1; } if(L <= R) printf("%d\n", R-L+1); else puts("0"); } } }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 55 ms | 2744 KB | Output is correct |
2 | Correct | 86 ms | 3368 KB | Output is correct |
3 | Correct | 46 ms | 3408 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 348 KB | Output is correct |
2 | Correct | 1 ms | 348 KB | Output is correct |
3 | Correct | 2 ms | 348 KB | Output is correct |
4 | Correct | 1 ms | 348 KB | Output is correct |
5 | Correct | 36 ms | 1396 KB | Output is correct |
6 | Correct | 40 ms | 1576 KB | Output is correct |
7 | Correct | 3 ms | 604 KB | Output is correct |
8 | Correct | 20 ms | 1140 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 35 ms | 852 KB | Output is correct |
2 | Correct | 43 ms | 1876 KB | Output is correct |
3 | Correct | 1 ms | 344 KB | Output is correct |
4 | Correct | 26 ms | 1356 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 36 ms | 900 KB | Output is correct |
2 | Correct | 44 ms | 1820 KB | Output is correct |
3 | Correct | 5 ms | 608 KB | Output is correct |
4 | Correct | 42 ms | 1740 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 59 ms | 1624 KB | Output is correct |
2 | Correct | 80 ms | 2904 KB | Output is correct |
3 | Correct | 13 ms | 1128 KB | Output is correct |
4 | Correct | 34 ms | 2824 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 67 ms | 1656 KB | Output is correct |
2 | Correct | 81 ms | 3072 KB | Output is correct |
3 | Correct | 42 ms | 3120 KB | Output is correct |
4 | Correct | 13 ms | 1112 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 53 ms | 1876 KB | Output is correct |
2 | Correct | 58 ms | 3152 KB | Output is correct |
3 | Correct | 46 ms | 3196 KB | Output is correct |
4 | Correct | 14 ms | 1112 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 89 ms | 1876 KB | Output is correct |
2 | Correct | 83 ms | 2900 KB | Output is correct |
3 | Correct | 22 ms | 2652 KB | Output is correct |
4 | Correct | 44 ms | 2900 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 71 ms | 1924 KB | Output is correct |
2 | Correct | 85 ms | 3408 KB | Output is correct |
3 | Correct | 83 ms | 3664 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 87 ms | 2412 KB | Output is correct |