Submission #1092556

#TimeUsernameProblemLanguageResultExecution timeMemory
1092556SunbaeGrowing Trees (BOI11_grow)C++17
0 / 100
89 ms3364 KiB
#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 (stderr)

grow.cpp: In function 'int main()':
grow.cpp:10:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   10 |  int q; scanf("%d %d", &n, &q);
      |         ~~~~~^~~~~~~~~~~~~~~~~
grow.cpp:11:33: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   11 |  for(int i = 1; i<=n; ++i) scanf("%d", a+i);
      |                            ~~~~~^~~~~~~~~~~
grow.cpp:15:17: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   15 |   char op; scanf(" %c", &op);
      |            ~~~~~^~~~~~~~~~~~
grow.cpp:17:19: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   17 |    int c, h; scanf("%d %d", &c, &h);
      |              ~~~~~^~~~~~~~~~~~~~~~~
grow.cpp:43:19: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   43 |    int l, r; scanf("%d %d", &l, &r);
      |              ~~~~~^~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...