Problem:
Problem D:
Distorted Love
Saying that it is not surprising that people want to know about their love, she has checked up his address, name, age, phone number, hometown, medical history, political party and even his sleeping position, every piece of his personal information. The word "privacy" is not in her dictionary. A person like her is called "stoker" or "
yandere
", but it doesn't mean much to her.
To know about him, she set up spyware to his PC. This spyware can record his mouse operations while he is browsing websites. After a while, she could successfully obtain the record from the spyware in absolute secrecy.
Well, we want you to write a program which extracts web pages he visited from the records.
All pages have the same size
H
×
W
where upper-left corner is (0, 0) and lower right corner is (
W
,
H
). A page includes several (or many) rectangular buttons (parallel to the page). Each button has a link to another page, and when a button is clicked the browser leads you to the corresponding page.
His browser manages history and the current page in the following way:
The browser has a buffer of 1-dimensional array with enough capacity to store pages, and a pointer to indicate a page in the buffer. A page indicated by the pointer is shown on the browser. At first, a predetermined page is stored and the pointer indicates that page. When the link button is clicked, all pages recorded in the right side from the pointer are removed from the buffer. Then, the page indicated by the link button is stored into the right-most position of the buffer, and the pointer moves to right. As a result, the user browse the page indicated by the button.
The browser also has special buttons 'back to the previous page' (back button) and 'forward to the next page' (forward button). When the user clicks the back button, the pointer moves to left, and the user clicks the forward button, the pointer moves to right. But in both cases, if there are no such pages in the buffer, nothing happen.
The record consists of the following operations:
click x y
It means to click (
x
,
y
). If there is a button on the point (
x
,
y
), he moved to the corresponding page. If there is nothing in the point, nothing happen. The button is clicked if
x
1 ≤
x
≤
x
2 and
y
1 ≤
y
≤
y
2 where
x
1,
x
2 means the leftmost and rightmost coordinate and
y
1,
y
2 means the topmost and bottommost coordinate of the corresponding button respectively.
back
It means to click the Back button.
forward
It means to click the Forward button.
In addition, there is a special operation
show
. Your program should print the name of current page for each
show
operation.
By the way, setting spyware into computers of others may conflict with the law. Do not attempt, or you will be reprimanded by great men.
Input
Input consists of several datasets.
Each dataset starts with an integer
n
which represents the number of pages in the dataset.
Next line contains two integers
W
and
H
.
Next, information of each page are give
...(truncated)

Submitted solutions:

code_snippet: #include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <sstream>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <bitset>
 
#define rep(i, n) for(int i = 0; i < (n); i++)
#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define all(v) (v).begin(), (v).end()
#define rev(s) (s).rbegin(), (s).rend()
#define MP make_pair
#define X first
#define Y second
 
using namespace std;
 
typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> vi;

void fin(){
	freopen("test.txt", "r", stdin);
}

struct button{
	int left, top, right, bottom;
	string link;
	button(int l, int t, int r, int b, string li){
		left = l, top = t, right = r, bottom = b, link = li;
	}
};

