QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#184589#5979. Log SetIshy25 ✓44ms6936kbC++142.9kb2023-09-20 21:40:272023-09-20 21:40:28

Judging History

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

  • [2023-09-20 21:40:28]
  • 评测
  • 测评结果:25
  • 用时:44ms
  • 内存:6936kb
  • [2023-09-20 21:40:27]
  • 提交

answer

#include<bits/stdc++.h>
#define LL long long
#define DB double
#define MOD 1000000007
#define ls(x) (x << 1)
#define rs(x) (x << 1 | 1)
#define lowbit(x) ((-x) & x)
#define MP make_pair
#define VI vector<int>
#define VL vector<LL>
#define VII VI::iterator
#define VLI VL::iterator
#define all(x) x.begin(), x.end()
#define EB emplace_back
#define PII pair<int, int>
#define PLL pair<LL, LL>
#define SI set<int>
#define SII SI::iterator
#define fi first
#define se second
using namespace std;
template<typename T> void chkmn(T &a, const T &b) { (a > b) && (a = b); }
template<typename T> void chkmx(T &a, const T &b) { (a < b) && (a = b); }
void Inc(int &a, const int &b) { ((a += b) >= MOD) && (a -= MOD); }
void Dec(int &a, const int &b) { ((a -= b) < 0) && (a += MOD); }
void Mul(int &a, const int &b) { a = 1LL * a * b % MOD; }
void Sqr(int &a) { a = 1LL * a * a % MOD; }
int inc(const int &a, const int &b) { return (a + b >= MOD) ? a + b - MOD : a + b; }
int dec(const int &a, const int &b) { return (a - b < 0) ? a - b + MOD : a - b; }
int mul(const int &a, const int &b) { return 1LL * a * b % MOD; }
int sqr(const int &a) { return 1LL * a * a % MOD; }
int qwqmi(int x, int k = MOD - 2)
{
	int res = 1;
	while(k)
	{
		if(k & 1) Mul(res, x);
		k >>= 1, Sqr(x);
	}
	return res;
}
const int N = 1e4 + 5;
const int M = 65;
int T, n, m;
PLL a[N];
LL ans[M];
map<LL, LL> mp;
set<LL> f[M];
void work(int cas)
{
	mp.clear(); LL sum = 0;
	scanf("%d", &n);
	for(int i = 1; i <= n; ++i)
		scanf("%lld", &a[i].fi);
	for(int i = 1; i <= n; ++i)
		scanf("%lld", &a[i].se);
	for(int i = 1; i <= n; ++i)
	{
		mp.insert(a[i]);
		sum += a[i].se;
	}
	m = log2(sum);
	for(int i = 1; i <= m + 1; ++i)
		f[i].clear();
	for(int i = 1; i <= m; ++i)
	{
		vector<PLL> vec; vec.clear();
		LL mx1 = 7210721, mx2 = 7210721;
		mx2 = mx1 = prev(mp.end())->fi;
		if(prev(mp.end()) != mp.begin())
			mx2 = prev(prev(mp.end()))->fi;
		LL p = mx1 - mx2;
		ans[i] = p;
		for(auto now : mp)
		{
			LL x = now.fi, c = now.se;
			if(c == 0)
			{
				vec.EB(MP(x, c));
				continue;
			}
			if(mp.find(x + p) == mp.end())
				continue;
			if(p == 0) mp[x] >>= 1;
			else mp[x + p] -= c;
		}
		for(auto now : vec)
			mp.erase(now.fi);
	}
	LL delta = abs(mp.begin()->fi);
	sort(ans + 1, ans + m + 1, [&](LL x, LL y){
		return x > y;
	});
	f[m + 1].insert(0);
	for(int i = m; i >= 1; --i)
		for(auto x : f[i + 1])
		{
			f[i].insert(x);
			f[i].insert(x + ans[i]);
		}
	for(int i = 1; i <= m; ++i)
		if(f[i + 1].find(delta - ans[i]) != f[i + 1].end())
			delta -= ans[i], ans[i] = -ans[i];
	sort(ans + 1, ans + m + 1);
	printf("Case #%d: ", cas);
	for(int i = 1; i <= m; ++i)
		printf("%lld ", ans[i]);
	puts("");
}
int main()
{
	scanf("%d", &T);
	for(int cas = 1; cas <= T; ++cas)
		work(cas);
	return 0;
}

//3
//8
//0 1 2 3 4 5 6 7
//1 1 1 1 1 1 1 1
//4
//0 1 3 4
//4 4 4 4
//5
//-2 -1 0 1 2
//1 2 2 2 1


詳細信息

Subtask #1:

score: 6
Accepted

Test #1:

score: 6
Accepted
time: 19ms
memory: 5156kb

input:

100
36
0 2 4 53591 53592 53593 53594 53595 53596 74164 74166 74168 107182 107183 107184 107185 107186 107187 127755 127756 127757 127758 127759 127760 160774 160776 160778 181346 181347 181348 181349 181350 181351 234938 234940 234942
1 2 1 2 1 4 2 2 1 1 2 1 1 2 2 4 1 2 2 1 4 2 2 1 1 2 1 1 2 2 4 1 2...

output:

Case #1: 2 2 53591 53591 53592 74164 
Case #2: 1 15547 76676 76677 153352 
Case #3: 1 1 1 1 2 
Case #4: 1 1 2 2 
Case #5: 9242 9243 77639 86881 96123 96123 201487 
Case #6: 0 0 0 1 8 16 
Case #7: 22874 72322 95195 95195 95195 95195 190390 
Case #8: 1 2 4 
Case #9: 0 0 1 1 1 1 12 15 
Case #10: 0 0 1 ...

result:

ok 100 lines

Subtask #2:

score: 19
Accepted

Test #2:

score: 19
Accepted
time: 44ms
memory: 6936kb

input:

100
10
-4 -3 -2 -1 0 1 2 3 4 5
1 3 4 4 4 4 4 4 3 1
11
-4 -3 -2 0 1 2 3 4 6 7 8
2 4 2 2 4 4 4 2 2 4 2
11
-3 -2 -1 0 1 2 3 4 5 6 7
2 4 4 8 10 8 10 8 4 4 2
56
-114052 -114051 -114050 -96688 -96687 -96686 -96685 -79323 -79322 -79321 -79320 -65712 -65711 -65710 -65706 -65705 -65704 -61958 -61957 -61956 -...

output:

Case #1: -4 1 1 1 2 
Case #2: -4 0 1 1 6 
Case #3: -3 0 1 1 2 3 
Case #4: -48346 -48340 -17365 -1 1 17364 17365 
Case #5: -65620 -65619 -42396 1 23223 65619 65619 
Case #6: -80 -79 -79 -78 -78 -75 -74 -73 -71 -68 -66 -66 -66 -65 -62 -61 -61 -60 -60 -7 -5 1 3 5 6 10 10 19 20 23 24 26 26 30 30 31 32 3...

result:

ok 100 lines

Extra Test:

score: 0
Extra Test Passed