답안 #826913

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
826913 2023-08-16T06:31:08 Z peteza 늑대인간 (IOI18_werewolf) C++14
100 / 100
494 ms 103520 KB
#include "werewolf.h"
#include <bits/stdc++.h>
using namespace std;
 
vector<int> adj[200005];
vector<int> ladj[400005], radj[400005];
int pl[400005], pr[400005];
int pls, prs, cur;
int llabel[400005], rlabel[400005];
pair<int, int> rngl[400005], rngr[400005];
int fenw[400005];
bool vis[400005];
 
int qr(int x) {
  int s = 0;
  for(;x;x-=x&-x) s += fenw[x];
  return s;
}
 
void upd(int x) {
  for(;x<=400000;x+=x&-x) fenw[x]++;
}
 
int fpar(int *parr, int x) {
  return parr[x] == x ? x : (parr[x] = fpar(parr, parr[x]));
}
 
void dfs(vector<int>* adj, pair<int, int>* rngarr, int *lab, int x) {
  rngarr[x].first = cur;// cout << x << ' ';
  if(adj[x].empty()){lab[x] = cur; rngarr[x].second=cur++; return;}
  for(int e:adj[x]) dfs(adj, rngarr, lab, e);
  rngarr[x].second = cur-1;
}
 
vector<int> check_validity(int N, vector<int> X, vector<int> Y, vector<int> S, vector<int> E, vector<int> L, vector<int> R) {
  for(int i=0;i<=400000;i++) pl[i] = pr[i] = i;
  int Q = S.size(); pls = prs = N;
  vector<int> A(Q, 0);
  vector<pair<int, int>> ls(Q), rs(Q);
  vector<int> lnode(Q), rnode(Q);
  for(int i=0;i<Q;i++) ls[i] = {L[i], i};
  for(int i=0;i<Q;i++) rs[i] = {R[i], i};
  for(int i=0;i<N;i++) ls.emplace_back(i, INT_MAX), rs.emplace_back(i, INT_MIN);
  sort(ls.rbegin(), ls.rend()); sort(rs.begin(), rs.end());
  vector<pair<int, int>> points;
  for(int i=0;i<X.size();i++) {
    adj[X[i]].push_back(Y[i]);
    adj[Y[i]].push_back(X[i]);
  }
  for(auto e:ls) {
    if(e.second == INT_MAX) { //merge
      ladj[pls].push_back(e.first); pl[e.first] = pls;
      for(int E:adj[e.first]) {
        if(E <= e.first) continue;
        if(fpar(pl, E) == pls) continue;
        ladj[pls].push_back(fpar(pl, E));
        pl[fpar(pl, E)] = pls; 
      }
      pls++;
    } else {
      lnode[e.second] = fpar(pl, S[e.second]);
    }
  }
  for(auto e:rs) {
    if(e.second == INT_MIN) { //merge
      radj[prs].push_back(e.first); pr[e.first] = prs;
      for(int E:adj[e.first]) {
        if(E >= e.first) continue;
        if(fpar(pr, E) == prs) continue;
        radj[prs].push_back(fpar(pr, E));
        pr[fpar(pr, E)] = prs;
      }
      prs++;
    } else {
      rnode[e.second] = fpar(pr, E[e.second]);
    }
  } pls--; prs--; //pls, prs == root of left and right respectively
  //for(int i=0;i<=pls;i++) {cout << i << ": "; for(int e:ladj[i]) cout << e << ' '; cout << '\n';}
  cur = 1; dfs(ladj, rngl, llabel, pls); 
  cur = 1; dfs(radj, rngr, rlabel, prs);
  for(int i=0;i<N;i++) points.emplace_back(llabel[i], rlabel[i]);
  for(int i=0;i<Q;i++) points.emplace_back(rngl[lnode[i]].first-1, N+i+1), points.emplace_back(rngl[lnode[i]].second, N+i+1);
  //cout << "Helhloe";
  sort(points.begin(), points.end());
  for(auto e:points) {
    if(e.second > N) {
      int ci = e.second-N-1; //query number
      A[ci] += (vis[ci] ? 1 : -1) * (qr(rngr[rnode[ci]].second) - qr(rngr[rnode[ci]].first-1));
      vis[ci] = 1; A[ci] = min(A[ci], 1);
    } else {
      upd(e.second);
    }
  }
  return A;
}

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:46:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   46 |   for(int i=0;i<X.size();i++) {
      |               ~^~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 15 ms 26964 KB Output is correct
2 Correct 14 ms 26964 KB Output is correct
3 Correct 13 ms 26996 KB Output is correct
4 Correct 13 ms 27000 KB Output is correct
5 Correct 12 ms 26972 KB Output is correct
6 Correct 13 ms 26964 KB Output is correct
7 Correct 13 ms 26996 KB Output is correct
8 Correct 13 ms 26996 KB Output is correct
9 Correct 14 ms 26992 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 15 ms 26964 KB Output is correct
2 Correct 14 ms 26964 KB Output is correct
3 Correct 13 ms 26996 KB Output is correct
4 Correct 13 ms 27000 KB Output is correct
5 Correct 12 ms 26972 KB Output is correct
6 Correct 13 ms 26964 KB Output is correct
7 Correct 13 ms 26996 KB Output is correct
8 Correct 13 ms 26996 KB Output is correct
9 Correct 14 ms 26992 KB Output is correct
10 Correct 20 ms 27988 KB Output is correct
11 Correct 17 ms 27984 KB Output is correct
12 Correct 17 ms 27888 KB Output is correct
13 Correct 18 ms 28172 KB Output is correct
14 Correct 18 ms 28120 KB Output is correct
15 Correct 18 ms 28068 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 429 ms 87076 KB Output is correct
2 Correct 415 ms 91604 KB Output is correct
3 Correct 406 ms 88528 KB Output is correct
4 Correct 448 ms 87396 KB Output is correct
5 Correct 442 ms 87388 KB Output is correct
6 Correct 416 ms 87172 KB Output is correct
7 Correct 408 ms 87056 KB Output is correct
8 Correct 386 ms 91744 KB Output is correct
9 Correct 354 ms 88612 KB Output is correct
10 Correct 379 ms 90524 KB Output is correct
11 Correct 381 ms 90428 KB Output is correct
12 Correct 408 ms 90252 KB Output is correct
13 Correct 409 ms 96520 KB Output is correct
14 Correct 357 ms 96524 KB Output is correct
15 Correct 367 ms 96468 KB Output is correct
16 Correct 407 ms 96520 KB Output is correct
17 Correct 432 ms 90268 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 15 ms 26964 KB Output is correct
2 Correct 14 ms 26964 KB Output is correct
3 Correct 13 ms 26996 KB Output is correct
4 Correct 13 ms 27000 KB Output is correct
5 Correct 12 ms 26972 KB Output is correct
6 Correct 13 ms 26964 KB Output is correct
7 Correct 13 ms 26996 KB Output is correct
8 Correct 13 ms 26996 KB Output is correct
9 Correct 14 ms 26992 KB Output is correct
10 Correct 20 ms 27988 KB Output is correct
11 Correct 17 ms 27984 KB Output is correct
12 Correct 17 ms 27888 KB Output is correct
13 Correct 18 ms 28172 KB Output is correct
14 Correct 18 ms 28120 KB Output is correct
15 Correct 18 ms 28068 KB Output is correct
16 Correct 429 ms 87076 KB Output is correct
17 Correct 415 ms 91604 KB Output is correct
18 Correct 406 ms 88528 KB Output is correct
19 Correct 448 ms 87396 KB Output is correct
20 Correct 442 ms 87388 KB Output is correct
21 Correct 416 ms 87172 KB Output is correct
22 Correct 408 ms 87056 KB Output is correct
23 Correct 386 ms 91744 KB Output is correct
24 Correct 354 ms 88612 KB Output is correct
25 Correct 379 ms 90524 KB Output is correct
26 Correct 381 ms 90428 KB Output is correct
27 Correct 408 ms 90252 KB Output is correct
28 Correct 409 ms 96520 KB Output is correct
29 Correct 357 ms 96524 KB Output is correct
30 Correct 367 ms 96468 KB Output is correct
31 Correct 407 ms 96520 KB Output is correct
32 Correct 432 ms 90268 KB Output is correct
33 Correct 467 ms 91804 KB Output is correct
34 Correct 236 ms 69140 KB Output is correct
35 Correct 467 ms 95024 KB Output is correct
36 Correct 432 ms 91004 KB Output is correct
37 Correct 472 ms 94152 KB Output is correct
38 Correct 443 ms 91792 KB Output is correct
39 Correct 421 ms 103188 KB Output is correct
40 Correct 481 ms 100412 KB Output is correct
41 Correct 466 ms 93328 KB Output is correct
42 Correct 414 ms 91104 KB Output is correct
43 Correct 464 ms 99320 KB Output is correct
44 Correct 440 ms 93916 KB Output is correct
45 Correct 416 ms 103520 KB Output is correct
46 Correct 429 ms 103244 KB Output is correct
47 Correct 376 ms 96696 KB Output is correct
48 Correct 389 ms 96456 KB Output is correct
49 Correct 368 ms 96684 KB Output is correct
50 Correct 366 ms 96524 KB Output is correct
51 Correct 494 ms 101004 KB Output is correct
52 Correct 490 ms 100908 KB Output is correct