답안 #972644

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
972644 2024-04-30T19:20:23 Z c2zi6 Growing Trees (BOI11_grow) C++14
10 / 100
176 ms 2560 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);
			}
		}
	}
}

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);
      |      ~~~~^~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 86 ms 2128 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 344 KB Output is correct
2 Correct 5 ms 516 KB Output is correct
3 Correct 6 ms 468 KB Output is correct
4 Correct 4 ms 344 KB Output is correct
5 Incorrect 110 ms 1364 KB Output isn't correct
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 129 ms 1268 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 133 ms 1108 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 87 ms 1404 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 94 ms 1452 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 82 ms 1800 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 128 ms 2088 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 117 ms 1876 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 176 ms 2560 KB Output is correct