This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
const int oo = INT_MAX;
const int nmax = 150000;
int n,m;
int p[nmax + 5][3], l[nmax + 5][3], r[nmax + 5][3];
pair<int,int> poz[nmax + 5];
void Add(int nr)
{
for(int i=1; i<=n; i++)
{
for(int j=1; j<=2; j++)
{
if(p[i][j])
{
l[i][j] = i;
}
else
{
l[i][j] = l[i - 1][j];
}
}
}
for(int i=n; i>=1; i--)
{
for(int j=1; j<=2; j++)
{
if(p[i][j])
{
r[i][j] = i;
}
else
{
r[i][j] = r[i + 1][j];
}
}
}
int val = 0;
int lin = 0, col = 0;
for(int i=1; i<=n; i++)
{
for(int j=1;j<=2;j++)
{
if(p[i][j])
{
continue;
}
int dist = oo;
for(int lj=1;lj<=2;lj++)
{
if(l[i][lj])
{
dist = min(dist, (i - l[i][lj]) * (i - l[i][lj]) + abs(j - lj));
}
if(r[i][lj])
{
dist = min(dist, (r[i][lj] - i) * (r[i][lj] - i) + abs(j - lj));
}
}
if(dist > val)
{
val = dist;
lin = i;
col = j;
}
}
}
p[lin][col] = nr;
poz[nr] = {lin,col};
cout<<lin<<' '<<col<<'\n';
}
void Remove(int nr)
{
int lin = poz[nr].first;
int col = poz[nr].second;
p[lin][col] = 0;
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
#ifdef home
freopen("nr.in","r",stdin);
freopen("nr.out","w",stdout);
#endif // home
cin>>n>>m;
for(int i=1; i<=m; i++)
{
char tip;
cin>>tip;
if(tip=='E')
{
Add(i);
}
else
{
int nr = 0;
cin>>nr;
Remove(nr);
}
}
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... |