int main(){
	//fin();
	int n;
	while(cin >> n, n){
		int w, h;
		cin >> w >> h;
		map<string, vector<button> > pages;
		string current;
		rep(i, n){
			string s;
			int bn;
			cin >> s >> bn;
			if(!i) current = s;
			rep(i, bn){
				int left, top, right, bottom;
				string link;
				cin >> left >> top >> right >> bottom >> link;
				pages[s].push_back(button(left, top, right, bottom, link));
			}
		}
		stack<string> back;
		stack<string> forward;
		int m;
		cin >> m;
		rep(i, m){
			string com;
			cin >> com;
			if(com == "click"){
				int x, y;
				cin >> x >> y;
				rep(i, pages[current].size()){
					button b = pages[current][i];
					if(x < b.left || x > b.right || y < b.top || y > b.bottom) continue;
					back.push(current);
					forward = stack<string>();
					current = b.link;
					break;
				}
			}
			else if(com == "back"){
				if(back.empty())continue;
				forward.push(current);
				current = back.top();
				back.pop();
			}
			else if(com == "forward"){
				if(forward.empty())continue;
				back.push(current);
				current = forward.top();
				forward.pop();
			}
			else if(com == "show"){
				cout << current << endl;
			}
		}
	}

	return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 1276
final_rank: 13

code_snippet: #include <iostream>
#include <string>
#include <vector>
#include <map>
using namespace std;

struct Button {
    int x1, y1, x2, y2;
    string to;
};

struct Page {
    vector<Button> bs;
};

int main() {
    int n;
    while (cin >> n, n) {
        int w, h;
        cin >> w >> h;
        map<string, Page> ps;
        vector<string> buf;
        for (int i = 0; i < n; i++) {
            string name;
            int b;
            cin >> name >> b;
            Page p;
            for (int j = 0; j < b; j++) {
                Button l;
                cin >> l.x1 >> l.y1 >> l.x2 >> l.y2 >> l.to;
                p.bs.push_back(l);
            }
            ps[name] = p;
            if (i == 0) {
                buf.push_back(name);
            }
        }
        int m;
        cin >> m;
        int idx = 0;
        for (int i = 0; i < m; i++) {
            string cmd;
            cin >> cmd;
            if (cmd == "click") {
                int x, y;
                cin >> x >> y;
                Page p = ps[buf[idx]];
                for (vector<Button>::iterator it = p.bs.begin(); it != p.bs.end(); it++) {
                    if (it->x1 <= x && x <= it->x2 && it->y1 <= y && y <= it->y2) {
                        buf.erase(buf.begin() + idx + 1, buf.end());
                        buf.push_back(it->to);
                        idx++;
                        break;
                    }
                }
            } else if (cmd == "back") {
                if (idx > 0) {
                    idx--;
                }
            } else if (cmd == "forward") {
                if (idx < (int) buf.size() - 1) {
                    idx++;
                }
            } else if (cmd == "show") {
                cout << buf[idx] << endl;
            }
        }
    }
}
accuracy: 1
time_ms: 30
memory_kb: 1256
final_rank: 15

code_snippet: #include<iostream>
#include<string>
#include<map>
#include<vector>
#include<algorithm>

using namespace std;

struct POINT{
  int x1, y1;
  int x2, y2;
};

multimap<string, POINT> MakeButton(int);
void Click(map< string, multimap<string, POINT> >,
	   vector<string>&, int&, int, int);

int main(){
  int i, n, m, w, h, now;
  string str;
  vector<string> logdata;
  map< string, multimap<string, POINT> > webpage;

  while(1){
    cin >> n;
    if(n == 0) break;
    cin >> w >> h;

    for(i=0; i<n; ++i){
      cin >> str >> m;
      if(i == 0) logdata.push_back(str);
      webpage.insert(make_pair(str, MakeButton(m)));
    }

    cin >> m;
    for(i=0, now=0; i<m; ++i){
      cin >> str;
      if(str == "click") Click(webpage, logdata, now, w, h);
      else if(str == "back" && now > 0) --now;
      else if(str == "forward" && now < logdata.size()-1) ++now;
      else if(str == "show") cout << logdata[now] << endl;
    }

    logdata.clear();
    webpage.clear();
  }
  return 0;
}

multimap<string, POINT> MakeButton(int n){
  int i, x1, y1, x2, y2;
  string str;
  POINT p;
  multimap<string, POINT> button;

  for(i=0; i<n; ++i){
    cin >> p.x1 >> p.y1 >> p.x2 >> p.y2 >> str;
    button.insert(make_pair(str, p));
  }
  return button;
}

void Click(map< string, multimap<string, POINT> > webpage,
	   vector<string>& logdata, int& now, int w, int h){
  int x, y;
  cin >> x >> y;
  if(x < 0 || w < x || y < 0 || h < y) return;

  POINT p;
  multimap<string, POINT> button;
  multimap<string, POINT>::iterator i;
  map< string, multimap<string, POINT> >::iterator j;

  j = webpage.find(logdata[now]);
  if(j == webpage.end()) return;
  button = j->second;

  for(i=button.begin(); i!=button.end(); ++i){
    p = i->second;
    if(p.x1 <= x && x <= p.x2 && p.y1 <= y && y <= p.y2){
      ++now;
      logdata.erase(logdata.begin()+now, logdata.end());
      logdata.push_back(i->first);
      return;
    }
  }
}
accuracy: 1
time_ms: 10
memory_kb: 1276
final_rank: 13

code_snippet: #include<cmath>
#include<algorithm>
#include<iostream>
#include<vector>
#include<climits>
#include<cfloat>

using namespace std;

struct point{
  double x, y;
};

struct button{
  point ld,ru;
  string name;
};

struct page{
  string name;
  vector<button>btn;   
}; 

int main(void){
  int n;
  int w,h,b;
  point l,r;
  page in;
  vector<page> a;
  button tmp;

  while(cin >> n,n){
  
    a.clear();

    cin >> w >> h;
    
    for(int j=0;j<n;j++){
      in.btn.clear();
      cin >> in.name >> b;    
      
      for(int i=0;i<b;i++){
	cin >> tmp.ld.x >> tmp.ld.y >> tmp.ru.x >> tmp.ru.y >> tmp.name;
	in.btn.push_back(tmp);
      }
      a.push_back(in);
    }

    int m,now=0,fg=0;
    static page buf[1000000];

    cin >> m;
    buf[0]=a[0];

    for(int k=0;k<m;k++){
      string s;
      cin >> s;
      
      if(s=="click"){
	int c,d;
	cin >> c >> d;
	
	for(int i=0;i<buf[now].btn.size();i++){
	  int fg2=0;
	  if(buf[now].btn[i].ld.x <=c &&
	     buf[now].btn[i].ld.y <=d &&
	     buf[now].btn[i].ru.x >=c &&
	     buf[now].btn[i].ru.y >=d){
	    for(int j=0;j<a.size();j++){
	      if(buf[now].btn[i].name==a[j].name){
		buf[++now]=a[j];
		fg=0;
		fg2=1;
		break;
	      }
	    }
	    if(fg2)break;
	  }
	}
      }
      else if(s=="back" && now>0){
	now--;
	fg++;
      }
      else if(s=="forward" && fg>0 && now < 1000000)now++,fg--;
      else if(s=="show")cout << buf[now].name << endl;
    }
  }

  return 0;
}
accuracy: 1
time_ms: 20
memory_kb: 19000
final_rank: 18

code_snippet: #include<cmath>
#include<algorithm>
#include<iostream>
#include<vector>
#include<climits>
#include<cfloat>

using namespace std;

struct point{
  int x, y;
};

struct button{
  point l,r;
  string name;
};

struct page{
  string name;
  vector<button>btn;   
}; 

int m,now;
vector<page> a;
page nowpage;
string buf[10001];

void func(void){
  for(int i=0;i<a.size();i++){
    if(buf[now]==a[i].name){
      nowpage=a[i];
      return ;
    }
  }
}

void click(int c,int d){
  
  for(int i=0;i<nowpage.btn.size();i++){
    if(nowpage.btn[i].l.x <=c && c<=nowpage.btn[i].r.x &&
       nowpage.btn[i].l.y <=d && d<=nowpage.btn[i].r.y ){
      fill(buf+now+1,buf+10001,"");
      buf[++now]=nowpage.btn[i].name;
      return ;
    }
  }
}


int main(void){
  int n;
  int w,h,b;
  page in;
  button tmp;

  while(cin >> n,n){
  
    a.clear();
    fill(buf,buf+10001,"");

    cin >> w >> h;
    
    for(int i=0;i<n;i++){
      in.btn.clear();
      cin >> in.name >> b;    
      if(i==0)buf[0]=in.name;

      for(int j=0;j<b;j++){
	cin >> tmp.l.x >> tmp.l.y >> tmp.r.x >> tmp.r.y >> tmp.name;
	in.btn.push_back(tmp);
      }
      a.push_back(in);
    }

    now=0;

    cin >> m;

    while(m--){
      string s;
      cin >> s;

      func();

      if(s=="click"){
	int c,d;
	cin >> c >> d;
	click(c,d);
      }
      else if(s=="back" && now>0)now--;
      else if(s=="forward" && buf[now+1]!="")now++;
      else if(s=="show")cout << buf[now] << endl;

    }
  }

  return 0;
}
accuracy: 1
time_ms: 240
memory_kb: 992
final_rank: 17

code_snippet: #include<iostream>
#include<map>
#include<vector>
#include<algorithm>

using namespace std;

const int MAX = 10001;

string data[MAX];
int W,H,N;

struct Button{
  int lx,rx,ly,ry;
  string name;
};

map<string,vector<Button> > M;


void init(){
  M.clear();
  fill(data,data+MAX,"");
}

void input(){
  cin >> W >> H;
  for(int i = 0; i < N; i++){
    string s;
    int num;
    cin >> s >> num;
    if(i == 0) data[0] = s;

    for(int j = 0; j < num; j++){
      Button B;
      cin >> B.lx >> B.ly >> B.rx >> B.ry >> B.name;
      M[s].push_back(B);	
    }

  }
}

void solve(){
  int num;
  cin >> num;
  int index = 0;


  while(num--){
    string op;
    cin >> op;
    if(op == "click"){
      int x,y;
      cin >> x >> y;
      string now = data[index];

      for(int i = 0; i < M[now].size(); i++){
	if(M[now][i].lx <= x && x <= M[now][i].rx && M[now][i].ly <= y && y <= M[now][i].ry){
	  data[++index] = M[now][i].name;
	  fill(data+index+1,data+MAX,"");
	  break;
	}

      }

    }else if(op == "back" && index > 0) index--;
    else if(op == "forward" && data[index+1] != "") index++;
    else if(op == "show") cout << data[index] << endl;
  }
}

int main(){

  while(cin >> N && N){
    input();
    solve();
  }
  return 0;
}
accuracy: 1
time_ms: 270
memory_kb: 984
final_rank: 19

code_snippet: #define _USE_MATH_DEFINES
#define INF 100000000
#include <iostream>
#include <sstream>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>
#include <set>
#include <deque>
#include <bitset>
#include <list>

using namespace std;

typedef long long ll;
typedef pair <int,int> P;
typedef pair <int,P> PP;

static const double EPS = 1e-8;

const int tx[] = {0,1,0,-1};
const int ty[] = {-1,0,1,0};

class Button{
public:
	int lu_x,lu_y,rl_x,rl_y;
	string name;
	Button() : lu_x(0),lu_y(0),rl_x(0),rl_y(0),name(""){}
	Button(int lu_x,int lu_y,int rl_x,int rl_y,string name): lu_x(lu_x),lu_y(lu_y),rl_x(rl_x),rl_y(rl_y),name(name){}
};

int main(){
	int n;
	int W,H;
	
	while(~scanf("%d",&n)){
		if(n==0) break;
		map<string,vector<Button> > page;
		vector<string> browsed;
		scanf("%d %d",&W,&H);
		for(int i=0;i<n;i++){
			string name;
			int num;
			cin >> name >> num;
			for(int j=0;j<num;j++){
				string next;
				int lu_x,lu_y,rl_x,rl_y;
				cin >> lu_x >> lu_y >> rl_x >> rl_y >> next;
				page[name].push_back(Button(lu_x,lu_y,rl_x,rl_y,next));
				if(browsed.size()==0) browsed.push_back(name);
			}
		}

		int m;
		int pos = 0;
		scanf("%d",&m);
		for(int i=0;i<m;i++){
			string act;
			cin >> act;
			if(act=="click"){
				int x,y;
				cin >> x >> y;
				string now = browsed[pos];
				for(int j=0;j<page[now].size();j++){
					if((page[now][j].lu_x <= x && x <= page[now][j].rl_x)
						&& (page[now][j].lu_y <= y && y <= page[now][j].rl_y)){
							//printf("to %s\n",page[now][j].name.c_str());

							browsed.erase(browsed.begin()+pos+1,browsed.end());
							browsed.push_back(page[now][j].name);
							pos++;
							break;
					}
				}
			}
			else if(act=="back"){

				if(pos>0){
					pos--;
					//printf("back\n");
				}
			}
			else if(act=="forward"){
				if(pos<browsed.size()-1){
					pos++;
					//printf("forwardk\n");
				}
			}
			else if(act=="show"){
				cout << browsed[pos] << "\n";
			}
		}
	}
	return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 0
final_rank: 1

code_snippet: #include <iostream>
#include <sstream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>

using namespace std;

#define FOR(i,k,n) for(int i=(k); i<(int)n; ++i)
#define REP(i,n) FOR(i,0,n)
#define FORIT(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)

template<class T> void debug(T begin, T end){ for(T i = begin; i != end; ++i) cout<<*i<<" "; cout<<endl; }

typedef long long ll;
const int INF = 100000000;
const double EPS = 1e-8;
const int MOD = 1000000007;
struct Page{
  string name;
  vector<int> bx;
  vector<int> by;
  vector<int> ex;
  vector<int> ey;
  vector<string> to;
  Page(string n){
    name = n;
  }
  void add(int x1, int y1, int x2, int y2, string s){
    bx.push_back(x1);
    by.push_back(y1);
    ex.push_back(x2);
    ey.push_back(y2);
    to.push_back(s);
  }
  string link(int x, int y){
    REP(i,bx.size()){
      if(bx[i] <= x && x <= ex[i] && by[i] <= y && y <= ey[i]){
        return to[i];
      }
    }
    return "";
  }
};


int main(){
  int N;
  while(cin>>N, N){
    int W,H; cin>>W>>H;
    vector<Page> pages;
    map<string, int> id;
    REP(i,N){
      string s; int n;
      cin>>s>>n;
      id[s] = i;
      Page p(s);
      while(n--){
        int a,b,c,d; string nm;
        cin>>a>>b>>c>>d>>nm;
        p.add(a,b,c,d,nm);
      }
      pages.push_back(p);
    }
    int O; cin>>O;
    vector<Page> bf;
    bf.push_back(pages[0]);
    int p = 0;
    while(O--){
      string ope; cin>>ope;
      int x,y;
      if(ope == "show"){
        cout<<bf[p].name<<endl;
      }
      if(ope == "forward"){
        if(p + 1 < bf.size()) p += 1;
      }
      if(ope == "back"){
        if(p - 1 >= 0) p -= 1;
      }
      if(ope == "click"){
        cin>>x>>y;
        string linkname = bf[p].link(x,y);
        int toidx = -1;
        if(id.count(linkname)) toidx = id[linkname];
        if(toidx != -1) {
          Page nextpage = pages[toidx];
          bf.erase(bf.begin() + p + 1, bf.end());
          bf.push_back(nextpage);
          p++;
        }
      }
    }
  }
  return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 0
final_rank: 1

code_snippet: #include <iostream>
#include <vector>
#include <string>
#include <map>
using namespace std;

typedef struct
{
  string name;
  int x1, x2, y1, y2;
} Button;

int main()
{
  int n;
  while (cin >> n) {
    if (n == 0)
      break;

    int W, H;
    cin >> W >> H;

    vector<string > buf;
    map<string, vector<Button> > button;
    for (int i = 0; i < n; ++i) {
      string name;
      int b;
      cin >> name >> b;
      for (int j = 0; j < b; ++j) {
	Button tmp;
	cin >> tmp.x1 >> tmp.y1 >> tmp.x2 >> tmp.y2 >> tmp.name;
	button[name].push_back(tmp);
      }

      if (i == 0)
	buf.push_back(name);
    }

    int m, p = 0;
    cin >> m;
    while (m--) {
      string cmd;
      cin >> cmd;

      if (cmd == "click") {
	int x, y;
	cin >> x >> y;
	const vector<Button>& link = button[buf[p]];
	for (int i = 0; i < link.size(); ++i) {
	  if (link[i].x1 <= x && x <= link[i].x2 &&
	      link[i].y1 <= y && y <= link[i].y2) {
	    buf.erase(buf.begin()+p+1, buf.end());
	    buf.push_back(link[i].name);
	    ++p;
	    break;
	  }
	}
      } else if (cmd == "show") {
	cout << buf[p] << endl;
      } else if (cmd == "back") {
	if (p != 0)
	  --p;
      } else {
	if (p+1 < buf.size())
	  ++p;
      }
    }
  }
  return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 0
final_rank: 1

code_snippet: #include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <cfloat>
#include <ctime>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <numeric>
#include <list>

using namespace std;

#ifdef _MSC_VER
#define __typeof__ decltype
template <class T> int __builtin_popcount(T n) { return n ? 1 + __builtin_popcount(n & (n - 1)) : 0; }
#endif

#define foreach(it, c) for (__typeof__((c).begin()) it=(c).begin(); it != (c).end(); ++it)
#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
#define popcount __builtin_popcount

#define rep(i, n) for (int i = 0; i < n; ++i)

template <class T> void max_swap(T& a, const T& b) { a = max(a, b); }
template <class T> void min_swap(T& a, const T& b) { a = min(a, b); }

typedef long long ll;
typedef pair<int, int> pint;


struct Button
{
	int x1, y1, x2, y2;
	string name;
	bool include(int x, int y)
	{
		return x1 <= x && x <= x2
			&& y1 <= y && y <= y2;
	}
	void input()
	{
		cin >> x1 >> y1 >> x2 >> y2 >> name;
	}
};
int main()
{
	int n, m, w, h;
	while (cin >> n, n)
	{
		cin >> w >> h;

		map<string, vector<Button> > page;
		vector<string> buffer;
		rep (i, n)
		{
			string name;
			int b;
			cin >> name >> b;
			if (i == 0)
				buffer.push_back(name);

			while (b--)
			{
				page[name].push_back(Button());
				page[name].back().input();
			}
		}

		cin >> m;
		int pointer = 0;
		while (m--)
		{
			string& b = buffer[pointer];

			string c;
			cin >> c;
			if (c[0] == 'c')
			{
				int x, y;
				cin >> x >> y;
				for (int i = 0; i < page[b].size(); ++i)
				{
					if (page[b][i].include(x, y))
					{
						++pointer;
						buffer.erase(buffer.begin() + pointer, buffer.end());
						buffer.push_back(page[b][i].name);
						break;
					}
				}
			}
			else if (c[0] == 'b')
				pointer = max(0, --pointer);
			else if (c[0] == 'f')
				pointer = min((int)buffer.size() - 1, ++pointer);
			else if (c[0] == 's')
				cout << b << endl;
		}
	}
}
accuracy: 1
time_ms: 10
memory_kb: 0
final_rank: 1

code_snippet: #include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <string>

using namespace std;

struct button{
	string toName;
	int minx;
	int maxx;
	int miny;
	int maxy;
};

int page;
vector<string> history;
int n;
int h,w;
map<string,vector<button> > pageInfo;

int main(){

	while(cin>>n&&n!=0){
		history.clear();
		pageInfo.clear();
		page=0;
		history.clear();
		cin>>w>>h;
		for(int i = 0; i < n; i++){
			string str;
			int bn;
			cin>>str>>bn;
			if(i==0){
				history.push_back(str);
			}
			vector<button> vb;
			for(int j = 0; j < bn; j++){
				button b;
				cin>>b.minx>>b.miny>>b.maxx>>b.maxy>>b.toName;
				vb.push_back(b);
			}
			pageInfo[str]=vb;
		}
		int m;
		cin>>m;
		// operation start
		for(int i = 0; i < m; i++){
			string op;
			cin>>op;
			if(op=="click"){
				int x,y;
				cin>>x>>y;
				// buttonÌÊuðcheck
				for(int j = 0; j < pageInfo[history[page]].size(); j++){
					// Ú®Å«éÌÈçÎA»ÝÌêÌ¨É éhistoryðíµA»ÝÌêÌ¨ÉÚ®æy[WðÇÁµApageðCNg
					button &b = pageInfo[history[page]][j];
					if(b.minx<=x&&b.maxx>=x&&b.miny<=y&&b.maxy>=y){
						// »ÝÌêÌEÉ éhistoryðí
						int t=history.size();
						for(int k = page+1; k < t; k++){
							history.erase(history.begin()+history.size()-1);
						}
						// »ÝÌêÌEÉÚ®æy[WðÇÁ
						history.push_back(b.toName);
						page++;
						break;
					}
				}
			}
			else if(op=="show"){
				cout<<history[page]<<endl;
			}
			else if(op=="back"){
				page=max(0,page-1);
			}
			else if(op=="forward"){
				page=min((int)history.size()-1,page+1);
			}
		}
	}

	return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 0
final_rank: 1

code_snippet: #include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <complex>
#include <cstring>
#include <cstdlib>
#include <string>
#include <cmath>
#include <map>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
const int INF = 1<<29;

struct P {
  int x1,y1,x2,y2;
  string s;
  P(int x1,int y1,int x2,int y2, string s) : x1(x1),y1(y1),x2(x2),y2(y2),s(s) {}
};

int main() {
  int n;
  while(cin>>n,n) {
    int w,h;
    cin >> w>>h;
    string title[n];
    vector<P> button[n];;
    map<string, int> rid;
    REP(i,n) {
      cin >> title[i];
      rid[title[i]] = i;
      int m;
      cin >> m;
      REP(j,m) {
        int ax,ay,bx,by;
        cin>>ax>>ay>>bx>>by;
        string s;
        cin >> s;
        button[i].push_back(P(ax,ay,bx,by,s));
      }
    }
    int m;
    cin >> m;
    int now = 0;
    int page[100000] = {};
    int maxpage = 0;
    while(m--) {
      string s;
      cin >> s;
      if (s == "click") {
        int x, y;
        cin >> x >> y;
        FOR(it, button[page[now]]) {
          if (it->x1<=x && x<=it->x2 && it->y1<=y && y<=it->y2) {
            page[++now] = rid[it->s];
            maxpage = now;
            break;
          }
        }
      } else if (s == "show"){
        cout << title[page[now]] << endl;
      } else if (s == "back") {
        if (now>0)
          now--;
      } else if (s == "forward") {
        if (now<maxpage)
          now++;
      }
    }
  }
}
accuracy: 1
time_ms: 10
memory_kb: 0
final_rank: 1

code_snippet: #include <iostream>
#include <fstream>
#include <algorithm>
#include <cassert>
#include <cctype>
#include <complex>
#include <cstdio>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;

#define rep(i,n) for(int i=0;i<n;i++)

int n,W,H,a[100001],c,po,m;
struct page{
	int b,x1[100],y1[100],x2[100],y2[100];
	string name,link[100];
};

int main(){
	while(cin>>n&&n){
		fill(a,a+100001,-1);
		a[0]=0;c=0;po=0;
		cin>>W>>H;
		page p[100];
		rep(i,n){
			cin>>p[i].name>>p[i].b;
			rep(j,p[i].b)cin>>p[i].x1[j]>>p[i].y1[j]>>p[i].x2[j]>>p[i].y2[j]>>p[i].link[j];
		}
		cin>>m;
		rep(i,m){
			string s;
			cin>>s;
			if(s=="click"){
				int x,y;
				cin>>x>>y;
				rep(j,p[c].b)if(p[c].x1[j]<=x&&x<=p[c].x2[j]&&p[c].y1[j]<=y&&y<=p[c].y2[j]){
					string st=p[c].link[j];
					rep(k,n)if(st==p[k].name)c=(a[++po]=k);
					fill(a+po+1,a+100001,-1);
					break;
				}
			}
			if(s=="back"&&po)c=a[--po];
			if(s=="forward"&&a[po+1]!=-1)c=a[++po];
			if(s=="show")cout<<p[c].name<<endl;
		}
	}
}
accuracy: 1
time_ms: 50
memory_kb: 1504
final_rank: 16

code_snippet: #include <iostream>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <algorithm>	// require sort next_permutation count etc.
#include <cstdlib>	// require abs
#include <cstdio>	// require printf
#include <functional>
#include <numeric>	// require accumulate
#include <cmath>
#include <climits>
#include <limits>
#include <cfloat>
#include <iomanip>	// require setw
#include <sstream>	// require stringstream 
#include <cstring>	// require memset
#include <cctype>	// require tolower, toupper
#include <fstream>	// require freopen

using namespace std;

typedef pair<int, int> P;

struct BUTTON{
	P start, end;
	string link_name;
};	

struct PAGE{
	string name;
	int link_num;
	vector <BUTTON> link;
};		
	

int main()
{
	const string action[] = { "click", "show", "back", "forward" };
//	cut here before submit 
//	freopen ("testcase.distortedlove", "r", stdin );
	int n;

	while (cin >> n && n ){
		int W, H;
		cin >> W >> H;
		vector<PAGE> page(n);

		for (int i = 0; i < n; ++i ){
			int num = 0;
			cin >> page[i].name >> num;
			page[i].link_num = num;
			page[i].link.resize(num );
			for (int j = 0; j < num; ++j ){
				cin >> page[i].link[j].start.first;
				cin >> page[i].link[j].start.second;
				cin >> page[i].link[j].end.first;
				cin >> page[i].link[j].end.second;
				cin >> page[i].link[j].link_name;
			} // end for
		} // end for

		vector <int> buffer (10500, -1 );
		int curr_page = 0;	// ツ個サツ催敖づ個ペツーツジ
		int pointer = 0;
		buffer[pointer] = curr_page;
		int m;
		cin >> m;

		for (int i = 0; i < m; ++i ){
			string com = "";
			cin >> com;
			int cw, ch;
			if (com == action[0] ){	// "click"
				cin >> cw >> ch;
				int curr = buffer[pointer];
				string next_page = "";	
				for (int j = 0; j < page[curr].link_num; ++j ){
					if ( page[curr].link[j].start.first <= cw 
					&&   cw <= page[curr].link[j].end.first
					&&   page[curr].link[j].start.second <= ch 
					&& ch <= page[curr].link[j].end.second ){
						next_page = page[curr].link[j].link_name;
						break;
					} // end if
				} // end for
				if (!next_page.empty() ){
					for (int j = pointer + 1; j < buffer.size(); ++j ){
						buffer[j] = -1;
					} // end for
					for (int j = 0; j < n; ++j ){
						if (next_page == page[j].name ){
							++pointer;
							buffer[pointer] = j;
							break;
						} // end fi
					} // end for
				} // end if
			}else
			if (com == action[1] ){	// "show"
				cout << page[buffer[pointer]].name << endl;
			}else
			if (com == action[2] ){	// "back"
				if (pointer > 0 ){
					--pointer;
				} // end if
			}else{				// "forward"
				if (buffer[pointer+1] != -1 ){
					++pointer;
				} // end if
			} // end if
		} // end for
	} // end loop
		
	return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 0
final_rank: 1

code_snippet: #include<iostream>
#include<string>
#include<vector>
#include<map>
using namespace std;
struct S{int x1,x2,y1,y2;string s;}_;
int main()
{
	int n,m,b,h,w,i,j,x,y;
	string s;
	while(cin>>n>>w>>h)
	{
		map<string,vector<S> >M;
		vector<string> V;
		vector<string>::iterator ite;
		for(i=0;i<n;++i)
		{
			cin>>s>>b;
			if(!i)V.push_back(s);
			for(j=0;j<b;++j)cin>>_.x1>>_.y1>>_.x2>>_.y2>>_.s, M[s].push_back(_);
		}
		cin>>m;
		ite=V.begin();
		for(i=0;i<m;++i)
		{
			cin>>s;
			if(s=="click")
			{
				cin>>x>>y;for(j=0;j<M[*ite].size();++j)
				{
					_=M[*ite][j];
					if(x>=_.x1&&x<=_.x2&&y>=_.y1&&y<=_.y2)
					{	V.erase(ite+1,V.end());
						V.push_back(_.s);
						ite=V.end()-1;
						break;
					}
				}
			}
			if(s=="back") if(ite!=V.begin())--ite;
			if(s=="forward") if(ite!=V.end()-1)++ite;
			if(s=="show") cout<<*ite<<endl;
		}
	}
	return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 0
final_rank: 1

code_snippet: #include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstring>
using namespace std;
static const double EPS = 1e-5;
typedef long long ll;

typedef struct _button{
	int xl,yu,xr,yl;
	string name;
}button;


map<string, vector<button> > page;
vector<string> rireki;


main(){
	int n;
	while(cin>>n){
		if(n==0)break;
		
		page.clear();
		rireki.clear();
		
		int W,H;
		cin>>W>>H;
		
		for(int i=0;i<n;i++){
			string name;
			int b;
			cin>>name>>b;
			if(i==0)rireki.push_back(name);
			for(int j=0;j<b;j++){
				int xl,xr,yu,yl;
				string tname;
				cin>>xl>>yu>>xr>>yl>>tname;
				button tbutton={xl,yu,xr,yl,tname};
				
				page[name].push_back(tbutton);
			}
		}
		
		int m;
		cin>>m;
		int p=0;
		
		for(int i=0;i<m;i++){
			string com;
			cin>>com;
			if(com=="click"){
				
				int x,y;
				cin>>x>>y;
				
				string target="";
				
				for(vector<button>::iterator vp=page[rireki[p]].begin();vp!=page[rireki[p]].end();++vp){
					if(vp->xr>=x && vp->xl<=x && vp->yu<=y && vp->yl>=y)target=vp->name;
				}
				
				if(target=="")continue;
				
				if(p==rireki.size()-1){
					rireki.push_back(target);
					++p;
					
					
				}else{
					++p;
					rireki[p]=target;
					while(p+1<rireki.size())rireki.pop_back();
				}
				
				
			}else if(com=="show"){
				cout<<rireki[p]<<endl;
			}else if(com=="back"){
				if(p)--p;
			}else if(com=="forward"){
				if(p<rireki.size()-1)++p;
			}
		}
		
	}
}
accuracy: 1
time_ms: 10
memory_kb: 0
final_rank: 1

code_snippet: #include<map>
#include<deque>
#include<string>
#include<vector>
#include<iostream>

#define	pb	push_back

using namespace std;

struct Rect{
	int l,r,u,b;
	bool isInside(int x,int y){
		return (l<=x && x<=r && u<=y && y<=b);
	}
};

struct Button:Rect{
	string link;
};

struct Page{
	string title;
	int bnum;
	vector<Button> btn;
};

int main(){
	for(int n;cin>>n,n;){
		int w,h;	cin>>w>>h;
		Page pg[100];
		for(int i=0;i<n;i++){
			cin>>pg[i].title>>pg[i].bnum;
			pg[i].btn=vector<Button>(pg[i].bnum);
			for(int j=0;j<pg[i].bnum;j++){
				cin>>pg[i].btn[j].l>>pg[i].btn[j].u
				   >>pg[i].btn[j].r>>pg[i].btn[j].b>>pg[i].btn[j].link;
			}
		}

		map<string,int> f;
		for(int i=0;i<n;i++)	f[pg[i].title]=i;

		int m;	cin>>m;
		deque<Page> dq;	dq.pb(pg[0]);
		int ptr=0;
		while(m--){
			string cmd;	cin>>cmd;
			if(cmd=="click"){
				int x,y;	cin>>x>>y;
				int on=-1;
				for(int i=0;i<dq[ptr].bnum;i++){
					if(dq[ptr].btn[i].isInside(x,y)){
						on=f[dq[ptr].btn[i].link];
						break;
					}
				}
				if(~on){
					dq.erase(dq.begin()+ptr+1,dq.end());
					dq.pb(pg[on]);
					ptr++;
				}
			}
			else if(cmd=="back"){
				if(ptr>0)	ptr--;
			}
			else if(cmd=="forward"){
				if(ptr<dq.size()-1)	ptr++;
			}
			else	cout<<dq[ptr].title<<endl;
		}
	}

	return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 0
final_rank: 1

code_snippet: #include <iostream>
#include <vector>
#include <map>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)

struct B{int x1,y1,x2,y2;string name;};
int W,H,n;

struct SITE{
	string myname;
	vector<B> co;
};

int pos;
map<string,int> to;
vector<SITE>info;

vector< vector<SITE>::iterator > lst;
vector<SITE>::iterator cur;


vector<SITE>::iterator find(string name){
	int lp = to[name];
	vector<SITE>::iterator it = info.begin();
	rep(i,lp){++it;}
	return it;
}

void move(string name){
	vector< vector<SITE>::iterator > newList;
	rep(i,pos+1){
		newList.push_back(lst[i]);
	}
	lst = newList;

	lst.push_back(find(name));
	cur = lst.back();
	pos = lst.size()-1;
}

main(){

	while(cin >> n , n ){
		to.clear();
		info.clear(),info.resize(n);
		cin >> W >> H;
		rep(i,n){
			string s;int d;
			cin >> s >> d;
			to[s] = i;
			
			info[i].myname = s;
			
			rep(j,d){
				B t;
				cin >> t.x1 >> t.y1 >> t.x2 >> t.y2 >> t.name;	
				info[i].co.push_back(t);
			}
			
		}
		
		int m;

		lst.clear();		
		lst.push_back(info.begin());
		cur = info.begin();
		pos = 0;
		
		cin >> m;
		
		rep(i,m){
			string s; cin >> s;
			if( s == "click" ){	
				int x,y;
				cin >> x >> y;
				SITE t= *cur;
				rep(i,t.co.size()){
					if(t.co[i].x1 <= x && x <= t.co[i].x2 &&
					   t.co[i].y1 <= y && y <= t.co[i].y2
					){
						move(  t.co[i].name );	
					}
				}
			}
			if( s == "show"){
				cout << (*cur).myname << endl;
			}
			
			if( s == "back"){
				if(pos==0)continue;
				
				pos--;
				cur = lst[pos];
			}
			
			if( s == "forward"){
				if(pos == lst.size()-1)continue;
				pos++;
				cur = lst[pos];
			}
			
		}
	}
}
accuracy: 1
time_ms: 10
memory_kb: 0
final_rank: 1

code_snippet: #include <iostream>
#include <fstream>
#include <sstream>
#include <iomanip>
#include <complex>
#include <string>
#include <vector>
#include <list>
#include <deque>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <bitset>
#include <functional>
#include <utility>
#include <algorithm>
#include <numeric>
#include <typeinfo>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <ctime>

using namespace std;

#define dump(n) cout<<"# "<<#n<<"="<<(n)<<endl
#define debug(n) cout<<__FILE__<<","<<__LINE__<<": #"<<#n<<"="<<(n)<<endl
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,n) repi(i,0,n)
#define iter(c) __typeof((c).begin())
#define foreach(i,c) for(iter(c) i=(c).begin();i!=(c).end();i++)
#define allof(c) (c).begin(),(c).end()
#define mp make_pair

typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int,int> pii;

struct Button{
	string name;
	int x1,y1,x2,y2;
	Button(){}
	Button(string name,int x1,int y1,int x2,int y2):name(name),x1(x1),y1(y1),x2(x2),y2(y2){}
};

struct Page{
	string name;
	vector<Button> buttons;
	Page(){}
	Page(string name):name(name){}
};

bool input(vector<Page>& pages,vs& cmds)
{
	int n;
	cin>>n;
	if(!n)
		return false;
	
	pages.resize(n);
	int h,w;
	cin>>h>>w;
	rep(i,n){
		string name;
		cin>>pages[i].name;
		int b;
		cin>>b;
		rep(j,b){
			int x1,y1,x2,y2;
			string name;
			cin>>x1>>y1>>x2>>y2>>name;
			pages[i].buttons.push_back(Button(name,x1,y1,x2,y2));
		}
	}
	int m;
	cin>>m;
	cmds.resize(m);
	cin.get();
	rep(i,m)
		getline(cin,cmds[i]);
	
	return true;
}

bool clicked(const Button& b,int x,int y)
{
	//printf("%d %d %d %d (%d,%d)\n",b.x1,b.y1,b.x2,b.y2,x,y);
	//dump(b.x1<=x && x<=b.x2 && b.y1<=y && y<=b.y2);
	return b.x1<=x && x<=b.x2 && b.y1<=y && y<=b.y2;
}

void solve(vector<Page>& pages,vs& cmds)
{
	map<string,int> nameToId;
	rep(i,pages.size())
		nameToId[pages[i].name]=i;
	
	vi buffer(1,0);
	int pos=0;
	rep(i,cmds.size()){
		if(cmds[i].substr(0,4)=="show")
			//dump(pages[buffer[pos]].name);
			cout<<pages[buffer[pos]].name<<endl;
		if(cmds[i].substr(0,4)=="back")
			pos=max(pos-1,0);
		if(cmds[i].substr(0,7)=="forward")
			pos=min(pos+1,(int)buffer.size()-1);
		if(cmds[i].substr(0,5)=="click"){
			buffer.resize(pos+1);
			istringstream iss(cmds[i].substr(5));
			int x,y;
			iss>>x>>y;
			Page& page=pages[buffer[pos]];
			rep(j,page.buttons.size()){
				if(clicked(page.buttons[j],x,y)){
					buffer.push_back(nameToId[page.buttons[j].name]);
					pos++;
				}
			}
		}
		//dump(pos);
	}
}

int main()
{
	for(;;){
		vector<Page> pages;
		vs cmds;
		if(!input(pages,cmds))
			break;
		solve(pages,cmds);
		//puts("--");
		//rep(i,pages.size()){
		//	dump(pages[i].name);
		//	rep(j,pages[i].buttons.size()){
		//		Button& b=pages[i].buttons[j];
		//		printf("%s %d %d %d %d\n",b.name.c_str(),b.x,b.y,b.w,b.h);
		//	}
		//}
		//rep(i,cmds.size())
		//	dump(cmds[i]);
	}
	
	return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 0
final_rank: 1