# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
1092556 | 2024-09-24T11:53:35 Z | Sunbae | Growing Trees (BOI11_grow) | C++17 | 89 ms | 3364 KB |
#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"); } } }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Incorrect | 42 ms | 2128 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 348 KB | Output is correct |
2 | Correct | 1 ms | 348 KB | Output is correct |
3 | Incorrect | 2 ms | 348 KB | Output isn't correct |
4 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Incorrect | 37 ms | 1620 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Incorrect | 24 ms | 1616 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Incorrect | 46 ms | 1872 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Incorrect | 47 ms | 1952 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Incorrect | 37 ms | 2132 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Incorrect | 89 ms | 2696 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Incorrect | 54 ms | 2384 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Incorrect | 79 ms | 3364 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |