제출 #1328983

#제출 시각아이디문제언어결과실행 시간메모리
1328983panhcutizzPlahte (COCI17_plahte)C++17
160 / 160
259 ms62616 KiB
#include <iostream>
#include <vector>
#include <random>
#include <algorithm>
#include <chrono>
#include <queue>
#include <stack>
#include <set>
#define all(x) x.begin(), x.end()
#define pb push_back
#define fi first
#define se second
#define compact(v) v.erase(unique(all(v)) , v.end())
#define pi pair<int , int>
#define vi vector<int>
#define eb emplace_back
#define FOR(i , l , r) for(int i = l; i <= r; ++ i)
#define FORD(i , l , r) for(int i = l; i >= r; -- i)
template <class T> bool maximize(T &a , T b){return (a < b ? a = b , true : false);}
template <class T> bool minimize(T &a , T b){return (a > b ? a = b , true : false);}

using namespace std;
typedef long long ll;

const int nd = 8e4 + 5 , mod = 1e9 + 7;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
uniform_int_distribution<int> dist(1 , (int)2e9);
int add(int a , int b){
    a += b;
    return (a >= mod ? a - mod : a);
}
int sub(int a , int b){
    a -= b;
    return (a < 0 ? a + mod : a);
}
int mul(ll a , ll b){return (a * b) % mod;}

int xpow(int a , int b){
    if(b == 1) return a;
    int x = xpow(a , b / 2);
    if(b & 1) return mul(a , mul(x , x));
    else return mul(x , x);
}

vi st[4 * 250005];
int cur_id = 0;
bool flag = true;

vi adj[nd];
int in[nd];

void up(int id , int l , int r , int a , int b , int x){
    if(l > b || r < a) return;
    if(st[id].size()) cur_id = st[id].back();
    if(a <= l && r <= b){
        if(x) st[id].eb(x);
        else st[id].pop_back();
        //cout << l << " " << r << " " << x << '\n';
        if((x > 0) && (cur_id > 0) && flag){
            adj[cur_id].eb(x);
            //cout << cur_id << " " << x << '\n';
            ++ in[x];
            //cout << l << " " << r << " " << x << " " << cur_id << '\n';
        }
        flag = false;
        return;
    }

    int mid = (r + l) >> 1;
    //cout << l << " " << r << " " << x << " " << cur_id << '\n';
    up(id * 2 , l , mid , a , b , x);
    up(id * 2 + 1 , mid + 1 , r , a , b , x);
}

void get(int id , int l , int r , int x){
    if(l > x || r < x) return;
    if(st[id].size()) cur_id = st[id].back();
    if(l == r) return;
    int mid = (r + l) >> 1;
    get(id * 2 , l , mid , x);
    get(id * 2 + 1 , mid + 1 , r , x);
}

struct event{
    int t , l , r , x , id;

    bool operator<(const event &o)const{
        if(x == o.x){
            if(t == o.t){
                return id < o.id;
            }
            return t < o.t;
        }
        return x < o.x;
    }
};

vector <event> e;
set <int> val[nd];

vi col[nd];
int ans[nd];

void dfs(int r , int pre = 0){
    for(int c : col[r]) val[r].insert(c);

    for(int v : adj[r]) if(v != pre){
        dfs(v , r);
        if(val[v].size() > val[r].size()) swap(val[r] , val[v]);
        for(int c : val[v]) val[r].insert(c);
    }

    ans[r] = val[r].size();
}

vi s;

tuple <int , int , int> query[nd];
tuple <int , int , int , int> square[nd];

void read(int n , int m){
    FOR(i , 1 , n){
        int x , y , a , b;
        cin >> x >> y >> a >> b;
        s.eb(y) , s.eb(b);
        square[i] = {x , y , a , b};
    }

    FOR(i , 1 , m){
        int x , y , k;
        cin >> x >> y >> k;
        query[i] = {x , y , k};
        s.eb(y);
    }
}

void solve(){
    int n , m;
    cin >> n >> m;
    read(n , m);

    sort(all(s));
    compact(s);

    FOR(i , 1 , n){
        auto [x , y , a , b] = square[i];

        y = lower_bound(all(s) , y) - s.begin() + 1;
        b = lower_bound(all(s) , b) - s.begin() + 1;

        //cout << i << " " << x << " " << y << " " << b << '\n';

        e.pb({0 , y , b , x , i});
        e.pb({0 , y , b , a + 1 , 0});
    }

    FOR(i , 1 , m){
        auto [x , y , k] = query[i];
        
        y = lower_bound(all(s) , y) - s.begin() + 1;
        e.pb({1 , y , y , x , k});
    }

    sort(all(e));
    for(auto [t , l , r , x , id] : e){
        cur_id = 0;
        flag = true;
        //cout << t << " " << l << " " << r << " " << x << " " << id << '\n';
        if(t == 0){
            //cout << l << " " << r << " " << id << '\n';
            up(1 , 1 , 250000 , l , r , id);
        }
        if(t == 1){
            get(1 , 1 , 250000 , l);
            //cout << l << " " << cur_id << '\n';
            col[cur_id].eb(id);
        }
    }
    
    FOR(i , 1 , n) sort(all(adj[i])) , compact(adj[i]);

    FOR(i , 1 , n) if(!in[i]){
        dfs(i);
    }

    FOR(i , 1 , n) cout << ans[i] << '\n';
}

signed main() {
   ios_base::sync_with_stdio(false);
   cin.tie(0);

    #define task "task" 
    if(fopen(task".inp", "r")) {
        freopen(task".inp", "r", stdin);
        freopen(task".out", "w", stdout);
    }
    solve();

    return 0;
}

컴파일 시 표준 에러 (stderr) 메시지

plahte.cpp: In function 'int main()':
plahte.cpp:195:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  195 |         freopen(task".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
plahte.cpp:196:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  196 |         freopen(task".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...