QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#125712 | #92. Santa Claus | Qwerty1232 | 0 | 0ms | 0kb | C++20 | 5.3kb | 2023-07-17 13:23:00 | 2023-07-17 13:23:02 |
Judging History
answer
#pragma GCC optimize("O3")
// #pragma GCC target("avx512vl,avx512dq,avx512bw")
#pragma GCC target("avx2")
#include <cassert>
#include <iostream>
void* operator new(size_t s) {
constexpr static int MEM = 1e8;
static char data[MEM];
static size_t ptr = 0;
ptr += s;
assert(ptr <= MEM);
return data + ptr - s;
}
void operator delete(void*) { ; }
#include <bits/stdc++.h>
std::mt19937 rnd;
void solve() {
int n;
std::cin >> n;
std::vector<int> x(n), h(n), v(n);
for (int i = 0; i < n; i++) {
std::cin >> x[i];
}
for (int i = 0; i < n; i++) {
std::cin >> h[i];
}
for (int i = 0; i < n; i++) {
std::cin >> v[i];
}
std::vector<int> s;
for (int i = 0; i < n; i++) {
if (h[i] == 0) {
s.push_back(v[i]);
}
}
std::sort(s.begin(), s.end());
for (int i = 0; i < n; i++) {
int it = std::lower_bound(s.begin(), s.end(), v[i]) - s.begin();
it += 5;
v[i] = it;
// if (h[i] == 0) {
// } else {
// ;
// }
}
if (n - std::accumulate(h.begin(), h.end(), 0) > n / 2) {
assert(false);
for (int i = 0; i < n; i++) {
std::cout << -1 << " \n"[i == n - 1];
}
return;
}
int it = h.rend() - std::find(h.rbegin(), h.rend(), 0) - 1;
if (it == -1) {
assert(false);
for (int i = 0; i < n; i++) {
std::cout << x[i] << " \n"[i == n - 1];
}
return;
}
std::vector<int> ans(n, -1);
std::vector<uint16_t> cum, fuck;
for (int i = 0; i <= it; i++) {
if (h[i] == 0) {
cum.push_back(v[i]);
} else {
fuck.push_back(v[i]);
}
}
while (it < n - 1 && cum.size() > fuck.size()) {
it++;
fuck.push_back(v[it]);
}
std::sort(fuck.begin(), fuck.end());
std::sort(cum.begin(), cum.end());
int x_left = -1;
int left = 0;
std::multiset<int> set;
for (int i = it; i < n; i++) {
if (i != it && h[i] == 1) {
auto it = std::lower_bound(fuck.begin(), fuck.end(), v[i]);
fuck.insert(it, v[i]);
}
auto check = [&]() {
if (fuck.size() >= cum.size()) {
uint16_t cnt = 0;
for (int i = 0; i < 100; i++) {
int id = rnd() % cum.size();
if (fuck[id] > cum[id]) {
return false;
}
}
constexpr int G = 1 << 10;
if (1) {
#pragma GCC ivdep
for (int i = 0; i < cum.size(); i++) {
cnt += fuck[i] > cum[i];
if (i + G < cum.size()) {
#pragma GCC ivdep
for (int j = 0; j < G; j++) {
cnt += fuck[i + j] > cum[i + j];
}
if (cnt > 0) {
break;
}
i += G - 1;
}
}
} else {
#pragma GCC ivdep
for (int i = cum.size() - 1; i >= 0; i--) {
cnt += fuck[i] > cum[i];
if (i > G) {
#pragma GCC ivdep
for (int j = 0; j < G; j++) {
cnt += fuck[i - j] > cum[i - j];
}
if (cnt > 0) {
break;
}
i -= G - 1;
}
}
}
return cnt == 0;
}
return false;
};
if (x_left != left && check()) {
x_left = left;
}
while (x_left == left && fuck.size() >= cum.size() && left < i) {
if (h[left] == 0) {
set.insert(v[left]);
left++;
x_left++;
continue;
}
int val_ch = v[left];
int it = std::lower_bound(fuck.begin(), fuck.end(), val_ch) - fuck.begin();
fuck.erase(fuck.begin() + it);
left++;
auto it1 = set.lower_bound(val_ch);
if (it1 == set.end()) {
// if (it >= cum.size()) {
// x_left = left;
// continue;
// }
if (check()) {
x_left = left;
continue;
}
break;
} else {
auto it = std::lower_bound(cum.begin(), cum.end(), *it1);
cum.erase(it);
set.erase(it1);
x_left = left;
}
}
if (x_left != -1) {
ans[i] = x[i] * 2 - x[x_left];
}
}
for (int i = 0; i < n; i++) {
std::cout << ans[i] << " \n"[i == n - 1];
}
}
int32_t main() {
std::ios_base::sync_with_stdio(false);
std::cin.tie(nullptr);
int t;
std::cin >> t;
while (t--) {
solve();
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Runtime Error
input:
5 84 25 26 31 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 90 94 102 105 112 117 125 134 140 146 147 156 157 167 173 183 186 187 190 198 206 212 220 224 226 234 235 240 250 251 259 261 268 271 1 0 0 0 0 0...
output:
result:
Test #2:
score: 0
Runtime Error
input:
10 134 105 106 107 108 109 110 111 112 113 114 115 116 117 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 1...
output:
result:
Test #3:
score: 0
Runtime Error
input:
10 1379 85 86 151 152 155 156 157 158 159 160 161 162 163 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 23...
output:
result:
Test #4:
score: 0
Runtime Error
input:
10 2709 75 76 81 88 89 119 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 2...
output:
result:
Test #5:
score: 0
Runtime Error
input:
10 5562 75 76 81 88 89 119 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 2...
output:
result:
Test #6:
score: 0
Runtime Error
input:
10 13123 75 76 81 88 89 119 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 ...
output:
result:
Test #7:
score: 0
Runtime Error
input:
10 27599 75 76 81 88 89 119 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 ...
output:
result:
Test #8:
score: 0
Runtime Error
input:
10 41646 75 76 81 88 89 119 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 ...
output:
result:
Test #9:
score: 0
Runtime Error
input:
10 95045 75 76 81 88 89 119 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 ...
output:
result:
Test #10:
score: 0
Runtime Error
input:
10 96068 75 76 81 88 89 119 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 ...