답안 #603434

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
603434 2022-07-24T06:50:17 Z 조영욱(#8429) Collapse (JOI18_collapse) C++17
0 / 100
15000 ms 11732 KB
#include "collapse.h"
#include <bits/stdc++.h>
using namespace std;

int sp;
typedef pair<int,int> P;
typedef pair<P,int> Pi;
set<Pi> s;
int n,c,q;
const int sz=131072;
vector<int> query[sz];
vector<int> ret;
int p[100000];
vector<P> seg[sz*2];
stack<P> st;

int find(int a) {
    return p[a]<0?a:find(a);
}

bool merge(int a,int b) {
    a=find(a);
    b=find(b);
    if (a==b) {
        return false;
    }
    if (-p[a]<=-p[b]) {
        swap(a,b);
    }
    if (p[a]==p[b]) {
        st.push(P(a,p[a]));
        p[a]=p[a]-1;
    }
    st.push(P(b,p[b]));
    p[b]=a;
    return true;
}

void ins(int l,int r,P e,int node=1,int nodel=0,int noder=sz-1) {
    if (r<nodel||l>noder) {
        return;
    }
    if (l<=nodel&&noder<=r) {
        seg[node].push_back(e);
        return;
    }
    int mid=(nodel+noder)/2;
    int got=st.size();
    ins(l,r,e,node*2,nodel,mid);
    ins(l,r,e,node*2+1,mid+1,noder);
    while (got<st.size()) {
        p[st.top().first]=st.top().second;
        st.pop();
    }
}

void dfs(int node,int val) {
    int now=val;
    for(int i=0;i<seg[node].size();i++) {
        if (merge(seg[node][i].first,seg[node][i].second)) {
            now--;
        }
    }
    if (node>=sz) {
        for(int i=0;i<query[node-sz].size();i++) {
            ret[query[node-sz][i]]=now;
        }
        return;
    }
    dfs(node*2,now);
    dfs(node*2+1,now);
}

std::vector<int> simulateCollapse(
	int N,
	std::vector<int> T,
	std::vector<int> X,
	std::vector<int> Y,
	std::vector<int> W,
	std::vector<int> pp
) {
    ret.resize(n);
    sp=pp[0];
    n=N;
    c=T.size();
    q=pp.size();
    for(int i=0;i<c;i++) {
        if (X[i]>Y[i]) {
            swap(X[i],Y[i]);
        }
        if (X[i]<=sp&&Y[i]>sp) {

        }
        else {
            continue;
        }
        if (T[i]==0) {
            s.insert(Pi(P(X[i],Y[i]),i));
        }
        else {
            auto iter=s.lower_bound(Pi(P(X[i],Y[i]),-1));
            int got=(*iter).second;
            s.erase(iter);
            ins(got,i,P(X[i],Y[i]));
        }
    }
    for(auto now:s) {
        ins(now.second,c-1,now.first);
    }
    for(int i=0;i<q;i++) {
        query[W[i]].push_back(i);
    }
    dfs(1,n);
	return ret;
}

Compilation message

collapse.cpp: In function 'void ins(int, int, P, int, int, int)':
collapse.cpp:51:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::stack<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   51 |     while (got<st.size()) {
      |            ~~~^~~~~~~~~~
collapse.cpp: In function 'void dfs(int, int)':
collapse.cpp:59:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   59 |     for(int i=0;i<seg[node].size();i++) {
      |                 ~^~~~~~~~~~~~~~~~~
collapse.cpp:65:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   65 |         for(int i=0;i<query[node-sz].size();i++) {
      |                     ~^~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 15008 ms 9940 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 15085 ms 11728 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 15045 ms 11732 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 15008 ms 9940 KB Time limit exceeded
2 Halted 0 ms 0 KB -