QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#261603#4428. FenceoogerboogerAC ✓501ms68176kbC++143.3kb2023-11-23 02:41:162023-11-23 02:41:16

Judging History

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

  • [2023-11-23 02:41:16]
  • 评测
  • 测评结果:AC
  • 用时:501ms
  • 内存:68176kb
  • [2023-11-23 02:41:16]
  • 提交

answer

#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>

#define INF 1000000000
#define INFl 1000000000000000000
#define all(x) x.begin(), x.end()
#define sajz(x) (int)x.size()
#define pb push_back
#define se second
#define fi first
#define yes puts("YES")
#define no puts("NO")
#define erase_duplicates(x) {sort(all(x));(x).resize(distance((x).begin(), unique(all(x))));}
using namespace std;
//using namespace __gnu_pbds;
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif

#define int ll

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef set<int> si;
typedef multiset<int> msi;
typedef long double ld;
//typedef cc_hash_table<int, int, hash<int>> ht;

struct Vertex {
	int sz, sum_odd, sum_even;
};

const int N = (1 << 20);

pii a[N];
Vertex t[2*N];
int pods;

void modify(int v, int x, int b) {
	int cnt = x / b;
	int odd = 0, even = 0;
	if (cnt % 2 == 0) {
		odd = cnt * b / 2 + x % b;
		even = cnt * b / 2;
	} else {
		odd = (cnt + 1) * b / 2;
		even = (cnt - 1) * b / 2 + x % b;
	}

	t[v += pods] = {(x + b - 1) / b, odd, even};

	//debug(v, t[v].sz, t[v].sum_odd, t[v].sum_even);

	while (v/2) {
		v/=2;

		if (t[v*2].sz % 2 == 1) {
			t[v] = {t[v*2].sz + t[v*2+1].sz, t[v*2].sum_odd + t[v*2+1].sum_even, t[v*2].sum_even + t[v*2+1].sum_odd};
		} else {
			t[v] = {t[v*2].sz + t[v*2+1].sz, t[v*2].sum_odd + t[v*2+1].sum_odd, t[v*2].sum_even + t[v*2+1].sum_even};
		}
	}
}

void test_case() {
	pods = 1;
	int n;
	cin >> n;
	while (pods <= n) pods *= 2;
	for (int i = 0; i <= 2*pods; i ++) t[i] = {0, 0, 0};

	for (int i = 0; i < n; i ++) {
		cin >> a[i].first;
		a[i].second = i;
		modify(i, a[i].first, 1);
	}
	sort(a, a + n, greater<pii>());

	cout << t[1].sum_odd << '\n';

	for (int b = 2; b <= a[0].first; b ++) {
		int j = 0;
		while (j < n && a[j].first >= b) {
			modify(a[j].second, a[j].first, b);
			j ++;
		}

		cout << t[1].sum_odd << '\n';
	}
}

int32_t main() {
	ios_base::sync_with_stdio(false);
	cout.tie(0);
	cin.tie(0);
	int t=1;
	cin >> t;
	for (int i = 1; i <= t; i ++) {
		test_case();
	}
}

详细

Test #1:

score: 100
Accepted
time: 501ms
memory: 36240kb

input:

5
333834
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1...

output:

500000
500000
499995
499987
500000
500032
499996
499987
500032
500000
499994
499998
499981
499996
500080
500090
500077
500032
499980
499915
500035
499941
500055
499923
500000
499980
499935
500042
500174
499905
500002
499998
500218
499899
499965
500010
500144
500242
499839
499915
499987
500010
500122...

result:

ok 2500000 lines

Test #2:

score: 0
Accepted
time: 284ms
memory: 14756kb

input:

5
48356
1 1 2 2 1 1 1 1 2 4 8 4 1 2 128 4 1 1 2 1 1 2 2 1 1 1 4 1 1 1 2 1 2 8 8 1 1 1 1 8 1 2 1 2 1 1 1 1 8 1 2 1 2 1 2 1 2 1 1 8 1 2 4 1 1 1 1 1 4 1 2 1 1 1 2 1 2 64 1 256 1 1 1 1 1 2 32 1 1 2 1 1 2 2 1 1 1 1 1 1 4 1 1 2 2 1 1 1 1 1 1 2 1 2 256 4 1 1 2 1 2 1 2 2 1 1 2 2 2 2 1 1 1 2 1 32 1 1 1 4 1 1...

output:

500000
499939
500012
499925
499701
499996
499780
499879
500247
499914
500226
500164
500084
500054
499449
499819
500132
500378
500533
500517
499941
499527
500493
500808
500635
499680
500903
500128
500111
500413
499462
500244
500233
499885
499983
500105
499925
500185
499961
499466
500376
500081
498569...

result:

ok 987898 lines

Test #3:

score: 0
Accepted
time: 145ms
memory: 14032kb

input:

5
100000
1 10 9 6 2 9 5 8 6 8 3 10 10 4 8 10 5 4 8 1 3 3 10 6 8 2 1 1 7 4 4 7 3 3 2 7 3 8 4 8 8 8 9 7 1 6 7 5 1 6 5 6 10 7 1 7 10 4 9 6 7 3 4 2 7 7 8 9 7 1 8 4 1 6 10 1 3 8 8 5 6 4 10 5 10 3 4 1 8 2 8 4 6 1 7 2 10 2 2 3 3 3 4 6 6 6 6 7 8 8 8 9 9 9 9 9 10 10 4 5 10 3 1 5 6 7 9 5 3 2 2 3 1 2 1 6 1 1 6...

output:

275038
275208
276333
274460
274715
278680
279579
271029
278720
274871
251536
251586
251550
251533
251687
251362
251680
251736
251758
251640
252228
251127
251367
250702
251853
250779
250632
250725
251045
251774
251515
249096
250101
253104
247732
248767
248976
249529
253658
252323
252069
251541
251651...

result:

ok 1010971 lines

Test #4:

score: 0
Accepted
time: 431ms
memory: 68176kb

input:

5
1413
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 1...

output:

499496
499496
499494
499848
499491
500202
499487
500553
499498
500905
499497
501264
499498
501599
499446
501961
499443
502306
499413
502649
499443
503017
499414
503329
499499
503710
499498
504049
499501
504360
499310
504777
499233
505155
499499
505440
499170
505761
499498
506160
499091
506583
499505...

result:

ok 502830 lines

Test #5:

score: 0
Accepted
time: 1ms
memory: 5348kb

input:

5
1
1
1
3
2
1 1
2
1 2
2
3 1

output:

1
2
2
3
1
2
1
2
3
3

result:

ok 10 lines

Extra Test:

score: 0
Extra Test Passed