QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#457898#8723. 乘二ZipperCompile Error//C++142.6kb2024-06-29 14:41:302024-06-29 14:41:32

Judging History

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

  • [2024-06-29 14:41:32]
  • 评测
  • [2024-06-29 14:41:30]
  • 提交

answer

#include<iostream>
#include<algorithm>
#incllude<math.h>
using namespace std;
#define int long long

const int N = 2e5 + 5, p = 1e9 + 7;
pair<int, int> nums[N], heap[N];
int ans, arr[N]; long double Logarr[N];

bool smaller(pair<int, int> a, pair<int, int> b)
{
	double x = log2(nums[a.first].first) + nums[a.first].second;
	double y = log2(nums[b.first].first) + nums[b.first].second;
	if (x < y) return true; else return false;
}

void heapInsert(int idx)
{
	while (idx != 0 && smaller(heap[idx], heap[idx / 2]))
	{
		pair<int, int> tmp = heap[idx]; heap[idx] = heap[idx / 2];
		heap[idx / 2] = tmp; idx = idx / 2;
	}
}

void heapify(int idx, int size)
{
	int l = 2 * idx;
	while (l <= size)
	{
		int mini = l + 1 <= size && smaller
			(heap[l + 1], heap[l]) ? l + 1 : l;
		if (smaller(heap[idx], heap[mini])) break;
		pair<int, int> tmp = heap[mini]; heap[mini] = heap[idx];
		heap[idx] = tmp; idx = mini; l = 2 * idx;
	}
}

int power(int a, int b)
{
	int tmp = 2, ans = 1;
	while (b > 0)
	{
		if (b % 2) ans = (ans * tmp) % p;
		tmp = (tmp * tmp) % p; b /= 2;
	}
	return (a * ans) % p;
}

//小根堆维护最小值
//signed main()
//{
//	int n, k; cin >> n >> k;
//	for (int i = 1; i <= n; i++)
//	{
//		cin >> nums[i].first;
//		nums[i].second = 0;
//		heap[i] = { i, nums[i].first };
//		heapInsert(i);
//	}
//
//	for (int i = 0; i < k; i++)
//	{
//		//时间复杂度O(k*logn),k比较大时无法在时限内得到结果
//		heap[1].second = (heap[1].second * 2) % p;
//		nums[heap[1].first].second++; heapify(1, n);
//	}
//
//	for (int i = 1; i <= n; i++)
//	{
//		ans += heap[i].second; ans %= p;
//	}
//	cout << ans;
//
//	return 0;
//}

signed main()
{
	int n, k; cin >> n >> k;
	for (int i = 1; i <= n; i++)
	{
		cin >> arr[i];
	}
	sort(arr + 1, arr + n + 1);
	for (int i = 1; i <= n; i++)
	{
		Logarr[i] = log2l(arr[i]);
	}

	int stop = n, times = 0;
	int left = 1, right = n;
	while (left <= right)
	{
		int sum = 0;
		int mid = (left + right) / 2;
		for (int i = 1; i < mid; i++)
		{
			sum += floor(Logarr[mid] - Logarr[i]);
		}

		if (sum <= k)
		{
			left = mid + 1; stop = mid; times = k - sum;
		}
		else
		{
			right = mid - 1;
		}
	}

	for (int i = 1; i < stop; i++)
	{
		arr[i] = power(arr[i], floor(Logarr[stop] - Logarr[i]));
	}
	sort(arr + 1, arr + stop + 1);
	int t = times / stop, s = times - t * stop;
	for (int i = 1; i <= stop; i++)
	{
		if (i <= s) arr[i] = power(arr[i], t + 1);
		else arr[i] = power(arr[i], t);
	}

	for (int i = 1; i <= n; i++)
	{
		ans += arr[i]; ans %= p;
	}
	cout << ans;

	return 0;
}

Details

answer.code:3:2: error: invalid preprocessing directive #incllude; did you mean #include?
    3 | #incllude<math.h>
      |  ^~~~~~~~
      |  include
answer.code: In function ‘bool smaller(std::pair<long long int, long long int>, std::pair<long long int, long long int>)’:
answer.code:13:20: error: ‘log2’ was not declared in this scope
   13 |         double x = log2(nums[a.first].first) + nums[a.first].second;
      |                    ^~~~
answer.code: In function ‘int main()’:
answer.code:89:29: error: ‘log2l’ was not declared in this scope
   89 |                 Logarr[i] = log2l(arr[i]);
      |                             ^~~~~
answer.code:100:32: error: ‘floor’ was not declared in this scope
  100 |                         sum += floor(Logarr[mid] - Logarr[i]);
      |                                ^~~~~
answer.code:115:40: error: ‘floor’ was not declared in this scope
  115 |                 arr[i] = power(arr[i], floor(Logarr[stop] - Logarr[i]));
      |                                        ^~~~~