QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#517096#9161. Naval battleskittles14126 1979ms264820kbC++177.2kb2024-08-13 06:07:472024-08-13 06:07:47

Judging History

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

  • [2024-08-13 06:07:47]
  • 评测
  • 测评结果:6
  • 用时:1979ms
  • 内存:264820kb
  • [2024-08-13 06:07:47]
  • 提交

answer

// cf bits/extc++.h nonsense
#ifdef ONLINE_JUDGE
#define _EXT_CODECVT_SPECIALIZATIONS_H 1
#define _EXT_ENC_FILEBUF_H 1
#endif
#include "bits/extc++.h"

using namespace std;

template <typename T, typename... U>
void dbgh(const T& t, const U&... u) {
    cerr << t;
    ((cerr << " | " << u), ...);
    cerr << endl;
}

#ifdef DEBUG
#define dbg(...)                                              \
    cerr << "L" << __LINE__ << " [" << #__VA_ARGS__ << "]: "; \
    dbgh(__VA_ARGS__)
#else
#define dbg(...)
#define cerr   \
    if (false) \
    cerr
#endif

using u64 = uint64_t;
using ll = long long;
using ld = long double;

template <typename T>
using min_pq = priority_queue<T, vector<T>, greater<T>>;

#define endl "\n"
#define long int64_t
#define sz(x) int(std::size(x))

inline void init_io() {
    cin.tie(nullptr);
    cin.exceptions(ios::failbit);
    ios_base::sync_with_stdio(false);
}

template <typename T>
vector<T> iota(int n, const T& init) {
    vector<T> arr(n);

    iota(begin(arr), end(arr), init);

    return arr;
}

template <typename T>
vector<vector<T>> transposed(const vector<vector<T>>& arr) {
    int n = sz(arr), m = sz(arr[0]);

    vector ans(m, vector<T>(n));

    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            ans[j][i] = arr[i][j];
        }
    }

    return ans;
}

template <typename T>
bool on(const T& mask, int bit) {
    return (mask >> bit) & 1;
}

template <typename T>
ostream& operator<<(ostream& out, const vector<T>& arr) {
    out << "[";
    for (int i = 0; i < sz(arr); i++) {
        if (i) {
            out << ", ";
        }
        out << arr[i];
    }
    return out << "]";
}

template <typename A, typename B>
ostream& operator<<(ostream& out, const pair<A, B>& p) {
    return out << "(" << p.first << ", " << p.second << ")";
}

template <typename A, typename T>
int lbs(const A& arr, const T& x) {
    return int(lower_bound(begin(arr), end(arr), x) - begin(arr));
}

inline vector<bool>::reference& operator&=(vector<bool>::reference&& a, bool b) {
    return a = a & b;
}

template <typename T>
T reversed(T arr) {
    reverse(begin(arr), end(arr));
    return arr;
}

constexpr int IINF = 1e9 + 10;

struct DS1 {
    map<int, int> active, copt, v_id;
    set<pair<int, int>> crash;

    DS1() {}
    DS1(vector<array<int, 3>> arr) {
        sort(begin(arr), end(arr));

        for (auto& [x, ty, id] : arr) {
            active[x] = ty;
            v_id[x] = id;
        }
        active[-IINF] = active[IINF] = -100;

        for (auto& [x, ty, _id] : arr) {
            if (ty == +1) {
                copt[x] = -1;
            }
        }
        for (auto& [x, ty, _id] : arr) {
            if (ty == +1) {
                upd(x);
            }
        }
    }

    void upd(int x) {
        if (x == -IINF || x == IINF) {
            return;
        }

        // assert(active[x] == +1);
        int& co = copt[x];
        if (co != -1) {
            crash.erase({co, x});
        }

        auto it = active.upper_bound(x);
        if (it->second == -1) {
            crash.emplace(co = it->first - x, x);
        } else {
            co = -1;
        }
    }

    void erase(int x) {
        int co = copt[x];

        if (co != -1) {
            crash.erase({co, x});
        }

        active.erase(x);
        copt.erase(x);
        upd((--active.lower_bound(x))->first);
    }

    int query_time() const {
        if (sz(crash)) {
            dbg(begin(crash)->first);
        }
        return sz(crash) ? begin(crash)->first : IINF;
    }

    template <typename Cb>
    void all_crashes(int t, const Cb& cb) {
        for (auto it = begin(crash); it != end(crash) && it->first == t; ++it) {
            cb(v_id[it->second]);

            auto it2 = active.upper_bound(it->second);
            cb(v_id[it2->first]);
        }
    }
};

struct DS2 {
    vector<array<int, 3>> arr;
    map<int, DS1> dsv;
    set<pair<int, int>> opt_time;

    DS2(const vector<array<int, 3>>& arr) : arr(arr) {
        map<int, vector<array<int, 3>>> mp;
        for (int i = 0; i < sz(arr); i++) {
            auto& [x, y, ty] = arr[i];
            if (!ty) {
                continue;
            }
            mp[x].push_back({y, ty, i});
        }

        for (auto& [k, v] : mp) {
            auto& cds = dsv[k] = DS1(v);
            opt_time.emplace(cds.query_time(), k);
        }
    }

    void erase(int ind) {
        auto& [x, y, ty] = arr[ind];
        if (!ty) {
            return;
        }
        auto& cds = dsv[x];

        opt_time.erase({cds.query_time(), x});
        cds.erase(y);
        opt_time.emplace(cds.query_time(), x);
    }

    int query_time() const {
        return sz(opt_time) ? begin(opt_time)->first : IINF;
    }

    template <typename Cb>
    void all_crashes(int t, const Cb& cb) {
        for (auto it = begin(opt_time); it != end(opt_time) && it->first == t;
             ++it) {
            dsv[it->second].all_crashes(t, cb);
        }
    }
};

void solve() {
    int n;
    cin >> n;
    vector<tuple<int, int, char>> arr(n);
    for (auto& [x, y, dir] : arr) {
        cin >> x >> y >> dir;
        if (dir == 'N' || dir == 'S') {
            dir = 'N' ^ 'S' ^ dir;
        }
    }

    vector<DS2> dss;
    auto go = [&](auto cb) -> void {
        vector<array<int, 3>> ans;

        for (auto& [x, y, dir] : arr) {
            ans.push_back(cb(x, y, dir));
        }

        dss.emplace_back(ans);
    };
    auto go2 = [&](auto cb1, char p1, char m1) -> void {
        auto cb2 = [&](char dir) -> int {
            if (dir == p1) {
                return +1;
            } else if (dir == m1) {
                return -1;
            } else {
                return 0;
            }
        };

        go([&](int x, int y, char dir) -> array<int, 3> {
            return {cb1(x, y), x, cb2(dir)};
        });
    };

    auto diag1 = [&](int x, int y) -> int {
        return x + y;
    };
    auto diag2 = [&](int x, int y) -> int {
        return x - y;
    };

    go2(diag1, 'E', 'N');
    go2(diag1, 'S', 'W');
    go2(diag2, 'N', 'W');
    go2(diag2, 'E', 'S');
    go2([&](int x, int) -> int {
        return x;
    }, 'N', 'S');
    go2([&](int, int y) -> int {
        return y;
    }, 'E', 'W');

    vector ans(n, true);

    while (true) {
        int opt_time = IINF;

        for (auto& a : dss) {
            opt_time = min(opt_time, a.query_time());
            dbg(opt_time);
        }

        if (opt_time == IINF) {
            break;
        }

        dbg(opt_time);
        set<int> death;
        for (auto& a : dss) {
            a.all_crashes(opt_time, [&](int ind) -> void {
                death.insert(ind);
            });
        }

        for (auto& a : death) {
            dbg(a);
            ans[a] = false;
            for (auto& b : dss) {
                b.erase(a);
            }
        }
    }

    for (int i = 0; i < n; i++) {
        if (ans[i]) {
            dbg(i);
            cout << i + 1 << endl;
        }
    }
}

int main() {
    init_io();
    solve();
}

詳細信息

Subtask #1:

score: 6
Accepted

Test #1:

score: 6
Accepted
time: 0ms
memory: 3552kb

input:

2
675333810 792019962 W
851860476 960355168 W

output:

1
2

result:

ok 

Test #2:

score: 6
Accepted
time: 0ms
memory: 3544kb

input:

2
714148610 688520844 W
359519570 789553998 S

output:

1
2

result:

ok 

Test #3:

score: 6
Accepted
time: 0ms
memory: 3620kb

input:

2
743286406 87591094 E
108453484 326740470 S

output:

1
2

result:

ok 

Test #4:

score: 6
Accepted
time: 0ms
memory: 3636kb

input:

2
629499666 659260200 W
391550936 897208930 N

output:


result:

ok 

Test #5:

score: 6
Accepted
time: 0ms
memory: 3632kb

input:

2
509095668 374922996 W
325521434 191348762 S

output:


result:

ok 

Test #6:

score: 6
Accepted
time: 0ms
memory: 3548kb

input:

2
357656592 713571312 E
456601638 614626266 S

output:


result:

ok 

Test #7:

score: 6
Accepted
time: 0ms
memory: 3568kb

input:

2
353512742 374956722 W
265604916 462864548 N

output:


result:

ok 

Test #8:

score: 6
Accepted
time: 0ms
memory: 3548kb

input:

2
253519292 302668732 E
436627396 119560628 S

output:


result:

ok 

Test #9:

score: 6
Accepted
time: 0ms
memory: 3644kb

input:

2
741954822 709863076 W
516385128 484293380 S

output:

1
2

result:

ok 

Test #10:

score: 6
Accepted
time: 0ms
memory: 3560kb

input:

2
268851874 524109226 E
503673708 758931058 N

output:

1
2

result:

ok 

Test #11:

score: 6
Accepted
time: 0ms
memory: 3632kb

input:

2
629380956 395789270 S
557401140 467769088 E

output:

1
2

result:

ok 

Test #12:

score: 6
Accepted
time: 0ms
memory: 3504kb

input:

2
606361496 587557658 N
667076156 526843000 W

output:

1
2

result:

ok 

Test #13:

score: 6
Accepted
time: 0ms
memory: 3568kb

input:

2
270428340 629167054 N
270428342 179345630 S

output:

1
2

result:

ok 

Subtask #2:

score: 0
Wrong Answer

Test #14:

score: 0
Wrong Answer
time: 1ms
memory: 3940kb

input:

100
32 46 N
8 24 W
74 86 W
2 76 N
90 70 N
34 74 N
4 68 N
42 26 N
66 94 N
28 40 W
96 12 W
82 78 W
54 24 N
36 42 W
92 68 W
0 26 N
14 54 N
94 66 N
26 52 N
66 12 W
72 6 W
64 96 W
6 20 N
4 22 W
26 42 N
40 28 W
70 76 N
18 60 N
62 16 N
30 48 N
36 36 W
42 36 W
52 94 N
62 98 N
0 78 N
70 2 W
28 50 N
80 80 W
8...

output:

28
94

result:

FAIL Unexpected end of file - token expected (/var/uoj_data/9161/14.ans)

Subtask #3:

score: 0
Skipped

Dependency #2:

0%

Subtask #4:

score: 0
Skipped

Dependency #1:

100%
Accepted

Dependency #2:

0%

Subtask #5:

score: 0
Skipped

Dependency #4:

0%

Subtask #6:

score: 0
Wrong Answer

Test #58:

score: 0
Wrong Answer
time: 1979ms
memory: 264820kb

input:

200000
526715640 430855204 E
731546662 226024182 S
254814720 702756124 E
227354364 730216480 S
764250602 193320242 S
150102088 807468756 E
204858572 752712272 S
635512190 322058654 E
403910248 553660596 S
257917918 4587926 S
949444340 8126504 S
907805098 49765746 S
553836306 403734538 S
40977864 617...

output:

1
3
44
67
68
72
76
85
88
94
107
109
116
141
143
146
159
160
163
166
168
175
184
194
200
201
203
215
232
233
235
237
243
250
256
296
303
304
310
316
352
367
375
384
388
394
397
400
405
409
435
438
439
440
442
509
529
531
544
551
564
568
583
605
611
612
617
620
628
636
637
640
648
660
664
683
706
730
...

result:

FAIL Unexpected end of file - token expected (/var/uoj_data/9161/58.ans)

Subtask #7:

score: 0
Skipped

Dependency #1:

100%
Accepted

Dependency #2:

0%