//#include "arithmetics.h"
//```// YF YUSUF
#define Free_open(File) freopen((File".in"),"r",stdin);freopen((File".out"),"w",stdout);
#define YF ios_base::sync_with_stdio(0);cout.setf(ios::fixed);
#define YUSUF cout.precision(0);cout.tie(0);cin.tie(0);
#include <bits/stdc++.h>
using namespace std;
#ifdef YF_CHECK
bool Output=1;
// #include "g/debug.h"
//#include "g/bigint.h"
//#include "g/text.h"
#else
bool Output=0;
#define deb(x...) 42
#endif
using ll = long long;
//using ld = long double;
using vll = vector <ll>;
using mll = map <ll,ll>;
using pll = pair <ll,ll>;
using vpll= vector <pll>;
template<class T>T MIN(T&a,T b){a=min(a,b);return a;}
template<class T>T MAX(T&a,T b){a=max(a,b);return a;}
#define revers(a) reverse(all(a))
#define all(a) a.begin(),a.end()
#define sortt(a) sort(all(a))
#define sgr v+v+1,tm+1,tr
#define sgl v+v,tl,tm
#define pb push_back
#define ins insert
#define S second
#define F first
#define int ll
ll BP(ll a,ll b,ll mod=1e9+7){
if(b==0)return 1;
ll q=BP(a,b/2,mod);
return ((q*q)%mod*(b%2?a:1ll))%mod;
}
ll lcm(ll a,ll b){return a/__gcd(a,b)*b;}
ll dup(ll a,ll b){return (a+b-1)/b;}
ll f(ll x){return x*(x+1)/2;}
const int mod=998244353;
const int INF=1e18+7;
const int inf=1e9+7;
const int N =1e6+7;
ll r,c,q;
bool check(pll A,pll B){
auto [a,b]=A;
auto [c,d]=B;
if(a-c==b-d||c-a==d-b||-(a-c)==b-d||-(c-a)==d-b)return 1;
return 0;
}
pll PP(ll x,ll y){
if(x!=y)return {0,0};
return {r-1,1};
}
ll dfs(ll u,ll x,ll y,char dir,ll ans=1){
if(u>=r && x==y)
return ans;
else if(x==1)
return dfs(u+1,x+1,y,'R',ans+1);
else if(x==c)
return dfs(u+1,x-1,y,'L',ans+1);
else if(dir=='L')
return dfs(u+1,x-1,y,'L',ans);
else
return dfs(u+1,x+1,y,'R',ans);
}
pll BB(ll x,ll y){
if(!((1+x)%2==(r+y)%2))return {0,0};
ll a,b;
if(x>1)
a=dfs(2,x-1,y,'L');
if(x<c)
b=dfs(2,x+1,y,'R');
if(a==b)return {a,2};
else return {min(a,b),1};
if(abs(y-x)==r-1)return {1,1};
ll l=1,R=1e9,ans1=1e9,ans2=ans1;
while(l<=R){
ll m=(l+R)/2;
ll f=max(x-1,c-x)+1;
ll s=(m-1)*(c-1);
// if(m<=10)cout<<f<<" "<<s<<" "<<s+f<<" "<<r<<" : "<<m<<" : "<<l<<" "<<R<<" : " <<"";
if(s+f>=r){
ans1=m;
R=m-1;
}
else{
l=m+1;
}
// if(m<=10)cout<<l<<" "<<R<<"\n";
}
l=1;R=1e9;
while(l<=R){
ll m=(l+R)/2;
ll f=min(x-1,c-x)+1;
ll s=(m-1)*(c-1);
if(s+f>=r){
ans2=m;
R=m-1;
}
else{
l=m+1;
}
}
// cout<<"ans1 "<<ans1<<" : "<<max(x-1,c-x)+1<<" "<<(ans1-1)*(c-1)<<"\n";
// cout<<"ans1 "<<ans1<<" : "<<max(x-1,c-x)+1<<" "<<(ans1)*(c-1)<<"\n";
// cout<<"ans2 "<<ans2<<" : "<<min(x-1,c-x)+1<<" "<<(ans2-1)*(c-1)<<"\n";
// cout<<"ans2 "<<ans2<<" : "<<min(x-1,c-x)+1<<" "<<(ans2)*(c-1)<<"\n";
ll posx=0;
ll posy=0;
if(x-1>c-x){
posx=x+(c-1)*(ans1-1);
if(ans1%2) posy=1;
else posy=c;
}
else{
posx=c-x+1+(c-1)*(ans1-1);
if(ans1%2==0) posy=1;
else posy=c;
}
if(posx-abs(posy-y)<r)ans1++;
if(x-1<c-x){
posx=x+(c-1)*(ans1-1);
if(ans1%2) posy=1;
else posy=c;
}
else{
posx=c-x+1+(c-1)*(ans1-1);
if(ans1%2==0) posy=1;
else posy=c;
}
if(posx-abs(posy-y)<r)ans2++;
// cout<<ans1<<" "<<ans2<<" : \n";
if(ans1==ans2){
return {ans1,2};
}
else{
return {ans1,1};
}
}
pll RR(ll x,ll y){
if(x==y)return {1,1};
else return {2,2};
}
pll KK(ll x,ll y){
return {r-1,393};
}
pll QQ(ll x,ll y){
if(x==y || abs(y-x)==r-1)return {1,1};
else{
pll R=RR(x,y);
pll B=BB(x,y);
// cout<<R.F<<" "<<R.S<<" : "<<B.F<<" "<<B.S<<"\n";
return {R.F,R.S+2+(B.F==R.S)*(B.S)};
}
}
void YF_MAIN(ll TEST){
cin>>c>>r>>q;
while(q--){
char troop;ll x,y;
cin>>troop>>x>>y;
pll ans;
if(troop=='P')ans=PP(x,y);
if(troop=='B')ans=BB(x,y);
if(troop=='K')ans=KK(x,y);
if(troop=='R')ans=RR(x,y);
if(troop=='Q')ans=QQ(x,y);
cout<<ans.F<<" "<<ans.S<<"\n";
}
}
bool TECT=0;
bool CASE=0;
bool OUTP=1;
//ll FACT[N],inv[N],FMOD=1e9+7;
//ll PER(ll n,ll k){return FACT[n] *inv[n-k]%FMOD;}
//ll CNK(ll n,ll k){return PER(n,k)*inv[k ]%FMOD;}
//ll lg[N];
void BEFORE(){
return;
// for(int i=2;i<=200000;i++){
// lg[i]=lg[i/2]+1;
// }
// FACT[0]=inv[0]=1;
// for(int i=1;i<=1e5;i++){
// FACT[i]=FACT[i-1]*i%FMOD;
// inv[i]=BP(FACT[i],FMOD-2,FMOD);
// }
}
signed main(){
if(OUTP){YF YUSUF}
// Free_open("TEST");
cout<<(Output ? "\nYF_OUTPUT:\n\n" : "");
int TEST=1;
if(TECT)
cin>>TEST;
BEFORE();
for(int T=1;T<=TEST;T++){
if(CASE)
cout<<"Case "<<T<<": ";
YF_MAIN(T);
cout<<(T==TEST ? "" : "\n");
}
return 0;
}
//```
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |