Submission #1105895

# Submission time Handle Problem Language Result Execution time Memory
1105895 2024-10-28T09:03:33 Z WeIlIaN Towers (NOI22_towers) C++14
100 / 100
749 ms 155856 KB
#include <bits/stdc++.h>
using namespace std;

#define MOD 1000000007
#define fir first
#define sec second
#define pushf push_front
#define pushb push_back
#define popf pop_front
#define popb pop_back
#define mp make_pair
#define all(a) a.begin(), a.end()

#define FOR(i, s, e) for(int i = s; i < e; i++)
#define RFOR(i, s, e) for(int i = e-1; i >= s; i--)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) RFOR(i, 0, n)

typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef pair<ll, ll> pll;
typedef vector<ll> vll;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef vector<vb> vvb;
typedef vector<vc> vvc;
typedef vector<vpii> vvpii;
typedef vector<vpll> vvpll;
typedef queue<int> qi;
typedef queue<ll> qll;
typedef queue<pii> qpii;
typedef queue<pll> qpll;
typedef deque<int> dqi;
typedef deque<ll> dqll;
typedef deque<pii> dqpii;
typedef deque<pll> dqpll;
typedef priority_queue<int> pqi;
typedef priority_queue<ll> pqll;
typedef priority_queue<pii> pqpii;
typedef priority_queue<pll> pqpll;
typedef priority_queue<int, vi, greater<int> > r_pqi;
typedef priority_queue<ll, vll, greater<ll> > r_pqll;
typedef priority_queue<pii, vpii, greater<pii> > r_pqpii;
typedef priority_queue<pll, vpll, greater<pll> > r_pqpll;

const int M = 1e6+5;

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n;
    cin>>n;
    vpii cities(n);
    vvi X(M);
    REP(i, n) {
        int x, y;
        cin>>x>>y;
        cities[i] = {x, y};
        X[x].pushb(y);
    }
    REP(i, M) {
        sort(all(X[i]));
    }
    vpii up(M, {M, M}), down(M);
    vpii chose(M, {-1, -1});
    REP(i, M) {
        int l = X[i].size();
        if(l == 0) {
            continue;
        }
        up[X[i][0]] = min(up[X[i][0]], {i, 0});
        down[X[i][0]] = max(down[X[i][0]], {i, 0});
        up[X[i][l-1]] = min(up[X[i][l-1]], {i, l-1});
        down[X[i][l-1]] = max(down[X[i][l-1]], {i, l-1});
        chose[i] = {0, l-1};
    }
    auto check = [&](int x, int y) -> bool {
        return (up[y].fir < x && x < down[y].fir);
    };
    qpii rem;
    REP(i, M) {
        int l = X[i].size();
        if(l == 0) {
            continue;
        }
        if(check(i, X[i][0])) {
            rem.push({i, 0});
            //cerr<<i<<' ';
        }
        if(l > 1 && check(i, X[i][l-1])) {
            rem.push({i, l-1});
            //cerr<<i<<' ';
        }
    }
    while(!rem.empty()) {
        auto [x, ind] = rem.front();
        rem.pop();
        auto [a, b] = chose[x];
        if(a == ind) {
            do {
                a++;
            } while(a <= b && check(x, X[x][a]));
            if(a > b) {
                chose[x] = {-1, -1};
                continue;
            }
            if(x < up[X[x][a]].fir) {
                if(up[X[x][a]].fir != down[X[x][a]].fir) {
                    rem.push(up[X[x][a]]);
                }
                up[X[x][a]] = {x, a};
            }
            if(down[X[x][a]].fir < x) {
                if(up[X[x][a]].fir != down[X[x][a]].fir) {
                    rem.push(down[X[x][a]]);
                }
                down[X[x][a]] = {x, a};
            }
        }
        else {
            do {
                b--;
            } while(a <= b && check(x, X[x][b]));
            if(a > b) {
                chose[x] = {-1, -1};
                continue;
            }
            if(x < up[X[x][b]].fir) {
                if(up[X[x][b]].fir != down[X[x][b]].fir) {
                    rem.push(up[X[x][b]]);
                }
                up[X[x][b]] = {x, b};
            }
            if(down[X[x][b]].fir < x) {
                if(up[X[x][b]].fir != down[X[x][b]].fir) {
                    rem.push(down[X[x][b]]);
                }
                down[X[x][b]] = {x, b};
            }
        }
        chose[x] = {a, b};
    }
    /*
    REP(i, 11) {
        cerr<<up[i].fir<<' '<<down[i].fir<<endl;
    }
    */
    map<pii, bool> ans;
    REP(i, M) {
        if(chose[i].fir == -1) {
            continue;
        }
        ans[{i, X[i][chose[i].fir]}] = true;
        ans[{i, X[i][chose[i].sec]}] = true;
    }
    REP(i, n) {
        if(ans[cities[i]]) {
            cout<<1;
        }
        else {
            cout<<0;
        }
    }
}

