Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- #define pb push_back
- #define ins insert
- using namespace std;
- int n;
- struct psycho {
- int f;
- int b;
- int id;
- };
- vector<psycho> ps;
- set<int> killerpos;
- void init() {
- psycho danielnie;
- danielnie.f=-1;
- danielnie.b=0; //tba
- danielnie.id=n+1;
- ps.pb(danielnie);
- cin>>n;
- 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);}
- psycho niedaniel;
- niedaniel.f=n-1;
- niedaniel.b=-1;
- niedaniel.id=n+1;
- ps.pb(niedaniel);
- }
- int killPeople() {
- int killed=0;
- set<int>::reverse_iterator i;
- for (i = killerpos.rbegin(); i!=killerpos.rend(); i++) {
- int k=*i;
- if (ps[k].id>ps[ps[k].b].id) {
- ps[k].b=ps[ps[k].b].b;
- killed++;
- if (killerpos.find(ps[k].b)!=killerpos.find(ps[k].b).end()) {killerpos.erase(ps[k].b);}
- } else {
- killerpos.erase(k);
- }
- }
- cout<<killed<<"\n";
- return killed;
- }
- int main() {
- init();
- killPeople();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement