Pagini recente » Cod sursa (job #879793) | Cod sursa (job #79273) | Cod sursa (job #1707803) | Cod sursa (job #1226811) | Cod sursa (job #541820)
Cod sursa(job #541820)
#include<algorithm>
using namespace std;
#include<vector>
#define DIM 100005
#define DIMbuff 1234
#define pb push_back
#define mp make_pair
#define fs first
#define sc second
int n,m,w[4][DIM],poz;
vector <pair <int,int> > a[DIM];
char buff[DIMbuff];
inline void pars (int &nr)
{
nr=0;
while(buff[poz]<'0' || buff[poz]>'9')
if(++poz==DIMbuff)
fread(buff,1,DIMbuff,stdin),poz=0;
while(buff[poz]>='0' && buff[poz]<='9')
{
nr=nr*10+buff[poz]-'0';
if(++poz==DIMbuff)
fread(buff,1,DIMbuff,stdin),poz=0;
}
}
int main ()
{
freopen("walls.in","r",stdin);
freopen("walls.out","w",stdout);
int i,x,y,*aux,wall,j,adanc;
bool gasit;
pars(n);
for(i=1;i<=n;++i)
{
pars(w[1][i]);
pars(w[2][i]);
if(i==1)
w[3][1]=w[1][1];
else
w[3][i]=w[3][i-1]+1+w[1][i];
}
pars(m);
for(i=1;i<=m;++i)
{
pars(x);
pars(y);
aux=lower_bound (1+w[3],1+w[3]+n,x);
wall=int(aux-w[3]-1);
while(w[2][wall]<y && wall>-1)
--wall;
if(wall==-1)
printf("MISS\n");
else
{
gasit=false;
adanc=1;
for(j=0;j<a[wall].size ();++j)
if(a[wall][j].fs==y)
{
adanc=++a[wall][j].sc;
gasit=true;break;
}
if(gasit==false)
a[wall].pb (mp (y,1));
printf("HIT %d %d ",w[3][wall]-adanc+1,wall);
if(adanc==w[1][wall])
{
w[2][wall]=y-1;
printf("YES\n");
}
else
printf("NO\n");
}
}
return 0;
}