QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#447359#8723. 乘二ZipperTL 1459ms12124kbC++141.6kb2024-06-18 10:43:492024-06-18 10:43:50

Judging History

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

  • [2024-06-18 10:43:50]
  • 评测
  • 测评结果:TL
  • 用时:1459ms
  • 内存:12124kb
  • [2024-06-18 10:43:49]
  • 提交

answer

#include<iostream>
#include<math.h>
#include<algorithm>
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], Logarr[N], dLog[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;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 7848kb

input:

3 3
7 2 1

output:

15

result:

ok 1 number(s): "15"

Test #2:

score: 0
Accepted
time: 1459ms
memory: 11272kb

input:

200000 1605067
366760624 67854 93901 693975 27016 1046 10808 6533158 54778 500941023 77236442 32173 10431454 2 9726 1553148 89282 411182309 494073 131299543 249904771 7906930 353 9909 3632698 29156 1917186 303 737 1189004 22 1983 263 711 4106258 2070 36704 12524642 5192 123 2061 22887 66 380 1 10153...

output:

707034173

result:

ok 1 number(s): "707034173"

Test #3:

score: 0
Accepted
time: 117ms
memory: 12124kb

input:

200000 108039
13 851590697 3104 109395313 37 928 2329004 13853269 1 15 226 4785 488 2930 83250294 12228 145352832 120690 14511669 181 10740 26395301 4 1172 451394571 24571 11076 90419 5929 579583498 903729755 142027966 300157 25 20 22148 30321289 71577040 37091 1951 445549 21 96460 3491 624 764 1 48...

output:

752908968

result:

ok 1 number(s): "752908968"

Test #4:

score: -100
Time Limit Exceeded

input:

200000 2903290
201855332 123438 83762 1638319 17 122361 121973 17172 44 51 1 5 367822770 251 1908405 5 240290 185972 303017248 22227 193978 133159 92105 504 227 4796 1173 143 6 67736 252033016 257 876 845 16 39 9408 18 204865935 18263757 564396 213 126820 23050809 235107 1025 2169 7495 1264417 1 158...

output:


result: