1 solutions

  • 0
    @ 2025-12-27 18:09:56
    #include<bits/stdc++.h>
    using namespace std;
    int n,q,p,op,x,y;
    char c;
    deque<pair<int,int> >dq;
    int main()
    {
    	cin>>n>>q;
    	for(int i=1;i<=n;i++)
    	{
    		dq.push_back({i,0});
    	}
    	while(q--)
    	{
    		cin>>op;
    		if(op==1)
    		{
    			cin>>c;
    			x=dq.front().first,y=dq.front().second;
    			if(c=='R')
    			{
    				x++;
    			}
    			if(c=='L')
    			{
    				x--;
    			}
    			if(c=='U')
    			{
    				y++;
    			}
    			if(c=='D')
    			{
    				y--;
    			}
    			dq.push_front({x,y});
    			dq.pop_back();
    		}
    		else
    		{
    			cin>>p;
    			cout<<dq[p-1].first<<" "<<dq[p-1].second<<"\n";
    		}
    	}
    	return 0;
    }
    

    Information

    ID
    2730
    Time
    1000ms
    Memory
    256MiB
    Difficulty
    10
    Tags
    # Submissions
    3
    Accepted
    3
    Uploaded By