QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#498703#9161. Naval battlebashkort#6 1333ms293736kbC++207.9kb2024-07-30 18:36:142024-07-30 18:36:14

Judging History

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

  • [2024-07-30 18:36:14]
  • 评测
  • 测评结果:6
  • 用时:1333ms
  • 内存:293736kb
  • [2024-07-30 18:36:14]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;
using ll = long long;

set<array<int, 3>> best;

struct Struct {
    vector<int> x, type;
    vector<int> nxt, prv, in, id;
    set<pair<int, int>> st;
    map<int, int> pos;
    int n, coef, idi;

    void init(vector<array<int, 3>> a, int coef, int idi) {
        this->coef = coef, this->idi = idi;
        sort(a.begin(), a.end());
        n = a.size();
        nxt.assign(n, -1);
        prv.assign(n, -1);
        in.assign(n, -1);
        x.assign(n, 0);
        type.assign(n, 0);
        id.assign(n, 0);
        for (int i = 0; i < n; ++i) {
            nxt[i] = i + 1, prv[i] = i - 1;
            x[i] = a[i][0], type[i] = a[i][1];
            pos[a[i][2]] = i;
            id[i] = a[i][2];
        }
        for (int i = 0; i < n - 1; ++i) {
            if (type[i] == 1 && type[i + 1] == 2) {
                st.emplace(in[i] = x[i + 1] - x[i], i);
            }
        }
    }

    int top() {
        return st.empty() ? int(2e9) : st.begin()->first;
    }

    void modify(int mod) {
        if (mod == -1) {
            best.erase({top(), coef, idi});
        } else {
            best.insert({top(), coef, idi});
        }
    }

    void erase_(int i) {
        if (prv[i] == -1 && nxt[i] == -1) {
            return;
        }
        if (in[i] >= 0) {
            st.erase({in[i], i});
            in[i] = -1;
        }
        if (prv[i] >= 0 && in[prv[i]] >= 0) {
            st.erase({in[prv[i]], prv[i]});
            in[prv[i]] = -1;
        }
        int p = prv[i], nx = nxt[i];
        prv[i] = -1, nxt[i] = n;
        if (p != -1) {
            nxt[p] = nx;
        }
        if (nx != n) {
            prv[nx] = p;
            if (p != -1 && type[p] == 1 && type[nx] == 2) {
                st.emplace(in[p] = x[nx] - x[p], p);
            }
        }
        prv[i] = nxt[i] = -1;
    }

    void erase(int i) {
        modify(-1);
        if (pos.count(i)) {
            pos.erase(i);
            erase_(pos[i]);
        }
        modify(1);
    }

    vector<int> norm() {
        modify(-1);
//        if (coef == -2 && idi == 1) {
//            cout << "here!" << endl;
//        }
        int t = top();
        vector<int> dead;
        while (!st.empty() && st.begin()->first == t) {
            dead.push_back(st.begin()->second);
            dead.push_back(nxt[dead.back()]);
            st.erase(st.begin());
        }
        for (int i : dead) {
            erase_(i);
        }
        vector<int> ids;
        for (int i : dead) {
            ids.push_back(id[i]);
        }
        modify(1);
        return ids;
    }
};

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int n;
    cin >> n;
    vector<pair<int, int>> p(n);
    vector<int> type(n);
    map<int, vector<int>> SW, SE, NE, NW, X, Y;
    for (int i = 0; i < n; ++i) {
        int x, y;
        cin >> x >> y;
        y = 8 - y;
        p[i] = {x, y};
        char c;
        cin >> c;
        if (c == 'N') {
            NE[x + y].push_back(i);
            NW[x - y].push_back(i);
            X[x].push_back(i);
            type[i] = 0;
        } else if (c == 'E') {
            NE[x + y].push_back(i);
            SE[x - y].push_back(i);
            Y[y].push_back(i);
            type[i] = 1;
        } else if (c == 'S') {
            SE[x - y].push_back(i);
            SW[x + y].push_back(i);
            X[x].push_back(i);
            type[i] = 2;
        } else {
            NW[x - y].push_back(i);
            SW[x + y].push_back(i);
            Y[y].push_back(i);
            type[i] = 3;
        }
    }

    auto makeStruct = [&](vector<int> id, vector<int> y, vector<int> type, int coef, int idi) {
        Struct s;
        vector<array<int, 3>> a(id.size());
        for (int i = 0; i < a.size(); ++i) {
            a[i][0] = y[i], a[i][1] = type[i], a[i][2] = id[i];
        }
        s.init(a, coef, idi);
        return s;
    };

    vector<pair<int, Struct>> s[6];

    for (auto [coef, a] : SW) {
        vector<int> id, y, tp;
        for (int i : a) {
            id.push_back(i);
            y.push_back(p[i].first);
            tp.push_back(type[i] == 2 ? 1 : 2);
        }
        s[0].push_back({coef, makeStruct(id, y, tp, coef, 0)});
    }
    for (auto [coef, a] : SE) {
        vector<int> id, y, tp;
        for (int i : a) {
            id.push_back(i);
            y.push_back(p[i].first);
            tp.push_back(type[i] == 2 ? 2 : 1);
        }
        s[1].push_back({coef, makeStruct(id, y, tp, coef, 1)});
    }

    for (auto [coef, a] : NE) {
        vector<int> id, y, tp;
        for (int i : a) {
            id.push_back(i);
            y.push_back(p[i].first);
            tp.push_back(type[i] == 0 ? 2 : 1);
        }
        s[2].push_back({coef, makeStruct(id, y, tp, coef, 2)});
    }
    for (auto [coef, a] : NW) {
        vector<int> id, y, tp;
        for (int i : a) {
            id.push_back(i);
            y.push_back(p[i].first);
            tp.push_back(type[i] == 0 ? 1 : 2);
        }
        s[3].push_back({coef, makeStruct(id, y, tp, coef, 3)});
    }

    for (auto [coef, a] : X) {
        vector<int> id, y, tp;
        for (int i : a) {
            id.push_back(i);
            y.push_back(p[i].second / 2);
            tp.push_back(type[i] == 0 ? 2 : 1);
        }
        s[4].push_back({coef, makeStruct(id, y, tp, coef, 4)});
    }
    for (auto [coef, a] : X) {
        vector<int> id, y, tp;
        for (int i : a) {
            id.push_back(i);
            y.push_back(p[i].first / 2);
            tp.push_back(type[i] == 1 ? 1 : 2);
        }
        s[5].push_back({coef, makeStruct(id, y, tp, coef, 5)});
    }

    for (int i = 0; i < 6; ++i) {
        for (auto &[coef, str] : s[i]) {
            best.insert({str.top(), coef, i});
        }
    }

    vector<int> del(n);

    auto find = [&](int i, int coef) {
        int lo = 0, hi = s[i].size();
        while (lo + 1 < hi) {
            int mid = lo + hi >> 1;
            if (s[i][mid].first > coef) {
                hi = mid;
            } else {
                lo = mid;
            }
        }
        return lo;
    };

    while (!best.empty()) {
        int t = best.begin()->begin()[0];
        if (t >= 1.5e9) {
            break;
        }
        vector<array<int, 3>> cur;
        while (!best.empty() && best.begin()->begin()[0] == t) {
            cur.push_back(*best.begin());
            best.erase(best.begin());
        }
        vector<int> died;
        for (auto [val, coef, i] : cur) {
            int pos = find(i, coef);
            auto now = s[i][pos].second.norm();
            died.insert(died.end(), now.begin(), now.end());
        }
        sort(died.begin(), died.end());
        died.resize(unique(died.begin(), died.end()) - died.begin());
        for (int i : died) {
            del[i] = true;
            auto [x, y] = p[i];
            if (type[i] == 0) {
                s[2][find(2, x + y)].second.erase(i);
                s[3][find(3, x - y)].second.erase(i);
                s[4][find(4, x)].second.erase(i);
            } else if (type[i] == 1) {
                s[2][find(2, x + y)].second.erase(i);
                s[1][find(1, x - y)].second.erase(i);
                s[5][find(5, y)].second.erase(i);
            } else if (type[i] == 2) {
                s[1][find(1, x - y)].second.erase(i);
                s[0][find(0, x + y)].second.erase(i);
                s[4][find(4, x)].second.erase(i);
            } else {
                s[3][find(3, x - y)].second.erase(i);
                s[0][find(0, x + y)].second.erase(i);
                s[5][find(5, y)].second.erase(i);
            }
        }
    }

    for (int i = 0; i < n; ++i) {
        if (!del[i]) {
            cout << i + 1 << '\n';
        }
    }

    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 6
Accepted

Test #1:

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

input:

2
675333810 792019962 W
851860476 960355168 W

output:

1
2

result:

ok 

Test #2:

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

input:

2
714148610 688520844 W
359519570 789553998 S

output:

1
2

result:

ok 

Test #3:

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

input:

2
743286406 87591094 E
108453484 326740470 S

output:

1
2

result:

ok 

Test #4:

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

input:

2
629499666 659260200 W
391550936 897208930 N

output:


result:

ok 

Test #5:

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

input:

2
509095668 374922996 W
325521434 191348762 S

output:


result:

ok 

Test #6:

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

input:

2
357656592 713571312 E
456601638 614626266 S

output:


result:

ok 

Test #7:

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

input:

2
353512742 374956722 W
265604916 462864548 N

output:


result:

ok 

Test #8:

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

input:

2
253519292 302668732 E
436627396 119560628 S

output:


result:

ok 

Test #9:

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

input:

2
741954822 709863076 W
516385128 484293380 S

output:

1
2

result:

ok 

Test #10:

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

input:

2
268851874 524109226 E
503673708 758931058 N

output:

1
2

result:

ok 

Test #11:

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

input:

2
629380956 395789270 S
557401140 467769088 E

output:

1
2

result:

ok 

Test #12:

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

input:

2
606361496 587557658 N
667076156 526843000 W

output:

1
2

result:

ok 

Test #13:

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

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: 3724kb

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:

6
7
11
17
26
33
35
41
52
56
64
70

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: 1333ms
memory: 293736kb

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:

4145
6111
10386
15506
41431
56511
56869
78188
79720
79798
95110
98272
99115
113756
118225
129855
136984
147293
155812
156482
180470
181412

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%