QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#365321#7939. High TowersEMBailey#Compile Error//C++141.5kb2024-03-25 02:58:022024-03-25 02:58:03

Judging History

你现在查看的是最新测评结果

  • [2024-03-25 02:58:03]
  • 评测
  • [2024-03-25 02:58:02]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;

#define rep(i, a, b) for (int i = a; i < b; i++)
#define sz(C)		 int(size(C))

struct RMQ
{
	vector<int> A;
	vector<vector<int>> jmp;
	RMQ(){

	}
	RMQ(const vector<int> &V) : jmp(1, V), A(V)
	{
		for(int i = 0; i < A.size(); i++){
			jmp[0][i] = i;
		}
		for (int pw = 1, k = 1; pw * 2 <= sz(V); pw *= 2, ++k)
		{
			jmp.emplace_back(sz(V) - pw * 2 + 1);
			rep(j, 0, sz(jmp[k])) {
				int l = jmp[k-1][j];
				int r = jmp[k-1][j+pw];
				if(A[l] > A[r]){
					jmp[k][j] = l;
				}
				else{
					jmp[k][j] = r;
				}
			}
		}
	}
	int query(int a, int b)
	{
		if (a >= b)
			return 0;
		int dep = 31 - __builtin_clz(b - a);
		//cout << dep << " " << a << " " << b << " " << jmp.size() << endl;
		int l = jmp[dep][a];
		int r = jmp[dep][b - (1 << dep)];
		if(A[l] > A[r]){
			return l;
		}
		return r;
	}
};

RMQ Q;
vector<int> A;
vector<int> res;

void solve(int l, int r){
	if(r < l) return;
	int N = r-l+1;
	int ind = Q.query(l, r+1);
	//cout << ind << endl;
	assert(l <= ind && r >= ind);
	res[ind] = N;
	solve(l, ind-1);
	solve(ind+1, r);
}


int main(int argc, char const *argv[])
{
	if (argc > 1)
	{
		ignore = freopen(argv[1], "r", stdin);
		ignore = freopen(argv[2], "w", stdout);
	}
	int N;
	cin >> N;
	A = vector<int>(N, 0);
	res = vector<int>(N, 0);
	for(int i = 0; i < N; i++){
		cin >> A[i];
	}
	Q = RMQ(A);
	//cout << "done\n";

	solve(0, N-1);
	for(int i = 0; i < N; i++){
		cout << res[i] << " ";
	}
	cout << endl;

}

详细

answer.code: In constructor ‘RMQ::RMQ(const std::vector<int>&)’:
answer.code:6:30: error: ‘size’ was not declared in this scope
    6 | #define sz(C)            int(size(C))
      |                              ^~~~
answer.code:20:51: note: in expansion of macro ‘sz’
   20 |                 for (int pw = 1, k = 1; pw * 2 <= sz(V); pw *= 2, ++k)
      |                                                   ^~