# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1229908 | MuhammadSaram | popa (BOI18_popa) | C++20 | 0 ms | 0 KiB |
// #include "popa.h"
#include <bits/stdc++.h>
using namespace std;
const int M = 1001;
int pr[M], nx[M];
int solve(int n,int* l,int* r)
{
for (int i=0;i<n;i++)
{
int s=i,e=n;
while (s+1<e)
{
int mid=(s+e)/2;
if (query(i,i,i,mid))
s=mid;
else
e=mid;
}
nx[i]=s;
s=-1,e=i;
while (s+1<e)
{
int mid=(s+e)/2;
if (query(i,i,mid,i))
e=mid;
else
s=mid;
}
pr[i]=e;
}
map<pair<int,int>,int> mp;
queue<pair<int,int>> q;
q.push({0,n-1});
while (!q.empty())
{
pair<int,int> p=q.front();q.pop();
for (int i=p.first;i<=p.second;i++)
if (pr[i]<=p.first && nx[i]>=p.second)
{
mp[p]=i;
if (i>p.first) q.push({p.first,i-1});
if (i<p.second) q.push({i+1,p.second});
}
}
q.push({0,n-1});
while (!q.empty())
{
pair<int,int> p=q.front();q.pop();
int u=mp[p];
if (u>p.first) l[u]=mp[{p.first,u-1}],q.push({p.first,u-1});
else l[u]=-1;
if (u<p.second) r[u]=mp[{u+1,p.second}],q.push({u+1,p.second});
else r[u]=-1;
}
return mp[{0,n-1}];
}