Submission #972643

# Submission time Handle Problem Language Result Execution time Memory
972643 2024-04-30T19:19:15 Z c2zi6 Growing Trees (BOI11_grow) C++14
0 / 100
1000 ms 83080 KB
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define ff first
#define ss second
#define pb push_back
#define all(a) (a).begin(), (a).end()
#define replr(i, a, b) for (int i = int(a); i <= int(b); ++i)
#define reprl(i, a, b) for (int i = int(a); i >= int(b); --i)
#define rep(i, n) for (int i = 0; i < int(n); ++i)
#define mkp(a, b) make_pair(a, b)
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<PII> VPI;
typedef vector<VI> VVI;
typedef vector<VVI> VVVI;
typedef vector<VPI> VVPI;
typedef pair<ll, ll> PLL;
typedef vector<ll> VL;
typedef vector<PLL> VPL;
typedef vector<VL> VVL;
typedef vector<VVL> VVVL;
typedef vector<VPL> VVPL;
template<class T> T setmax(T& a, T b) {if (a < b) return a = b; return a;}
template<class T> T setmin(T& a, T b) {if (a < b) return a; return a = b;}
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
template<class T>
using indset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

VI BIT;
void add(int i, int s) {
	while (i < BIT.size()) BIT[i] += s, i += i&-i;
}
void add(int l, int r, int s) {
	add(l, s);
	if (r+1 < BIT.size()) add(r+1, -s);
}
int get(int i) {
	int ret = 0;
	while (i > 0) ret += BIT[i], i -= i&-i;
	return ret;
}

int ubound(int x) {
	int l = 0, r = BIT.size();
	while (l + 1 < r) {
		int m = (l + r) / 2;
		if (get(m) > x) r = m;
		else l = m;
	}
	return r;
}
int lbound(int x) {
	int l = 0, r = BIT.size();
	while (l + 1 < r) {
		int m = (l + r) / 2;
		if (get(m) >= x) r = m;
		else l = m;
	}
	return r;
}
int answer(int L, int R) {
	return ubound(R)-lbound(L);
}

void solve() {
	int n, q;
	cin >> n >> q;
	VI a(n);
	for (int& x : a) cin >> x;
	sort(all(a));
	BIT = VI(n+1);
	rep(i, n) add(i+1, i+1, a[i]);
	while (q--) {
		char t;
		cin >> t;
		if (t == 'C') {
			int l, r;
			cin >> l >> r;
			cout << answer(l, r) << endl;
		} else {
			int c, h;
			cin >> c >> h;
			int l = lbound(h);
			if (l+c-1 >= n) add(l, n-1, +1);
			else {
				int r = lbound(get(l+c-1))-1;
				add(l, r, +1);
				int cnt = l+c-1-r;
				r = ubound(get(l+c-1))-1;
				l = r - cnt + 1;
				add(l, r, +1);
			}
			
			replr(i, 1, n) cout << get(i) << " "; cout << endl;
		}
	}
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    int t = 1;
    /* cin >> t; */
    while (t--) solve();
}

Compilation message

grow.cpp: In function 'void add(int, int)':
grow.cpp:35:11: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   35 |  while (i < BIT.size()) BIT[i] += s, i += i&-i;
      |         ~~^~~~~~~~~~~~
grow.cpp: In function 'void add(int, int, int)':
grow.cpp:39:10: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   39 |  if (r+1 < BIT.size()) add(r+1, -s);
      |      ~~~~^~~~~~~~~~~~
grow.cpp: In function 'void solve()':
grow.cpp:7:24: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
    7 | #define replr(i, a, b) for (int i = int(a); i <= int(b); ++i)
      |                        ^~~
grow.cpp:98:4: note: in expansion of macro 'replr'
   98 |    replr(i, 1, n) cout << get(i) << " "; cout << endl;
      |    ^~~~~
grow.cpp:98:42: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
   98 |    replr(i, 1, n) cout << get(i) << " "; cout << endl;
      |                                          ^~~~
# Verdict Execution time Memory Grader output
1 Execution timed out 1025 ms 57172 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 4 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1066 ms 56960 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1049 ms 57212 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1049 ms 57516 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1078 ms 59344 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1040 ms 41700 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1053 ms 83080 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1048 ms 56308 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1035 ms 80144 KB Time limit exceeded
2 Halted 0 ms 0 KB -