Submission #1092556

# Submission time Handle Problem Language Result Execution time Memory
1092556 2024-09-24T11:53:35 Z Sunbae Growing Trees (BOI11_grow) C++17
0 / 100
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

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 time Memory Grader output
1 Incorrect 42 ms 2128 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory 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 -
# Verdict Execution time Memory Grader output
1 Incorrect 37 ms 1620 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 24 ms 1616 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 46 ms 1872 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 47 ms 1952 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 37 ms 2132 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 89 ms 2696 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 54 ms 2384 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 79 ms 3364 KB Output isn't correct
2 Halted 0 ms 0 KB -