Submission #1125009

#TimeUsernameProblemLanguageResultExecution timeMemory
1125009otariusPlahte (COCI17_plahte)C++20
160 / 160
379 ms66488 KiB
#include <bits/stdc++.h>
#include <bits/extc++.h>
using namespace __gnu_pbds;
using namespace std;

// #pragma GCC optimize("Ofast")
// #pragma GCC optimize ("unroll-loops")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#define ff first
#define sc second
#define pb push_back
#define ll long long
#define pll pair<ll, ll>
#define pii pair<int, int>
#define ull unsigned long long
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
mt19937_64 rngl(chrono::steady_clock::now().time_since_epoch().count());

// #define int long long
// #define int unsigned long long

// #define ordered_set(T) tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>
// #define ordered_multiset(T) tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>

void open_file(string filename) {
    freopen((filename + ".in").c_str(), "r", stdin);
    freopen((filename + ".out").c_str(), "w", stdout);
}

// const ll mod = 1e9 + 7;
// const ll mod = 998244353;

const ll inf = 1e9;
const ll biginf = 1e18;
const int maxN = 2 * 1e5 + 25;

struct node {
    int y, l, r, id; bool f;
    node(int _y, int _l, int _r, int _id, bool _f) {
        y = _y; l = _l; r = _r; id = _id; f = _f;
    }
};
bool comp(node a, node b) {
    if (a.y == b.y) {
        if (a.f == b.f) {
            return a.r - a.l > b.r - b.l;
        } return a.f < b.f;
    } return a.y < b.y;
}

set<int> dp[2 * maxN];
vector<int> g[2 * maxN];
int n, m, A[maxN], B[maxN], C[maxN], D[maxN], X[maxN], Y[maxN], K[maxN], lazy[4 * maxN], par[maxN], ans[maxN];
void prop(int v, int tl, int tr) {
    if (tl != tr) {
        lazy[2 * v] = lazy[v];
        lazy[2 * v + 1] = lazy[v];
        lazy[v] = 0;
    }
}
void update(int v, int tl, int tr, int l, int r, int val) {
    if (lazy[v]) prop(v, tl, tr);
    if (r < tl || tr < l) return;
    if (l <= tl && tr <= r) {
        lazy[v] = val; prop(v, tl, tr); return;
    } int tm = (tl + tr) / 2;
    update(2 * v, tl, tm, l, r, val);
    update(2 * v + 1, tm + 1, tr, l, r, val);
}
int getpos(int v, int tl, int tr, int pos) {
    if (lazy[v]) prop(v, tl, tr);
    if (tl == tr) return lazy[v];
    int tm = (tl + tr) / 2;
    if (pos <= tm) return getpos(2 * v, tl, tm, pos);
    else return getpos(2 * v + 1, tm + 1, tr, pos);
}
void dfs(int v) {
    for (int u : g[v]) {
        dfs(u);
        if (dp[u].size() > dp[v].size())
            swap(dp[u], dp[v]);
        for (int i : dp[u]) dp[v].insert(i);
        dp[u].clear();
    } ans[v] = dp[v].size();
}
void solve() {
    cin >> n >> m;
    vector<int> temp;
    for (int i = 1; i <= n; i++) {
        cin >> A[i] >> B[i] >> C[i] >> D[i];
        temp.pb(A[i]); temp.pb(B[i]); temp.pb(C[i]); temp.pb(D[i]);
    } for (int i = 1; i <= m; i++) {
        cin >> X[i] >> Y[i] >> K[i];
        temp.pb(X[i]); temp.pb(Y[i]);
    } sort(all(temp)); temp.resize(unique(all(temp)) - temp.begin());
    for (int i = 1; i <= n; i++) {
        A[i] = lower_bound(all(temp), A[i]) - temp.begin() + 1;
        B[i] = lower_bound(all(temp), B[i]) - temp.begin() + 1;
        C[i] = lower_bound(all(temp), C[i]) - temp.begin() + 1;
        D[i] = lower_bound(all(temp), D[i]) - temp.begin() + 1;
    } for (int i = 1; i <= m; i++) {
        X[i] = lower_bound(all(temp), X[i]) - temp.begin() + 1;
        Y[i] = lower_bound(all(temp), Y[i]) - temp.begin() + 1;
    } for (int i = 1; i <= m; i++)
        dp[n + i].insert(K[i]);
    int N = temp.size();
    vector<node> events;
    for (int i = 1; i <= n; i++) {
        events.pb(*new node(A[i], B[i], D[i], i, 0));
        events.pb(*new node(C[i], B[i], D[i], i, 1));
    } for (int i = 1; i <= m; i++) {
        events.pb(*new node(X[i], Y[i], Y[i], n + i, 0));
        events.pb(*new node(X[i], Y[i], Y[i], n + i, 1));
    } update(1, 1, N, 1, N, n + m + 1); sort(all(events), comp);
    for (node i : events) {
        if (i.f == 0) {
            int val = getpos(1, 1, N, i.l);
            par[i.id] = val;
            update(1, 1, N, i.l, i.r, i.id);
        } else {
            int val = getpos(1, 1, N, i.l);
            update(1, 1, N, i.l, i.r, par[val]);
        }
    } for (int i = 1; i <= n + m; i++)
        g[par[i]].pb(i);
    dfs(n + m + 1);
    for (int i = 1; i <= n; i++)
        cout << ans[i] << '\n';
}
int32_t main() { 
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr); cout.tie(nullptr);
    
    int t = 1;
    // cin >> t;
    while (t--) {
        solve();
        cout << '\n';
    }
    return 0;
}

Compilation message (stderr)

plahte.cpp: In function 'void open_file(std::string)':
plahte.cpp:30:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   30 |     freopen((filename + ".in").c_str(), "r", stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
plahte.cpp:31:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   31 |     freopen((filename + ".out").c_str(), "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...