Submission #421536

# Submission time Handle Problem Language Result Execution time Memory
421536 2021-06-09T08:48:08 Z 장태환(#7576) Collapse (JOI18_collapse) C++17
0 / 100
15000 ms 5740 KB
#include "collapse.h"
#include <string.h>
using namespace std;
int st[100100];
int e[100100];
int d[200100];
unsigned int vis[200200>>6];
vector<pair<int,int>>q[100100];
int sta[100100];
int siz;
vector<int> simulateCollapse(int N,vector<int> T,vector<int> X,vector<int> Y,vector<int> W,vector<int> P)
{
    memset(vis,-1,sizeof(vis));
	vector<int>ann=vector<int>(W.size(), 0);
	int i;
	int M=T.size();
	for(i=0;i<M;i++)
	{
        if(T[i])
        {
            e[X[i]]--;
            e[Y[i]]--;
        }
        else
        {
            e[X[i]]++;
            e[Y[i]]++;
            st[X[i]+1]=max(st[X[i]+1],e[X[i]]);
            st[Y[i]+1]=max(st[Y[i]+1],e[Y[i]]);
        }
	}
	for(i=0;i<N;i++)
	{
        if(i)
            st[i]+=st[i-1];
        e[i]=st[i];
	}
	int C=P.size();
	for(i=0;i<C;i++)
	{
        q[W[i]].push_back({P[i],i});
	}
	for(i=0;i<M;i++)
	{
        int ty=T[i];
        int s=X[i];
        int en=Y[i];
        register int j;
        if(ty)
        {
            int fi=st[s];
            int se=e[s];
            for(j=fi;j<se;j++)
            {
                if(d[j]==en)
                {
                    d[j]=d[se];
                    break;
                }
            }
            e[s]--;
            fi=st[en];
            se=e[en];
            for(j=fi;j<se;j++)
            {
                if(d[j]==s)
                {
                    d[j]=d[se];
                    break;
                }
            }
            e[en]--;
        }
        else
        {
            d[e[s]++]=en;
            d[e[en]++]=s;
        }
        for(j=0;j<q[i].size();j++)
        {
            int div=q[i][j].first+1;
            int cur=0;
            int an=0;
            for(j=0;j<div;j++)
            {
                vis[j>>5]^=1U<<(j&31);
            }
            while(cur<div)
            {
                an++;
                sta[siz++]=cur;
                while(siz)
                {
                    int cou=sta[--siz];
                    register int k;
                    for(k=st[cou];k<e[cou];k++)
                    {
                        if(!(vis[d[k]>>5]&(1U<<(d[k]&31))))
                        {
                            vis[d[k]>>5]|=1U<<(d[k]&31);
                            sta[siz++]=d[k];
                        }
                    }
                }
                cur++;
                while((vis[cur>>5]&(1U<<(cur&31))))
                {
                    cur++;
                }
            }
            for(j=div;j<N;j++)
            {
                vis[j>>5]^=1U<<(j&31);
            }
            cur=N-1;
            while(cur>=div)
            {
                an++;
                sta[siz++]=cur;
                while(siz)
                {
                    int cou=sta[--siz];
                    register int k;
                    for(k=st[cou];k<e[cou];k++)
                    {
                        if(!(vis[d[k]>>5]&(1U<<(d[k]&31))))
                        {
                            vis[d[k]>>5]|=1U<<(d[k]&31);
                            sta[siz++]=d[k];
                        }
                    }
                }
                cur--;
                while(cur&&(vis[cur>>5]&(1U<<(cur&31))))
                {
                    cur--;
                }
            }

            ann[q[i][j].second]=an;
        }
	}
	return ann;
}

Compilation message

collapse.cpp: In function 'std::vector<int> simulateCollapse(int, std::vector<int>, std::vector<int>, std::vector<int>, std::vector<int>, std::vector<int>)':
collapse.cpp:48:22: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   48 |         register int j;
      |                      ^
collapse.cpp:79: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]
   79 |         for(j=0;j<q[i].size();j++)
      |                 ~^~~~~~~~~~~~
collapse.cpp:95:34: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   95 |                     register int k;
      |                                  ^
collapse.cpp:123:34: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
  123 |                     register int k;
      |                                  ^
# Verdict Execution time Memory Grader output
1 Incorrect 274 ms 3020 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 15058 ms 5732 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 15060 ms 5740 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 274 ms 3020 KB Output isn't correct
2 Halted 0 ms 0 KB -