QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#125714#92. Santa ClausQwerty123280 935ms5324kbC++205.4kb2023-07-17 13:27:272023-07-17 13:27:29

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-07-17 13:27:29]
  • 评测
  • 测评结果:80
  • 用时:935ms
  • 内存:5324kb
  • [2023-07-17 13:27:27]
  • 提交

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]);
        }
    }
    assert(s.size() <= 60'000);
    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 (cum.size() == 0) {
                return true;
            }
            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: 10
Accepted
time: 1ms
memory: 3476kb

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:

-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 349 190 198 206 212 220 224 226 234 235 240 250 251 259 261 268 271
-1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -...

result:

ok 5 lines

Test #2:

score: 10
Accepted
time: 1ms
memory: 3452kb

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:

-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 246 247 248 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 19...

result:

ok 10 lines

Test #3:

score: 0
Wrong Answer
time: 5ms
memory: 3536kb

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:

-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 ...

result:

wrong answer 1st lines differ - expected: '-1 -1 -1 -1 -1 -1 -1 -1 -1 -1 ...7 3206 3209 3216 3223 3232 3241', found: '-1 -1 -1 -1 -1 -1 -1 -1 -1 -1 ...7 3206 3209 3216 3223 3232 3241'

Test #4:

score: 10
Accepted
time: 8ms
memory: 3532kb

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:

-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 ...

result:

ok 10 lines

Test #5:

score: 10
Accepted
time: 22ms
memory: 3616kb

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:

-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 ...

result:

ok 10 lines

Test #6:

score: 10
Accepted
time: 60ms
memory: 3876kb

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:

-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 ...

result:

ok 10 lines

Test #7:

score: 10
Accepted
time: 195ms
memory: 4148kb

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:

-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 ...

result:

ok 10 lines

Test #8:

score: 10
Accepted
time: 424ms
memory: 4060kb

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:

-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 ...

result:

ok 10 lines

Test #9:

score: 10
Accepted
time: 935ms
memory: 5324kb

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:

-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 ...

result:

ok 10 lines

Test #10:

score: 0
Time Limit Exceeded

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 ...

output:

-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 ...

result: