Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <fstream>
- #include <iostream>
- #include <queue>
- #include <string>
- using namespace std;
- ifstream fin("coada1.in");
- ofstream fout("coada1.out");
- queue <int>q;
- queue <int>q2;
- string cmd;
- int ap[10001];
- int main()
- {
- int m,x,c=0;
- fin>>m;
- for(int i=1; i<=m; i++)
- {
- fin>>cmd>>x;
- if(cmd=="push")
- {
- if(ap[x]==0)
- {
- q.push(x);
- ap[x]++;
- }
- else
- {
- while(!q.empty()&&q.front()!=x)
- {
- ap[q.front()]--;
- q.pop();
- }
- if(!q.empty())
- q.pop();
- q.push(x);
- }
- }
- else if(cmd=="query")
- {
- if(ap[x]!=0)
- {
- q2=queue<int>(q);
- c=1;
- while(!q2.empty() && q2.front()!=x)
- {
- q2.pop();
- c++;
- }
- fout<<c<<'\n';
- }
- else
- {
- fout<<-1<<'\n';
- }
- }
- }
- fin.close();
- fout.close();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement