QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#182571#6414. Classical Maximization ProblemjackwasWA 86ms8932kbC++143.6kb2023-09-18 08:54:272023-09-18 08:54:28

Judging History

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

  • [2023-09-18 08:54:28]
  • 评测
  • 测评结果:WA
  • 用时:86ms
  • 内存:8932kb
  • [2023-09-18 08:54:27]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define pb push_back
#define el << '\n'
#define spe << ' '
#define sp spe <<
#define umap unordered_map
#define uset unordered_set
#define prqu priority_queue
#define fornr(i, j, n) for (int i = j; i < n; i++)
#define forn(i, n) for (int i = 0; i < n; i++)
#define forn1(i, n) for (int i = 1; i <= n; i++)
#define fornrb(i, j, n) for (int i = n - 1; i >= j; i--)
#define fornb(i, n) for (int i = n - 1; i >= 0; i--)
#define forn1b(i, n) for (i = n; i > 0; i--)
#define fornn(i, n) for (int i = 1; i <= n; i++)
#define rety cout << "YES\n"; return 0;
#define retn cout << "NO\n"; return 0;
#define conty cout << "YES\n"; continue;
#define contn cout << "NO\n"; continue;
#define all(x) x.begin(), x.end()
#define mp make_pair
#define pb push_back
const int IMX = 2e9 + 5;
const ll LMX = 4e18 + 10, MOD = 1e9 + 7, MOD2 = 998244353;

const int MAXN = 1e5 + 5;

int x[MAXN], y[MAXN], n;
vector<int> gx[MAXN], gy[MAXN], ans1, ans2;
bool visited[MAXN], used[MAXN];

void dfs(int p, int f = MAXN - 1) {
    visited[p] = 1;
    forn(i, gx[x[p]].size()) {
        int nx = gx[x[p]][i];
        if (nx == p || nx == f) continue;
        if (!visited[nx]) dfs(nx, p);
        if (!used[p] && !used[nx]) {
            used[p] = 1;
            used[nx] = 1;
            ans1.pb(p);
            ans2.pb(nx);
        }
    }
    forn(i, gy[y[p]].size()) {
        int nx = gy[y[p]][i];
        if (nx == p || nx == f) continue;
        if (!visited[nx]) dfs(nx, p);
        if (!used[p] && !used[nx]) {
            used[p] = 1;
            used[nx] = 1;
            ans1.pb(p);
            ans2.pb(nx);
        }
    }
    if (!used[p] && f < n && !used[f]) {
        used[f] = 1;
        used[p] = 1;
        ans1.pb(f);
        ans2.pb(p);
    }
}

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

    int t;
    cin >> t;
    while (t--) {
        cin >> n;
        n *= 2;
        set<int> xv, yv;
        vector<int> sx, sy;
        forn(i, n) {
            cin >> x[i] >> y[i];
            if (xv.insert(x[i]).second) sx.pb(x[i]);
            if (yv.insert(y[i]).second) sy.pb(y[i]);
            visited[i] = 0;
            used[i] = 0;
            gx[i].clear();
            gy[i].clear();
            ans1.clear();
            ans2.clear();
        }
        sort(sx.begin(), sx.end());
        sort(sy.begin(), sy.end());
        forn(i, n) {
            int l = 0, r = sx.size() - 1;
            while (l < r) {
                int m = (l + r) / 2;
                if (sx[m] == x[i]) {
                    l = m;
                    r = m;
                } else if (sx[m] < x[i]) l = m + 1;
                else r = m - 1;
            }
            x[i] = l;
            l = 0, r = sy.size() - 1;
            while (l < r) {
                int m = (l + r) / 2;
                if (sy[m] == y[i]) {
                    l = m;
                    r = m;
                } else if (sy[m] < y[i]) l = m + 1;
                else r = m - 1;
            }
            y[i] = l;
            gx[x[i]].pb(i);
            gy[y[i]].pb(i);
        }
        forn(i, n) {
            if (!visited[i]) dfs(i);
        }
        cout << ans1.size() el;
        forn(i, ans1.size()) cout << ans1[i] + 1 sp ans2[i] + 1 el;
        vector<int> ans3;
        forn(i, n) if (!used[i]) ans3.pb(i + 1);
        forn(i, ans3.size()) {
            cout << ans3[i] sp ans3[i + 1] el;
            i++;
        }
    }
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 2ms
memory: 8328kb

input:

3
2
0 0
0 1
1 0
1 1
2
0 0
0 1
0 2
0 3
2
0 0
1 1
2 2
3 3

output:

2
3 1
2 4
2
3 1
4 2
0
1 2
3 4

result:

ok ok (3 test cases)

Test #2:

score: 0
Accepted
time: 86ms
memory: 8604kb

input:

