답안 #1038671

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1038671 2024-07-30T05:52:19 Z vjudge1 늑대인간 (IOI18_werewolf) C++17
100 / 100
522 ms 126032 KB
#include "werewolf.h"
#include<bits/stdc++.h>
using namespace std;
#define M 200100
typedef vector<int> VI;
struct dsu{
  int par[M];
  int abp(int n){
    return par[n]?par[n]=abp(par[n]):n;
  }
  int merge(int a,int b){
    a++;b++;
    a=abp(a),b=abp(b);
    if(a-b)par[a]=b;
    return a!=b;
  }
} dsuhuman,dsuwolf;
int bjh[M][20],bjw[M][20],in[M],out[M],CC;
vector<pair<int,int>>qry[M];
set<int>st[M];
VI EDGES[M],adjh[M],adjw[M];
vector<int>ans;
void dfsw(int n){
  in[n]=++CC;
  for(auto i:adjw[n])
    dfsw(i);
  out[n]=CC;
}
void merge(int a,int b){
  if(st[a].size()<st[b].size())
    swap(st[a],st[b]);
  for(auto i:st[b])
    st[a].insert(i);
  st[b].clear();
}
void dfsans(int n){
  st[n].insert(in[n]);
  for(auto i:adjh[n])
    dfsans(i),merge(n,i);
  for(auto[i,x]:qry[n])
    ans[i]=st[n].lower_bound(in[x])!=
          st[n].upper_bound(out[x]);
}
VI check_validity(int N,VI X,VI Y,VI S,VI E,VI L,VI R) {
  for(int i=0;i<X.size();i++)
    EDGES[X[i]].push_back(Y[i]),
    EDGES[Y[i]].push_back(X[i]);
  for(int i=N;i--;)
    for(auto k:EDGES[i]) {
      if(k<i)continue;
      int x=dsuhuman.abp(k+1)-1;
      if(x==i) continue;
      bjh[x][0]=i,adjh[i].push_back(x);
      dsuhuman.merge(x,i);
    }
  for(int i=0;i<N;i++)
    for(auto k:EDGES[i]) {
      if(k>i)continue;
      int x=dsuwolf.abp(k+1)-1;
      if(x==i) continue;
      bjw[x][0]=i,adjw[i].push_back(x);
      dsuwolf.merge(x,i);
    }
  bjw[N-1][0]=bjw[N][0]=N;
  for(int j=1;j<20;j++)
    for(int i=0;i<=N;i++)
      bjw[i][j]=bjw[bjw[i][j-1]][j-1],
      bjh[i][j]=bjh[bjh[i][j-1]][j-1];
  dfsw(N-1);
  int Q=S.size();
  ans=S;
  for(int i=0;i<Q;i++){
    int l=L[i],r=R[i],s=S[i],e=E[i];
    for(int i=20;i--;)
      if(bjh[s][i]>=l)
        s=bjh[s][i];
    for(int i=20;i--;)
      if(bjw[e][i]<=r)
        e=bjw[e][i];
    qry[s].push_back({i,e});
  }
  dfsans(0);
  return ans;
}

Compilation message

werewolf.cpp: In function 'VI check_validity(int, VI, VI, VI, VI, VI, VI)':
werewolf.cpp:45:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   45 |   for(int i=0;i<X.size();i++)
      |               ~^~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 13 ms 28508 KB Output is correct
2 Correct 13 ms 28584 KB Output is correct
3 Correct 12 ms 28508 KB Output is correct
4 Correct 13 ms 28508 KB Output is correct
5 Correct 12 ms 28508 KB Output is correct
6 Correct 12 ms 28660 KB Output is correct
7 Correct 12 ms 28500 KB Output is correct
8 Correct 12 ms 28508 KB Output is correct
9 Correct 12 ms 28504 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 13 ms 28508 KB Output is correct
2 Correct 13 ms 28584 KB Output is correct
3 Correct 12 ms 28508 KB Output is correct
4 Correct 13 ms 28508 KB Output is correct
5 Correct 12 ms 28508 KB Output is correct
6 Correct 12 ms 28660 KB Output is correct
7 Correct 12 ms 28500 KB Output is correct
8 Correct 12 ms 28508 KB Output is correct
9 Correct 12 ms 28504 KB Output is correct
10 Correct 16 ms 29784 KB Output is correct
11 Correct 16 ms 29832 KB Output is correct
12 Correct 20 ms 29788 KB Output is correct
13 Correct 17 ms 29788 KB Output is correct
14 Correct 17 ms 29788 KB Output is correct
15 Correct 18 ms 30044 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 461 ms 112616 KB Output is correct
2 Correct 458 ms 110880 KB Output is correct
3 Correct 505 ms 109196 KB Output is correct
4 Correct 464 ms 109008 KB Output is correct
5 Correct 460 ms 109756 KB Output is correct
6 Correct 441 ms 111244 KB Output is correct
7 Correct 434 ms 111532 KB Output is correct
8 Correct 422 ms 110760 KB Output is correct
9 Correct 406 ms 108868 KB Output is correct
10 Correct 355 ms 108628 KB Output is correct
11 Correct 353 ms 108624 KB Output is correct
12 Correct 357 ms 109652 KB Output is correct
13 Correct 475 ms 125684 KB Output is correct
14 Correct 414 ms 125780 KB Output is correct
15 Correct 446 ms 125924 KB Output is correct
16 Correct 436 ms 125788 KB Output is correct
17 Correct 430 ms 111688 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 13 ms 28508 KB Output is correct
2 Correct 13 ms 28584 KB Output is correct
3 Correct 12 ms 28508 KB Output is correct
4 Correct 13 ms 28508 KB Output is correct
5 Correct 12 ms 28508 KB Output is correct
6 Correct 12 ms 28660 KB Output is correct
7 Correct 12 ms 28500 KB Output is correct
8 Correct 12 ms 28508 KB Output is correct
9 Correct 12 ms 28504 KB Output is correct
10 Correct 16 ms 29784 KB Output is correct
11 Correct 16 ms 29832 KB Output is correct
12 Correct 20 ms 29788 KB Output is correct
13 Correct 17 ms 29788 KB Output is correct
14 Correct 17 ms 29788 KB Output is correct
15 Correct 18 ms 30044 KB Output is correct
16 Correct 461 ms 112616 KB Output is correct
17 Correct 458 ms 110880 KB Output is correct
18 Correct 505 ms 109196 KB Output is correct
19 Correct 464 ms 109008 KB Output is correct
20 Correct 460 ms 109756 KB Output is correct
21 Correct 441 ms 111244 KB Output is correct
22 Correct 434 ms 111532 KB Output is correct
23 Correct 422 ms 110760 KB Output is correct
24 Correct 406 ms 108868 KB Output is correct
25 Correct 355 ms 108628 KB Output is correct
26 Correct 353 ms 108624 KB Output is correct
27 Correct 357 ms 109652 KB Output is correct
28 Correct 475 ms 125684 KB Output is correct
29 Correct 414 ms 125780 KB Output is correct
30 Correct 446 ms 125924 KB Output is correct
31 Correct 436 ms 125788 KB Output is correct
32 Correct 430 ms 111688 KB Output is correct
33 Correct 447 ms 110928 KB Output is correct
34 Correct 177 ms 62804 KB Output is correct
35 Correct 484 ms 115152 KB Output is correct
36 Correct 433 ms 111052 KB Output is correct
37 Correct 488 ms 113736 KB Output is correct
38 Correct 442 ms 111952 KB Output is correct
39 Correct 470 ms 116784 KB Output is correct
40 Correct 489 ms 124804 KB Output is correct
41 Correct 412 ms 111948 KB Output is correct
42 Correct 368 ms 109260 KB Output is correct
43 Correct 522 ms 120916 KB Output is correct
44 Correct 459 ms 113028 KB Output is correct
45 Correct 436 ms 115272 KB Output is correct
46 Correct 462 ms 115284 KB Output is correct
47 Correct 430 ms 126032 KB Output is correct
48 Correct 436 ms 125780 KB Output is correct
49 Correct 452 ms 126032 KB Output is correct
50 Correct 453 ms 125780 KB Output is correct
51 Correct 479 ms 124528 KB Output is correct
52 Correct 459 ms 124372 KB Output is correct