Submission #862653

# Submission time Handle Problem Language Result Execution time Memory
862653 2023-10-18T17:56:56 Z hqminhuwu Plahte (COCI17_plahte) C++17
0 / 160
11 ms 41564 KB
#include <bits/stdc++.h>
#define forr(_a,_b,_c) for(_a = (_b); _a <= (_c); ++_a)
#define ford(_a,_b,_c) for(_a = (_b) + 1; _a --> (_c);)
#define forf(_a,_b,_c) for(_a = (_b); _a < (_c); ++_a)
#define st first
#define nd second
#define ll long long
#define ull unsigned long long
#define pii pair <int,int>
#define pll pair <ll,ll>
#define piii pair <pii,int>
#define vi vector <int>
#define pb push_back
#define mp make_pair
#define all(x) begin(x),end(x)
#define file "test"
#define ld long double

using namespace std;
const int N = 5e5 + 5;
const ll oo = 1e9;
const ll mod = 1e9 + 7;
const ld eps = 1e-6;

pii tree[4 * N];
void update (int i, int l, int r, int u, pii val){
    if (l > u || r < u)
        return;
    //cout << l << " " << r << " " << u << "\n";
    if (l == r){
        tree[i] = val;
        return;
    }
    int mid = (l + r) >> 1;
    update (i * 2, l, mid, u, val);
    update (i * 2 + 1, mid + 1, r ,u, val);
    tree[i] = min (tree[i * 2], tree[i * 2 + 1]);
}

pii get (int i, int l, int r, int u, int v){

    if (l > v || r < u)
        return {oo,oo};
    if (l >= u && r <= v)
        return tree[i];
    int mid = (l + r) >> 1;
    return min (get (i * 2, l, mid, u, v),
    get (i * 2 + 1, mid + 1, r ,u, v));
}

vector <piii> ev;
vector <int> vx,vy;
pii a[N],b[N];
set <int> col[N];
int i,n,ans[N],m,nl[N];
vector <int> g[N];
piii c[N];

void dfs (int u){
    for (int v : g[u]){
        dfs(v);
     //   cout << u << " " << v << "\n";
        if (col[v].size() > col[u].size())
            swap(col[u],col[v]);
        for (int x : col[v])
                col[u].insert(x);
    }
}
int main(){
    ios_base::sync_with_stdio(0); cin.tie(0);
    //#ifndef ONLINE_JUDGE
       freopen(file".inp", "r", stdin); freopen(file".out", "w", stdout);
    //#endif
    cin >> n >> m;
    forr (i,1,(n * 2 + m) * 4)
        tree[i] = {oo,oo};
    forr (i,1,n){
        cin >> a[i].st >> a[i].nd >> b[i].st >> b[i].nd;
        vx.pb(a[i].st);
        vx.pb(b[i].st);
        vy.pb(a[i].nd);
        vy.pb(b[i].nd);
    }
    forr (i,1,m){
        cin >> c[i].st.st >> c[i].st.nd >> c[i].nd;
        vx.pb(c[i].st.st);
        vy.pb(c[i].st.nd);
    }
    sort(all(vx));
    vx.erase(unique(all(vx)),vx.end());
    sort(all(vy));
    vy.erase(unique(all(vy)),vy.end());
    forr (i,1,n){
        a[i].st = lower_bound (all(vx),a[i].st) - vx.begin() + 1;
        a[i].nd = lower_bound (all(vy),a[i].nd) - vy.begin() + 1;
        b[i].st = lower_bound (all(vx),b[i].st) - vx.begin() + 1;
        b[i].nd = lower_bound (all(vy),b[i].nd) - vy.begin() + 1;
        swap(a[i].nd,b[i].nd);
        ev.pb({{a[i].st,-a[i].nd},i});
        ev.pb({{b[i].st,oo + a[i].nd},i + n});
     //   cout << a[i].st << " " << a[i].nd << " "<< b[i].st << " " << b[i].nd << "\n";
    }
    forr (i,1,m){
        c[i].st.st = lower_bound (all(vx),c[i].st.st) - vx.begin() + 1;
        c[i].st.nd = lower_bound (all(vy),c[i].st.nd) - vy.begin() + 1;
        ev.pb({c[i].st,-i});
    }
    int lmt = n * 2 + m;
    sort(all(ev));
    forf (i,0,ev.size()){
        piii u = ev[i];
        // cout << u.st.st << " " << u.st.nd << " " << u.nd << "\n";
        if (u.nd < 0){
            int l = u.st.nd, r = lmt;
         //   cout << l << " " << r << ": \n";
            while (l < r){
                int mid = (l + r) >> 1;
            //    cout << mid << " " << get (1,1,lmt,u.st.nd,mid).st << "\n";
                if (get(1,1,lmt,u.st.nd,mid).st <= u.st.nd)
                    r = mid;
                else l = mid + 1;
            }
            pii v = get (1,1,lmt,u.st.nd,l);
           // cout << l << " " << v.st << " ";
          //  pii v = get (1,1,lmt,u.st.nd,lmt);
            if (v.st == oo)
                continue;
            if (v.st <= u.st.nd)
            col[v.nd].insert(c[-u.nd].nd);
          // cout << "paint: " << v.nd << " " << -u.nd << "\n";
        }
        else if (u.nd <= n){
           // cout << -u.st.nd << "\n";
            update(1,1,lmt,-u.st.nd,{b[u.nd].nd,u.nd});
        }
        else {
            int f =  u.st.nd - oo;
            int l = f + 1, r = lmt;
           // cout << l << " " << r << "\n";
            while (l < r){
                int mid = (l + r) / 2;
            //    cout << mid << " " << get(1,1,lmt,mid,lmt).st << "\n";
                if (get(1,1,lmt,f + 1,mid).st <= b[u.nd - n].nd)
                    r = mid;
                else l = mid + 1;
            }
            pii v = get (1,1,lmt,f + 1,l);
           // cout << v.st << " " << v.nd << " " << b[u.nd - n].nd << "\n";
            if (v.st < b[u.nd - n].nd)
                g[v.nd].pb(u.nd - n),nl[u.nd - n] = 1;
            update(1,1,lmt,f,{oo,oo});
           // cout << get (1,1,lmt,f,lmt).st << "\n";
        }
    }
    forr (i,1,n)
    if (!nl[i])
        dfs(i);
   forr (i,1,n)
       cout << ans[i] << "\n";
    return 0;
}
/*



*/

Compilation message

plahte.cpp: In function 'int main()':
plahte.cpp:4:42: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<std::pair<int, int>, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    4 | #define forf(_a,_b,_c) for(_a = (_b); _a < (_c); ++_a)
      |                                          ^
plahte.cpp:110:5: note: in expansion of macro 'forf'
  110 |     forf (i,0,ev.size()){
      |     ^~~~
plahte.cpp:72:15: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   72 |        freopen(file".inp", "r", stdin); freopen(file".out", "w", stdout);
      |        ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
plahte.cpp:72:48: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   72 |        freopen(file".inp", "r", stdin); freopen(file".out", "w", stdout);
      |                                         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 9 ms 41560 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 9 ms 41564 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 11 ms 41564 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 9 ms 41560 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 8 ms 41564 KB Output isn't correct
2 Halted 0 ms 0 KB -