10000
2
-107276936 -310501829
419434212 585811870
-65754386 -491212232
381152038 897148193
3
-474045168 493506332
299114415 540203303
165808153 983551
-506936261 -694189769
766718170 -725540031
975267148 -593051087
1
-818952276 -762387923
584023914 -612401389
6
-77701228 -266484128
659434465 6322062...

output:

0
1 2
3 4
0
1 2
3 4
5 6
0
1 2
0
1 2
3 4
5 6
7 8
9 10
11 12
0
1 2
3 4
5 6
7 8
9 10
11 12
13 14
0
1 2
0
1 2
3 4
5 6
7 8
9 10
11 12
13 14
15 16
17 18
19 20
21 22
23 24
25 26
27 28
29 30
31 32
33 34
35 36
37 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
0
1 2
3 4...

result:

ok ok (10000 test cases)

Test #3:

score: 0
Accepted
time: 79ms
memory: 8584kb

input:

10000
1
999855386 999580905
999342928 999615227
21
999601032 999015398
999155628 999176944
999309856 999524434
999121011 999509537
999323572 999685730
999272272 999769606
999450559 999390758
999632027 999178534
999024993 999463838
999784856 999374197
999980525 999366771
999241260 999516879
999599548...

output:

0
1 2
0
1 2
3 4
5 6
7 8
9 10
11 12
13 14
15 16
17 18
19 20
21 22
23 24
25 26
27 28
29 30
31 32
33 34
35 36
37 38
39 40
41 42
0
1 2
3 4
5 6
7 8
9 10
11 12
13 14
15 16
17 18
19 20
21 22
23 24
25 26
27 28
29 30
0
1 2
3 4
5 6
7 8
9 10
11 12
13 14
15 16
17 18
19 20
21 22
23 24
25 26
27 28
0
1 2
3 4
5 6
7...

result:

ok ok (10000 test cases)

Test #4:

score: 0
Accepted
time: 79ms
memory: 8824kb

input:

10000
5
999984799 999981445
999958394 999984217
999994978 999981258
999955539 999938710
999936554 999963561
999907222 999907508
999938166 999941959
999910567 999986887
999901446 999961092
999994730 999963038
5
999916115 999962400
999948250 999940355
999954204 999920844
999928148 999990369
999978118 ...

output:

0
1 2
3 4
5 6
7 8
9 10
0
1 2
3 4
5 6
7 8
9 10
0
1 2
3 4
5 6
7 8
9 10
11 12
13 14
15 16
17 18
19 20
21 22
0
1 2
3 4
5 6
7 8
0
1 2
3 4
5 6
7 8
9 10
11 12
13 14
15 16
17 18
19 20
21 22
23 24
25 26
27 28
29 30
31 32
0
1 2
3 4
5 6
7 8
9 10
0
1 2
3 4
5 6
7 8
9 10
11 12
13 14
15 16
0
1 2
3 4
5 6
7 8
9 10
1...

result:

ok ok (10000 test cases)

Test #5:

score: 0
Accepted
time: 79ms
memory: 8364kb

input:

10000
1
999990146 999993828
999995909 999996353
56
999999851 999991179
999997250 999997987
999990590 999997316
999997350 999996856
999997034 999996236
999999396 999996897
999991180 999993309
999991265 999995185
999993952 999994054
999990210 999994471
999993201 999995893
999997170 999998971
999998201...

output:

0
1 2
1
76 111
1 2
3 4
5 6
7 8
9 10
11 12
13 14
15 16
17 18
19 20
21 22
23 24
25 26
27 28
29 30
31 32
33 34
35 36
37 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 77
78 79
80 81
82 83
84 85
86 87
88 89
90 91
92 93
94 95
96 97
98 99
...

result:

ok ok (10000 test cases)

Test #6:

score: -100
Wrong Answer
time: 83ms
memory: 8932kb

input:

10000
5
999999432 999999813
999999271 999999233
999999043 999999606
999999523 999999406
999999564 999999274
999999641 999999102
999999903 999999858
999999058 999999098
999999974 999999119
999999643 999999620
5
999999370 999999738
999999181 999999907
999999163 999999783
999999393 999999086
999999661 ...

output:

0
1 2
3 4
5 6
7 8
9 10
0
1 2
3 4
5 6
7 8
9 10
0
1 2
3 4
5 6
0
1 2
3 4
5 6
7 8
9 10
1
9 10
1 2
3 4
5 6
7 8
11 12
13 14
15 16
17 18
19 20
21 22
23 24
25 26
27 28
29 30
31 32
33 34
1
12 13
1 2
3 4
5 6
7 8
9 10
11 14
15 16
0
1 2
3 4
0
1 2
3 4
1
10 44
1 2
3 4
5 6
7 8
9 11
12 13
14 15
16 17
18 19
20 21
22...

result:

wrong answer worse than author's solution: expected 15, found 14 (test case 2133)