QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#518069 | #7617. Spectacle | Carameow | WA | 1ms | 11808kb | C++20 | 2.1kb | 2024-08-13 15:27:57 | 2024-08-13 15:27:58 |
Judging History
answer
#include<bits/stdc++.h>
#define ii pair<int, int>
#define iii pair<int, ii>
using namespace std;
const int N = 2e5 + 10;
int n, ans;
int a[N], f[N], l[N], s[N];
int od[18][N], ev[18][N];
bool red[N];
priority_queue<iii, vector<iii>, greater<iii> > pq;
void init() {
cin >> n;
for(int i = 1; i <= n; ++i) cin >> a[i];
}
int getod(int f, int l) {
f = f / 2 + 1;
l = l / 2 + 1;
int j = log2(l - f + 1);
return max(od[j][f], od[j][l - (1 << j) + 1]);
}
int getev(int f, int l) {
f /= 2;
l /= 2;
int j = log2(l - f + 1);
return max(ev[j][f], ev[j][l - (1 << j) + 1]);
}
int main () {
cin.tie(0) -> sync_with_stdio(0);
if(fopen("Task.inp", "r")) {
freopen("Task.inp", "r", stdin);
freopen("Wa.out", "w", stdout);
}
init();
int m1 = n / 2, m2 = n / 2 + n % 2 - 1;
int lg = log2(n / 2);
sort(a + 1, a + n + 1);
// for(int i = 1; i <= n; ++i) cout << a[i] << " "; cout << "\n";
for(int i = 1; i <= n; i += 2) od[0][i / 2 + 1] = a[i + 1] - a[i];
for(int i = 2; i <= n; i += 2) ev[0][i / 2] = a[i + 1] - a[i];
for(int j = 1; j <= lg; ++j) {
for(int i = 1; i <= m1 - (1 << j - 1); ++i) {
od[j][i] = max(od[j - 1][i], od[j - 1][i + (1 << j - 1)]);
}
for(int i = 1; i <= m2 - (1 << j - 1); ++i) {
ev[j][i] = max(ev[j - 1][i], ev[j - 1][i + (1 << j - 1)]);
}
}
for(int i = 0; i <= n; ++i) {
f[i + 1] = i; l[i] = i + 1;
if(i && n - i) pq.push({a[i + 1] - a[i], {i, i + 1}});
}
for(int i = 1; i <= n / 2; ++i) {
while(!pq.empty()) {
int mx, F, L;
mx = pq.top().first;
tie(F, L) = pq.top().second;
pq.pop();
// cout << mx << " " << F << " " << L << "\n";
if(red[F] || red[L]) continue;
ans = mx;
red[F] = red[L] = 1;
int nxtf = f[F], nxtl = l[L] - 1;
if(!nxtf || nxtl == n) break;
int val = nxtf % 2 ? getod(nxtf, nxtl) : getev(nxtf, nxtl);
f[nxtl + 1] = nxtf;
l[nxtf] = nxtl + 1;
pq.push({val, {nxtf, nxtl + 1}});
break;
}
cout << ans << " ";
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 11808kb
input:
6 100 13 20 14 10 105
output:
1 5 6
result:
ok single line: '1 5 6 '
Test #2:
score: -100
Wrong Answer
time: 1ms
memory: 9760kb
input:
2 1 1000000000000000000
output:
2147483646
result:
wrong answer 1st lines differ - expected: '999999999999999999', found: '2147483646 '