/*
16
9 10
2 10
5 10
6 3
6 1
5 8
6 7
9 8
4 3
6 10
4 8
2 7
2 1
5 7
4 1
9 3
*/

Compilation message

Main.cpp: In function 'int main()':
Main.cpp:103:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
  103 |         auto [x, ind] = rem.front();
      |              ^
Main.cpp:105:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
  105 |         auto [a, b] = chose[x];
      |              ^
# Verdict Execution time Memory Grader output
1 Correct 16 ms 47440 KB Output is correct
2 Correct 17 ms 47440 KB Output is correct
3 Correct 22 ms 47184 KB Output is correct
4 Correct 18 ms 47352 KB Output is correct
5 Correct 18 ms 47184 KB Output is correct
6 Correct 18 ms 47440 KB Output is correct
7 Correct 16 ms 47440 KB Output is correct
8 Correct 23 ms 47184 KB Output is correct
9 Correct 17 ms 47440 KB Output is correct
10 Correct 24 ms 47440 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 16 ms 47440 KB Output is correct
2 Correct 17 ms 47440 KB Output is correct
3 Correct 22 ms 47184 KB Output is correct
4 Correct 18 ms 47352 KB Output is correct
5 Correct 18 ms 47184 KB Output is correct
6 Correct 18 ms 47440 KB Output is correct
7 Correct 16 ms 47440 KB Output is correct
8 Correct 23 ms 47184 KB Output is correct
9 Correct 17 ms 47440 KB Output is correct
10 Correct 24 ms 47440 KB Output is correct
11 Correct 18 ms 47440 KB Output is correct
12 Correct 16 ms 47440 KB Output is correct
13 Correct 17 ms 47440 KB Output is correct
14 Correct 17 ms 47440 KB Output is correct
15 Correct 17 ms 47452 KB Output is correct
16 Correct 24 ms 47184 KB Output is correct
17 Correct 15 ms 47440 KB Output is correct
18 Correct 15 ms 47608 KB Output is correct
19 Correct 16 ms 47440 KB Output is correct
20 Correct 16 ms 47436 KB Output is correct
21 Correct 15 ms 47440 KB Output is correct
22 Correct 16 ms 47184 KB Output is correct
23 Correct 18 ms 47236 KB Output is correct
24 Correct 16 ms 47440 KB Output is correct
25 Correct 16 ms 47184 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 43 ms 55332 KB Output is correct
2 Correct 49 ms 56648 KB Output is correct
3 Correct 142 ms 75848 KB Output is correct
4 Correct 228 ms 104264 KB Output is correct
5 Correct 60 ms 57724 KB Output is correct
6 Correct 22 ms 49320 KB Output is correct
7 Correct 212 ms 100676 KB Output is correct
8 Correct 156 ms 83644 KB Output is correct
9 Correct 350 ms 127032 KB Output is correct
10 Correct 280 ms 113736 KB Output is correct
11 Correct 388 ms 130508 KB Output is correct
12 Correct 335 ms 130200 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 516 ms 154840 KB Output is correct
2 Correct 465 ms 154796 KB Output is correct
3 Correct 478 ms 154776 KB Output is correct
4 Correct 469 ms 154888 KB Output is correct
5 Correct 484 ms 154836 KB Output is correct
6 Correct 706 ms 155856 KB Output is correct
7 Correct 749 ms 155748 KB Output is correct
8 Correct 653 ms 155720 KB Output is correct
9 Correct 659 ms 155784 KB Output is correct
10 Correct 666 ms 155720 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 16 ms 47440 KB Output is correct
2 Correct 17 ms 47440 KB Output is correct
3 Correct 22 ms 47184 KB Output is correct
4 Correct 18 ms 47352 KB Output is correct
5 Correct 18 ms 47184 KB Output is correct
6 Correct 18 ms 47440 KB Output is correct
7 Correct 16 ms 47440 KB Output is correct
8 Correct 23 ms 47184 KB Output is correct
9 Correct 17 ms 47440 KB Output is correct
10 Correct 24 ms 47440 KB Output is correct
11 Correct 18 ms 47440 KB Output is correct
12 Correct 16 ms 47440 KB Output is correct
13 Correct 17 ms 47440 KB Output is correct
14 Correct 17 ms 47440 KB Output is correct
15 Correct 17 ms 47452 KB Output is correct
16 Correct 24 ms 47184 KB Output is correct
17 Correct 15 ms 47440 KB Output is correct
18 Correct 15 ms 47608 KB Output is correct
19 Correct 16 ms 47440 KB Output is correct
20 Correct 16 ms 47436 KB Output is correct
21 Correct 15 ms 47440 KB Output is correct
22 Correct 16 ms 47184 KB Output is correct
23 Correct 18 ms 47236 KB Output is correct
24 Correct 16 ms 47440 KB Output is correct
25 Correct 16 ms 47184 KB Output is correct
26 Correct 18 ms 47952 KB Output is correct
27 Correct 19 ms 47952 KB Output is correct
28 Correct 22 ms 47764 KB Output is correct
29 Correct 18 ms 47876 KB Output is correct
30 Correct 17 ms 47696 KB Output is correct
31 Correct 20 ms 47696 KB Output is correct
32 Correct 20 ms 47696 KB Output is correct
33 Correct 20 ms 47696 KB Output is correct
34 Correct 19 ms 47696 KB Output is correct
35 Correct 20 ms 47688 KB Output is correct
36 Correct 21 ms 47896 KB Output is correct
37 Correct 21 ms 47796 KB Output is correct
38 Correct 19 ms 47700 KB Output is correct
39 Correct 18 ms 47696 KB Output is correct
40 Correct 23 ms 47864 KB Output is correct
41 Correct 19 ms 47696 KB Output is correct
42 Correct 20 ms 47884 KB Output is correct
43 Correct 20 ms 47696 KB Output is correct
44 Correct 27 ms 47816 KB Output is correct
45 Correct 20 ms 47644 KB Output is correct
46 Correct 20 ms 47688 KB Output is correct
47 Correct 19 ms 47864 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 16 ms 47440 KB Output is correct
2 Correct 17 ms 47440 KB Output is correct
3 Correct 22 ms 47184 KB Output is correct
4 Correct 18 ms 47352 KB Output is correct
5 Correct 18 ms 47184 KB Output is correct
6 Correct 18 ms 47440 KB Output is correct
7 Correct 16 ms 47440 KB Output is correct
8 Correct 23 ms 47184 KB Output is correct
9 Correct 17 ms 47440 KB Output is correct
10 Correct 24 ms 47440 KB Output is correct
11 Correct 18 ms 47440 KB Output is correct
12 Correct 16 ms 47440 KB Output is correct
13 Correct 17 ms 47440 KB Output is correct
14 Correct 17 ms 47440 KB Output is correct
15 Correct 17 ms 47452 KB Output is correct
16 Correct 24 ms 47184 KB Output is correct
17 Correct 15 ms 47440 KB Output is correct
18 Correct 15 ms 47608 KB Output is correct
19 Correct 16 ms 47440 KB Output is correct
20 Correct 16 ms 47436 KB Output is correct
21 Correct 15 ms 47440 KB Output is correct
22 Correct 16 ms 47184 KB Output is correct
23 Correct 18 ms 47236 KB Output is correct
24 Correct 16 ms 47440 KB Output is correct
25 Correct 16 ms 47184 KB Output is correct
26 Correct 18 ms 47952 KB Output is correct
27 Correct 19 ms 47952 KB Output is correct
28 Correct 22 ms 47764 KB Output is correct
29 Correct 18 ms 47876 KB Output is correct
30 Correct 17 ms 47696 KB Output is correct
31 Correct 20 ms 47696 KB Output is correct
32 Correct 20 ms 47696 KB Output is correct
33 Correct 20 ms 47696 KB Output is correct
34 Correct 19 ms 47696 KB Output is correct
35 Correct 20 ms 47688 KB Output is correct
36 Correct 21 ms 47896 KB Output is correct
37 Correct 21 ms 47796 KB Output is correct
38 Correct 19 ms 47700 KB Output is correct
39 Correct 18 ms 47696 KB Output is correct
40 Correct 23 ms 47864 KB Output is correct
41 Correct 19 ms 47696 KB Output is correct
42 Correct 20 ms 47884 KB Output is correct
43 Correct 20 ms 47696 KB Output is correct
44 Correct 27 ms 47816 KB Output is correct
45 Correct 20 ms 47644 KB Output is correct
46 Correct 20 ms 47688 KB Output is correct
47 Correct 19 ms 47864 KB Output is correct
48 Correct 91 ms 58696 KB Output is correct
49 Correct 100 ms 58696 KB Output is correct
50 Correct 114 ms 57672 KB Output is correct
51 Correct 114 ms 57672 KB Output is correct
52 Correct 74 ms 56420 KB Output is correct
53 Correct 65 ms 56404 KB Output is correct
54 Correct 65 ms 56408 KB Output is correct
55 Correct 57 ms 56504 KB Output is correct
56 Correct 57 ms 56528 KB Output is correct
57 Correct 56 ms 56524 KB Output is correct
58 Correct 56 ms 56392 KB Output is correct
59 Correct 58 ms 56392 KB Output is correct
60 Correct 59 ms 56436 KB Output is correct
61 Correct 57 ms 56404 KB Output is correct
62 Correct 63 ms 56444 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 16 ms 47440 KB Output is correct
2 Correct 17 ms 47440 KB Output is correct
3 Correct 22 ms 47184 KB Output is correct
4 Correct 18 ms 47352 KB Output is correct
5 Correct 18 ms 47184 KB Output is correct
6 Correct 18 ms 47440 KB Output is correct
7 Correct 16 ms 47440 KB Output is correct
8 Correct 23 ms 47184 KB Output is correct
9 Correct 17 ms 47440 KB Output is correct
10 Correct 24 ms 47440 KB Output is correct
11 Correct 18 ms 47440 KB Output is correct
12 Correct 16 ms 47440 KB Output is correct
13 Correct 17 ms 47440 KB Output is correct
14 Correct 17 ms 47440 KB Output is correct
15 Correct 17 ms 47452 KB Output is correct
16 Correct 24 ms 47184 KB Output is correct
17 Correct 15 ms 47440 KB Output is correct
18 Correct 15 ms 47608 KB Output is correct
19 Correct 16 ms 47440 KB Output is correct
20 Correct 16 ms 47436 KB Output is correct
21 Correct 15 ms 47440 KB Output is correct
22 Correct 16 ms 47184 KB Output is correct
23 Correct 18 ms 47236 KB Output is correct
24 Correct 16 ms 47440 KB Output is correct
25 Correct 16 ms 47184 KB Output is correct
26 Correct 43 ms 55332 KB Output is correct
27 Correct 49 ms 56648 KB Output is correct
28 Correct 142 ms 75848 KB Output is correct
29 Correct 228 ms 104264 KB Output is correct
30 Correct 60 ms 57724 KB Output is correct
31 Correct 22 ms 49320 KB Output is correct
32 Correct 212 ms 100676 KB Output is correct
33 Correct 156 ms 83644 KB Output is correct
34 Correct 350 ms 127032 KB Output is correct
35 Correct 280 ms 113736 KB Output is correct
36 Correct 388 ms 130508 KB Output is correct
37 Correct 335 ms 130200 KB Output is correct
38 Correct 516 ms 154840 KB Output is correct
39 Correct 465 ms 154796 KB Output is correct
40 Correct 478 ms 154776 KB Output is correct
41 Correct 469 ms 154888 KB Output is correct
42 Correct 484 ms 154836 KB Output is correct
43 Correct 706 ms 155856 KB Output is correct
44 Correct 749 ms 155748 KB Output is correct
45 Correct 653 ms 155720 KB Output is correct
46 Correct 659 ms 155784 KB Output is correct
47 Correct 666 ms 155720 KB Output is correct
48 Correct 18 ms 47952 KB Output is correct
49 Correct 19 ms 47952 KB Output is correct
50 Correct 22 ms 47764 KB Output is correct
51 Correct 18 ms 47876 KB Output is correct
52 Correct 17 ms 47696 KB Output is correct
53 Correct 20 ms 47696 KB Output is correct
54 Correct 20 ms 47696 KB Output is correct
55 Correct 20 ms 47696 KB Output is correct
56 Correct 19 ms 47696 KB Output is correct
57 Correct 20 ms 47688 KB Output is correct
58 Correct 21 ms 47896 KB Output is correct
59 Correct 21 ms 47796 KB Output is correct
60 Correct 19 ms 47700 KB Output is correct
61 Correct 18 ms 47696 KB Output is correct
62 Correct 23 ms 47864 KB Output is correct
63 Correct 19 ms 47696 KB Output is correct
64 Correct 20 ms 47884 KB Output is correct
65 Correct 20 ms 47696 KB Output is correct
66 Correct 27 ms 47816 KB Output is correct
67 Correct 20 ms 47644 KB Output is correct
68 Correct 20 ms 47688 KB Output is correct
69 Correct 19 ms 47864 KB Output is correct
70 Correct 91 ms 58696 KB Output is correct
71 Correct 100 ms 58696 KB Output is correct
72 Correct 114 ms 57672 KB Output is correct
73 Correct 114 ms 57672 KB Output is correct
74 Correct 74 ms 56420 KB Output is correct
75 Correct 65 ms 56404 KB Output is correct
76 Correct 65 ms 56408 KB Output is correct
77 Correct 57 ms 56504 KB Output is correct
78 Correct 57 ms 56528 KB Output is correct
79 Correct 56 ms 56524 KB Output is correct
80 Correct 56 ms 56392 KB Output is correct
81 Correct 58 ms 56392 KB Output is correct
82 Correct 59 ms 56436 KB Output is correct
83 Correct 57 ms 56404 KB Output is correct
84 Correct 63 ms 56444 KB Output is correct
85 Correct 18 ms 47184 KB Output is correct
86 Correct 18 ms 47184 KB Output is correct
87 Correct 19 ms 47440 KB Output is correct
88 Correct 696 ms 152136 KB Output is correct
89 Correct 646 ms 152136 KB Output is correct
90 Correct 679 ms 152136 KB Output is correct
91 Correct 582 ms 139428 KB Output is correct
92 Correct 569 ms 139276 KB Output is correct
93 Correct 605 ms 139080 KB Output is correct
94 Correct 563 ms 138664 KB Output is correct
95 Correct 536 ms 138720 KB Output is correct
96 Correct 554 ms 138692 KB Output is correct
97 Correct 588 ms 138544 KB Output is correct
98 Correct 541 ms 138648 KB Output is correct
99 Correct 611 ms 138568 KB Output is correct
100 Correct 507 ms 137480 KB Output is correct
101 Correct 517 ms 137544 KB Output is correct
102 Correct 455 ms 137288 KB Output is correct
103 Correct 478 ms 137452 KB Output is correct
104 Correct 466 ms 137228 KB Output is correct
105 Correct 494 ms 137232 KB Output is correct
106 Correct 485 ms 136264 KB Output is correct
107 Correct 491 ms 136180 KB Output is correct