답안 #972693

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
972693 2024-04-30T23:25:24 Z NemanjaSo2005 늑대인간 (IOI18_werewolf) C++17
100 / 100
515 ms 79996 KB
#include "werewolf.h"
#include<bits/stdc++.h>
#define ll long long
#define f first
#define s second
using namespace std;
const int maxn=2e5+5;
int N,M,Q,rod[maxn],vel[maxn],in[maxn],out[maxn],vrem,rod2[maxn],vred[maxn];
vector<int> koji[maxn],graf[maxn];
vector<pair<int,int>> stablo[maxn];
set<int> SS[maxn];
struct grana{
   int a,b,w,id;
} grane[2*maxn];
bool cmp(grana a,grana b){
   return a.w<b.w;
}
int getp(int x){
   if(rod[x]==x)
      return x;
   return getp(rod[x]);
}
void spoj(int a,int b,int w){
   //cout<<a<<" "<<b<<endl;
   a=getp(a);
   b=getp(b);
   if(a==b)
      return;
   if(vel[b]>vel[a])
      swap(a,b);
   rod[b]=a;
   vred[b]=w;
   stablo[b].push_back({a,w});
   stablo[a].push_back({b,w});
   vel[a]=max(vel[a],vel[b]+1);
   //cout<<b<<" "<<a<<" "<<w<<endl;
   return;
}
void dfs(int gde,int pret){
   in[gde]=++vrem;
   for(auto x:stablo[gde])
      if(x.f!=pret)
         dfs(x.f,gde);
   out[gde]=vrem;
}
int getp2(int x){
   if(rod2[x]==x)
      return x;
   rod2[x]=getp2(rod2[x]);
   return rod2[x];
}
void spoj2(int a,int b){
   a=getp2(a);
   b=getp2(b);
   if(a==b)
      return;

   if(SS[a].size()<SS[b].size())
      swap(a,b);
   //cout<<"SPOJ 2  "<<a<<" "<<b<<endl;
   for(auto it=SS[b].begin();it!=SS[b].end();it++)
      SS[a].insert(*it);
   SS[b].clear();
   rod2[b]=a;
   return;
}
vector<int> check_validity(int NN, vector<int> X, vector<int> Y,vector<int> S, vector<int> E,vector<int> L, vector<int> R) {
   vector<int> ans(R.size(),0);
   N=NN;
   M=X.size();
   for(int i=0;i<S.size();i++){
      S[i]++;
      E[i]++;
      L[i]++;
      R[i]++;
   }
   for(int i=0;i<X.size();i++){
      X[i]++;
      Y[i]++;
   }
   for(int i=1;i<=N;i++){
      rod[i]=i;
      rod2[i]=i;
   }
   for(int i=0;i<M;i++){
      grane[i].a=X[i];
      grane[i].b=Y[i];
      grane[i].w=max(grane[i].a,grane[i].b);
      grane[i].id=i;
      graf[grane[i].a].push_back(grane[i].b);
      graf[grane[i].b].push_back(grane[i].a);
   }
   sort(grane,grane+M,cmp);
   for(int i=0;i<M;i++)
      spoj(grane[i].a,grane[i].b,grane[i].w);
/*
   for(int i=1;i<=N;i++){
      cout<<i<<": ";
      for(auto p:stablo[i])
         cout<<p.f<<" "<<p.s<<"   ";
      cout<<endl;
   }*/

   dfs(getp(1),getp(1));
   //for(int i=1;i<=N;i++)
    //  cout<<i<<": "<<in[i]<<" "<<out[i]<<endl;
   vred[getp(1)]=1e9;
 //  for(int i=1;i<=N;i++)
  //    cout<<i<<": "<<rod[i]<<endl;
   for(int i=1;i<=N;i++)
      SS[i].insert(in[i]);
   for(int i=0;i<L.size();i++){
      koji[L[i]].push_back(i);
   }
   for(int i=N;i>=1;i--){
      for(int x:graf[i])
         if(x>=i)
            spoj2(x,i);

      for(int q:koji[i]){
         int kraj=E[q];
         int poc=S[q];
         int r=R[q];
        // cout<<"R JE "<<r<<endl;
         while(vred[kraj]<=r){
         //   cout<<kraj<<" "<<vred[kraj]<<endl;
            kraj=rod[kraj];
         }
        // cout<<kraj<<" "<<vred[kraj]<<endl;
         int il=in[kraj];
         int ir=in[kraj];

        // cout<<kraj<<endl;

         if(stablo[kraj].size()){
            int dg=0,gg=stablo[kraj].size()-1,sred,ret=-1;
            while(dg<=gg){
               sred=(dg+gg)/2;
               if(stablo[kraj][sred].s<=r){
                  dg=sred+1;
                  ret=sred;
               }
               else
                  gg=sred-1;
            }
            if(ret!=-1)
               ir=out[stablo[kraj][ret].f];
         }

  //       cout<<il<<" "<<ir<<endl;

        /* cout<<"DODAO DO "<<i<<endl;
         cout<<poc<<" "<<getp2(poc)<<endl;
         for(auto it=SS[getp2(poc)].begin();it!=SS[getp2(poc)].end();it++)
            cout<<(*it)-1<<" ";
         cout<<endl;
*/
         auto it=SS[getp2(poc)].upper_bound(il-1);
         if(it!=SS[getp2(poc)].end())
            if((*it)<=ir)
               ans[q]=1;
      }
   }
   return ans;
}

Compilation message

werewolf.cpp: In function 'std::vector<int> check_validity(int, std::vector<int>, std::vector<int>, std::vector<int>, std::vector<int>, std::vector<int>, std::vector<int>)':
werewolf.cpp:71:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   71 |    for(int i=0;i<S.size();i++){
      |                ~^~~~~~~~~
werewolf.cpp:77:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   77 |    for(int i=0;i<X.size();i++){
      |                ~^~~~~~~~~
werewolf.cpp:112:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  112 |    for(int i=0;i<L.size();i++){
      |                ~^~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 26972 KB Output is correct
2 Correct 6 ms 27168 KB Output is correct
3 Correct 6 ms 26972 KB Output is correct
4 Correct 7 ms 26972 KB Output is correct
5 Correct 6 ms 26972 KB Output is correct
6 Correct 7 ms 26972 KB Output is correct
7 Correct 7 ms 26972 KB Output is correct
8 Correct 6 ms 26972 KB Output is correct
9 Correct 6 ms 26972 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 26972 KB Output is correct
2 Correct 6 ms 27168 KB Output is correct
3 Correct 6 ms 26972 KB Output is correct
4 Correct 7 ms 26972 KB Output is correct
5 Correct 6 ms 26972 KB Output is correct
6 Correct 7 ms 26972 KB Output is correct
7 Correct 7 ms 26972 KB Output is correct
8 Correct 6 ms 26972 KB Output is correct
9 Correct 6 ms 26972 KB Output is correct
10 Correct 10 ms 27736 KB Output is correct
11 Correct 11 ms 27740 KB Output is correct
12 Correct 12 ms 27740 KB Output is correct
13 Correct 9 ms 27740 KB Output is correct
14 Correct 10 ms 27912 KB Output is correct
15 Correct 10 ms 27996 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 504 ms 74476 KB Output is correct
2 Correct 315 ms 75720 KB Output is correct
3 Correct 340 ms 76132 KB Output is correct
4 Correct 433 ms 76884 KB Output is correct
5 Correct 427 ms 76988 KB Output is correct
6 Correct 509 ms 78936 KB Output is correct
7 Correct 504 ms 78420 KB Output is correct
8 Correct 312 ms 75676 KB Output is correct
9 Correct 320 ms 74444 KB Output is correct
10 Correct 388 ms 77512 KB Output is correct
11 Correct 432 ms 77612 KB Output is correct
12 Correct 425 ms 78028 KB Output is correct
13 Correct 327 ms 79924 KB Output is correct
14 Correct 334 ms 79932 KB Output is correct
15 Correct 317 ms 79984 KB Output is correct
16 Correct 378 ms 79996 KB Output is correct
17 Correct 482 ms 78540 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 26972 KB Output is correct
2 Correct 6 ms 27168 KB Output is correct
3 Correct 6 ms 26972 KB Output is correct
4 Correct 7 ms 26972 KB Output is correct
5 Correct 6 ms 26972 KB Output is correct
6 Correct 7 ms 26972 KB Output is correct
7 Correct 7 ms 26972 KB Output is correct
8 Correct 6 ms 26972 KB Output is correct
9 Correct 6 ms 26972 KB Output is correct
10 Correct 10 ms 27736 KB Output is correct
11 Correct 11 ms 27740 KB Output is correct
12 Correct 12 ms 27740 KB Output is correct
13 Correct 9 ms 27740 KB Output is correct
14 Correct 10 ms 27912 KB Output is correct
15 Correct 10 ms 27996 KB Output is correct
16 Correct 504 ms 74476 KB Output is correct
17 Correct 315 ms 75720 KB Output is correct
18 Correct 340 ms 76132 KB Output is correct
19 Correct 433 ms 76884 KB Output is correct
20 Correct 427 ms 76988 KB Output is correct
21 Correct 509 ms 78936 KB Output is correct
22 Correct 504 ms 78420 KB Output is correct
23 Correct 312 ms 75676 KB Output is correct
24 Correct 320 ms 74444 KB Output is correct
25 Correct 388 ms 77512 KB Output is correct
26 Correct 432 ms 77612 KB Output is correct
27 Correct 425 ms 78028 KB Output is correct
28 Correct 327 ms 79924 KB Output is correct
29 Correct 334 ms 79932 KB Output is correct
30 Correct 317 ms 79984 KB Output is correct
31 Correct 378 ms 79996 KB Output is correct
32 Correct 482 ms 78540 KB Output is correct
33 Correct 515 ms 77456 KB Output is correct
34 Correct 195 ms 57956 KB Output is correct
35 Correct 505 ms 76888 KB Output is correct
36 Correct 482 ms 76624 KB Output is correct
37 Correct 459 ms 76744 KB Output is correct
38 Correct 475 ms 72144 KB Output is correct
39 Correct 509 ms 71612 KB Output is correct
40 Correct 515 ms 78040 KB Output is correct
41 Correct 407 ms 71908 KB Output is correct
42 Correct 363 ms 70200 KB Output is correct
43 Correct 442 ms 73176 KB Output is correct
44 Correct 478 ms 72304 KB Output is correct
45 Correct 398 ms 69408 KB Output is correct
46 Correct 449 ms 69800 KB Output is correct
47 Correct 332 ms 75564 KB Output is correct
48 Correct 319 ms 75568 KB Output is correct
49 Correct 337 ms 75576 KB Output is correct
50 Correct 325 ms 75568 KB Output is correct
51 Correct 424 ms 78400 KB Output is correct
52 Correct 442 ms 78444 KB Output is correct