QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#65215#4428. FenceSa3tElSefrTL 0ms0kbC++201.4kb2022-11-28 05:45:022022-11-28 05:45:05

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2022-11-28 05:45:05]
  • 评测
  • 测评结果:TL
  • 用时:0ms
  • 内存:0kb
  • [2022-11-28 05:45:02]
  • 提交

answer

#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
using namespace std;
const int N = 1e6 + 5;
int t, n, a[N];
int pref[N];
vector<int> g[N];
int main() {
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    cin >> t;
    while(t--) {
		cin >> n;
		int mx = 0;
		for(int i = 1;i <= n;i++) {
			cin >> a[i];
			mx = max(mx, a[i]);
		}
		pref[n + 1] = pref[n + 2] = 0;
		for(int i = n;i >= 1;i--)
			pref[i] = pref[i + 2] + a[i];
		set<int> st;
		g[a[n + 1]].clear();
		g[0].clear();
		for(int i = 0;i <= n + 1;i++) {
			st.insert(i);
			g[a[i]].push_back(i);
		}
		a[n + 1] = 0;
		for(int b = 1;b <= mx;b++) {
			int p = 0;
			int ans = 0;
			for(auto it = st.begin();*it <= n;it++) {
				int nxt = *next(it);
				if(*it + 1 != nxt) {
					bool flip = ((*it % 2) == (nxt % 2));
					if(!p)
						ans += pref[*it + 1] - pref[nxt + flip];	
					else
						ans += pref[*it + 2] - pref[nxt + !flip];
					p ^= flip;
				}
				int cnt = a[nxt] / b, rem = a[nxt] % b;
				ans += ((cnt + !p) / 2) * b;
				p ^= (cnt & 1);
				if(rem) {
					ans += !p * rem;
					p ^= 1;
				}
			}
			for(auto i : g[b])
				st.erase(i);
			cout << ans << '\n';
		}
		for(int i = 1;i <= n + 1;i++)
			g[a[i]].clear();
	}
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Time Limit Exceeded

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: