Team Selection1.pas 768 B

123456789101112131415161718192021222324252627282930313233343536
  1. #include <stdio.h>
  2. int n;
  3. int list[524288];
  4. int rank[2][524288];
  5. int itree[20][524288];
  6. int ans;
  7. int main(void) {
  8. int i, t;
  9. int level, offset;
  10. scanf("%d", &n);
  11. for (i=1; i<=n; i++) scanf("%d", &list[i]);
  12. for (i=1; i<=n; i++) {
  13. scanf("%d", &t);
  14. rank[0][t] = i;
  15. }
  16. for (i=1; i<=n; i++) {
  17. scanf("%d", &t);
  18. rank[1][t] = i;
  19. }
  20. for (i=1; i<=n; i++) {
  21. t = 1;
  22. for (level=0, offset=rank[1][list[i]]; level<=19; level++,offset/=2) {
  23. if (!itree[level][offset] ||rank[0][list[i]]<itree[level][offset])
  24. itree[level][offset] = rank[0][list[i]];
  25. if (offset%2 && itree[level][offset-1] &&itree[level][offset-1]<rank[0][list[i]]) {
  26. t = 0;
  27. break;
  28. }
  29. }
  30. ans += t;
  31. }
  32. printf("%d\n", ans);
  33. return 0;
  34. }