Advertisement
FyanRu

Untitled

Feb 26th, 2023
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.12 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. #define pb push_back
  3. #define ins insert
  4. using namespace std;
  5.  
  6. int n;
  7.  
  8. struct psycho {
  9. int f;
  10. int b;
  11. int id;
  12. };
  13.  
  14. vector<psycho> ps;
  15. set<int> killerpos;
  16.  
  17. void init() {
  18. psycho danielnie;
  19. danielnie.f=-1;
  20. danielnie.b=0; //tba
  21. danielnie.id=n+1;
  22. ps.pb(danielnie);
  23.  
  24. cin>>n;
  25.  
  26. for (int i=0; i<n; i++) {int id; cin>>id;psycho temp; ps[i].b=i; temp.f=i; temp.id=id; ps.pb(temp); killerpos.ins(i+1);}
  27.  
  28. psycho niedaniel;
  29. niedaniel.f=n-1;
  30. niedaniel.b=-1;
  31. niedaniel.id=n+1;
  32. ps.pb(niedaniel);
  33. }
  34.  
  35. int killPeople() {
  36. int killed=0;
  37. set<int>::reverse_iterator i;
  38.  
  39. for (i = killerpos.rbegin(); i!=killerpos.rend(); i++) {
  40. int k=*i;
  41. if (ps[k].id>ps[ps[k].b].id) {
  42. ps[k].b=ps[ps[k].b].b;
  43. killed++;
  44. if (killerpos.find(ps[k].b)!=killerpos.find(ps[k].b).end()) {killerpos.erase(ps[k].b);}
  45. } else {
  46. killerpos.erase(k);
  47. }
  48. }
  49. cout<<killed<<"\n";
  50. return killed;
  51. }
  52.  
  53. int main() {
  54. init();
  55. killPeople();
  56. return 0;
  57. }
  58.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement