Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- using namespace std;
- int a[100011],n,m,k,mn,s,l,q,p[100011],o[100011],u,i;
- //p[i]- locul persoanei ce a rezervat locul i;
- //o[i]-locul rezervat al persoanei ce ocupa locul i;
- //a[i]=0=>loc liber;altfel ocupat;
- char c;
- ifstream f("input.txt");
- ofstream g("output.txt");
- int main()
- {
- f>>n>>m;
- while(m--)
- {
- f>>c>>q;
- if(c=='b')
- {
- if(mn<=q)
- {
- a[mn]=1;
- o[mn]=q;
- p[q]=mn;
- i=mn+1;
- while(a[i])
- ++i;
- mn=i;
- }
- else
- {
- while(a[q]>0)
- {
- ++s;
- p[q]=q;
- u=o[q];
- o[q]=q;
- q=u;
- }
- a[q]=1;
- if(q==mn)
- {
- i=mn+1;
- while(a[i])
- ++i;
- mn=i;
- }
- }
- }
- else
- {
- a[p[q]]=0;
- mn=min(mn,p[q]);
- }
- }
- g<<s;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement