Submission #631126

# Submission time Handle Problem Language Result Execution time Memory
631126 2022-08-17T17:36:49 Z Soul234 Plahte (COCI17_plahte) C++14
160 / 160
300 ms 40180 KB
#include<bits/stdc++.h>
using namespace std;

void DBG() { cerr << "]\n"; }
template<class H, class... T> void DBG(H h, T... t) {
    cerr << h; if(sizeof...(t)) cerr << ", ";
    DBG(t...);
}
#ifdef LOCAL
#define dbg(...) cerr << "[" << #__VA_ARGS__ << "]: [", DBG(__VA_ARGS__)
#else
#define dbg(...) 0
#endif // LOCAL

#define FOR(i,a,b) for(int i = (a) ; i<(b) ; i++)
#define F0R(i,a) FOR(i,0,a)
#define ROF(i,a,b) for(int i = (b)-1 ; i>=(a) ; i--)
#define R0F(i,a) ROF(i,0,a)
#define each(e,a) for(auto &e : (a))
#define sz(v) (int)(v).size()
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define pb push_back
#define tcT template<class T
#define nl "\n"

using ll = long long;
using vi = vector<int>;
using pi = pair<int,int>;
using str = string;
tcT> using V = vector<T>;
tcT> using pqg = priority_queue<T,vector<T>,greater<T>>;

void setIO(string NAME = "") {
    cin.tie(0)->sync_with_stdio(0);
    if(sz(NAME)) {
        freopen((NAME + ".inp").c_str(),"r",stdin);
        freopen((NAME + ".out").c_str(),"w",stdout);
    }
}

tcT> bool ckmin(T&a, const T&b) {
    return b < a ? a=b,1 : 0; }
tcT> bool ckmax(T&a, const T&b) {
    return b > a ? a=b,1 : 0; }

const int MOD = 1e9 + 7;

struct SegTree {
    int N;
    vi seg, lazy;
    int comb(int a, int b) {
        return max(a,b);
    }
    void init(int _N = 0) {
        N = _N;
        seg.assign(N*4 + 7, 0);
        lazy.assign(N*4 + 7, -1);
    }
    void push(int ind) {
        if(lazy[ind] == -1) return;
        F0R(i, 2) {
            seg[ind*2 + i] = lazy[ind];
            lazy[ind*2 + i] = lazy[ind];
        }
        lazy[ind] = -1;
    }
    void upd(int l, int r, int val, int ind, int L, int R) {
        if(L > R || l > r || l > R || r < L) return;
        if(l <= L && R <= r) {
            seg[ind] = val;
            lazy[ind] = val;
            return;
        }
        push(ind);
        int mid = (L + R) >> 1;
        upd(l, r, val, ind<<1, L, mid);
        upd(l, r, val, ind<<1|1, mid+1, R);
        seg[ind] = comb(seg[ind<<1], seg[ind<<1|1]);
    }
    void upd(int l, int r, int val) {
        upd(l, r, val, 1, 1, N);
    }
    int query(int p, int ind, int L, int R) {
        if(L == R) return seg[ind];
        int mid = (L + R) >> 1;
        push(ind);
        if(p <= mid) return query(p, ind<<1, L, mid);
        return query(p, ind<<1|1, mid+1, R);
    }
    int query(int p) {
        return query(p, 1, 1, N);
    }
};

SegTree st;

struct Dat {
    int tt, evntype, l, r, pos;
    Dat(int _tt = 0, int _evntype = 0, int _l = 0, int _r = 0, int _pos = 0) {
        tt = _tt;
        evntype = _evntype;
        l = _l;
        r = _r;
        pos = _pos;
    }
    bool operator<(const Dat&rhs) const {
        if(tt == rhs.tt) return evntype < rhs.evntype;
        return tt < rhs.tt;
    }
};

const int MX = 1e5+5;
vi adj[MX];

int N, A[MX], B[MX], C[MX], D[MX], X[MX], Y[MX], K[MX], M;
vi ys;
V<Dat> evn;

int par[MX], ans[MX];
set<int> col[MX];

int getind(const vi&v, const int&val) {
    return lower_bound(all(v), val) - begin(v) + 1;
}

void dfs(int u) {
    each(v, adj[u]) {
        dfs(v);
        if(sz(col[u]) < sz(col[v])) swap(col[u], col[v]);
        each(c, col[v]) col[u].insert(c);
    }
    ans[u] = sz(col[u]);
}

void solve() {
    cin >> N >> M;
    FOR(i,1,N+1) {
        cin >> A[i] >> B[i] >> C[i] >> D[i];
        ys.pb(B[i]);
        ys.pb(D[i]);
    }
    FOR(i,1,M+1) {
        cin >> X[i] >> Y[i] >> K[i];
        ys.pb(Y[i]);
    }
    sort(all(ys)); ys.erase(unique(all(ys)), ys.end());
    FOR(i,1,N+1) {
        B[i] = getind(ys, B[i]);
        D[i] = getind(ys, D[i]);
        evn.pb(Dat(A[i], 0, B[i], D[i], i));
        evn.pb(Dat(C[i], 2, B[i], D[i], i));
    }
    FOR(i,1,M+1) {
        Y[i] = getind(ys, Y[i]);
        evn.pb(Dat(X[i], 1, Y[i], Y[i], i));
    }
    sort(all(evn));

    st.init(sz(ys) + 5);
    F0R(i,sz(evn)) {
        if(evn[i].evntype == 0) {
            par[evn[i].pos] = st.query(evn[i].l);
            st.upd(evn[i].l, evn[i].r, evn[i].pos);
        }
        else if(evn[i].evntype == 1) {
            col[st.query(evn[i].l)].insert(K[evn[i].pos]);
        }
        else {
            st.upd(evn[i].l, evn[i].r, par[evn[i].pos]);
        }
    }
    FOR(i,1,N+1) {
        adj[par[i]].pb(i);
    }
    dfs(0);
    FOR(i,1,N+1) cout << ans[i] << nl;
}

int main() {
    setIO();

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

    return 0;
}

Compilation message

plahte.cpp: In function 'void setIO(std::string)':
plahte.cpp:37:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   37 |         freopen((NAME + ".inp").c_str(),"r",stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
plahte.cpp:38:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   38 |         freopen((NAME + ".out").c_str(),"w",stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 77 ms 16772 KB Output is correct
2 Correct 77 ms 17392 KB Output is correct
3 Correct 4 ms 7384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 90 ms 18988 KB Output is correct
2 Correct 93 ms 18208 KB Output is correct
3 Correct 4 ms 7380 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 151 ms 27728 KB Output is correct
2 Correct 150 ms 24540 KB Output is correct
3 Correct 5 ms 7380 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 258 ms 40180 KB Output is correct
2 Correct 300 ms 36284 KB Output is correct
3 Correct 4 ms 7380 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 253 ms 38020 KB Output is correct
2 Correct 264 ms 34608 KB Output is correct
3 Correct 4 ms 7380 KB Output is correct