Submission #1302330

#TimeUsernameProblemLanguageResultExecution timeMemory
1302330tuandqTowers (NOI22_towers)C++20
7 / 100
2097 ms73552 KiB
#include <bits/stdc++.h>
using namespace std ;

typedef long long ll ;
typedef long double ld ;
typedef pair<int, int> pii ;
typedef pair<int, long long> pil ;
typedef pair<long long, int> pli ;
typedef pair<long long, long long> pll ;

#define bitc(n) (__builtin_popcountll(n))
#define clz(n) (__builtin_clzll(n))
#define ctz(n) (__builtin_ctzll(n))
#define lgi(n) (31 - __builtin_clz(n))
#define lgl(n) (63 - __builtin_clzll(n))
#define MASK(k) (1ll << (k))
#define getbit(n, k) ((n) >> (k) & 1)
#define flipbit(n, k) ((n) ^ (1ll << (k)))
#define ton(n, k) ((n) | (1ll << (k)))
#define toff(n, k) ((n) & ~(1ll << (k)))

#define fi first
#define se second
#define mp make_pair
#define eb emplace_back
#define lwb lower_bound
#define upb upper_bound
#define sz(x) (int)(x.size())
#define all(x) x.begin(),x.end()
#define taskname "slamp"

template<class X, class Y>
bool maximize(X &x, const Y &y) {
    if(x < y) {
        return x = y, true ;
    }
    return false ;
}

template<class X, class Y>
bool minimize(X &x, const Y &y) {
    if(x > y) {
        return x = y, true ;
    }
    return false ;
}

template<class X>
void removeDup(vector<X> &ve) {
    sort(ve.begin(), ve.end()) ;
    ve.resize(unique(ve.begin(), ve.end()) - ve.begin()) ;
}

const ll INF = 1e18 ;
const int inf = 1e9 ;
const int mod = 1e9 + 7 ;
const int N = 1e6 + 5, LG = 17 ;

/* Some Peach Tea Is Great ;-; */
/* Author : Tuandq */

int n ;
pii a[N] ;

namespace sub6 {
    vector<pii> row[N], col[N] ;
    
    int maskRow[N], maskCol[N] ;
    bitset<N> mark ;
    
    void upset(const int &idx, int c, int r) {
        mark.set(idx) ; maskRow[a[idx].se] |= r ; maskCol[a[idx].fi] |= c ;
    }

    void solve() {
        for(int i = 1; i <= n; i ++) {
            col[a[i].fi].emplace_back(a[i].se, i) ;
            row[a[i].se].emplace_back(a[i].fi, i) ;
        }

        for(int i = 1; i < N; i ++) {
            sort(all(row[i])) ; sort(all(col[i])) ;
        }

        int le = 1, ri = N - 1, up = N - 1, dw = 0 ;
        while(true) {
            while(le <= ri && (col[le].empty() || maskCol[le] == 3)) ++ le ;
            while(ri >= le && (col[ri].empty() || maskCol[ri] == 3)) -- ri ;
            while(dw <= up && (row[dw].empty() || maskRow[dw] == 3)) ++ dw ;
            while(up >= dw && (row[up].empty() || maskRow[up] == 3)) -- up ;

            cerr << le << ' ' << ri << ' ' << dw << ' ' << up << endl ;

            if(le > ri || dw > up) break ;

            int p = 0, q = sz(col[le]) - 1 ;
            while(p < sz(col[le]) && col[le][p].fi < dw) ++ p ;
            while(q > 0 && col[le][q].fi > up) -- q ;
            if(p <= q) {
                if(p == q) upset(col[le][p].se, 3, 0) ;
                else {
                    upset(col[le][p].se, 1, 0) ;
                    upset(col[le][q].se, 2, 0) ;
                }
            }

            if(ri > le) {
                p = 0, q = sz(col[ri]) - 1 ;
                while(p < sz(col[ri]) && col[ri][p].fi < dw) ++ p ;
                while(q > 0 && col[ri][q].fi > up) -- q ;
                if(p <= q) {
                    if(p == q) upset(col[ri][p].se, 3, 0) ;
                    else {
                        upset(col[ri][p].se, 1, 0) ;
                        upset(col[ri][q].se, 2, 0) ;
                    }
                }
            }

            p = 0, q = sz(row[dw]) - 1 ;
            while(p < sz(row[dw]) && row[dw][p].fi < le) ++ p ;
            while(q > 0 && row[dw][q].fi > ri) -- q ;
            if(p <= q) {
                if(p == q) upset(row[dw][p].se, 0, 3) ;
                else {
                    upset(row[dw][p].se, 0, 1) ;
                    upset(row[dw][q].se, 0, 2) ;
                }
            }

            if(up > dw) {
                p = 0, q = sz(row[up]) - 1 ;
                while(p < sz(row[up]) && row[up][p].fi < le) ++ p ;
                while(q > 0 && row[up][q].fi > ri) -- q ;
                if(p <= q) {
                    if(p == q) upset(row[up][p].se, 0, 3) ;
                    else {
                        upset(row[up][p].se, 0, 1) ;
                        upset(row[up][q].se, 0, 2) ;
                    }
                }
            }
        }

        for(int i = 1; i <= n; i ++) cout << mark[i] ;
    }
}

void kittncool() {
    cin >> n ;
    for(int i = 1; i <= n; i ++) {
        cin >> a[i].fi >> a[i].se ;
    }

    return sub6::solve() ;
}

signed main() {
    ios_base::sync_with_stdio(0) ; cin.tie(0) ; cout.tie(0) ;
    if(fopen(taskname".inp", "r")) {
        freopen(taskname".inp", "r", stdin) ;
        freopen(taskname".out", "w", stdout) ;
    }

    int t = 1 ; //cin >> t ;
    while(t --) {
        kittncool() ;
    }
}

Compilation message (stderr)

Main.cpp: In function 'int main()':
Main.cpp:161:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  161 |         freopen(taskname".inp", "r", stdin) ;
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:162:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  162 |         freopen(taskname".out", "w", stdout) ;
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...