#include "popa.h"
#include<bits/stdc++.h>
using namespace std;
map<pair<pair<int,int>,pair<int,int>>,int> mp;
int myquery(int a, int b, int c, int d)
{
int na=min(a,b),nb=max(a,b),nc=min(c,d),nd=max(c,d);
if(mp[{{a,b},{c,d}}]==0) mp[{{a,b},{c,d}}] = query(na,nb,nc,nd)+1;
return mp[{{a,b},{c,d}}]-1;
}
vector<int> ord;
void precalc(int limle[1005])
{
limle[ord[0]]=0;
for(int i=1;i<ord.size();i++)
{
if(myquery(ord[i-1],ord[i],ord[i],ord[i]))
{
limle[ord[i]] = limle[ord[i-1]];
while(limle[ord[i]]>0 && myquery(ord[limle[ord[i]]-1],ord[i],ord[i],ord[i]))
limle[ord[i]]--;
}
else
{
limle[ord[i]] = i;
}
}
for(int i=0;i<ord.size();i++)
limle[i] = ord[limle[i]];
}
int tole[1005],tori[1005];
int limle[1005],limri[1005];
int calc(int le, int ri)
{
if(le>ri)
return -1;
if(le==ri)
{
tole[le]=tori[le]=-1;
return le;
}
for(int root=le;root<=ri;root++)
{
if(limle[root]<=le && limri[root]>=ri)
{
tole[root] = calc(le,root-1);
tori[root] = calc(root+1,ri);
return root;
}
}
return -5;
}
int solve(int N, int* Left, int* Right)
{
mp.clear();
ord.clear();
for(int i=0;i<N;i++)
ord.push_back(i);
precalc(limle);
reverse(ord.begin(),ord.end());
precalc(limri);
//for(int i=0;i<N;i++) cout<<i<<" "<<limle[i]<<" "<<limri[i]<<" lim\n";
for(int i=0;i<N;i++)
tole[i]=tori[i]=-1;
int root = calc(0,N-1);
for(int i=0;i<N;i++)
{
Left[i]=tole[i];
Right[i]=tori[i];
}
return root;
}
Compilation message
popa.cpp: In function 'void precalc(int*)':
popa.cpp:15:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
15 | for(int i=1;i<ord.size();i++)
| ~^~~~~~~~~~~
popa.cpp:28:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
28 | for(int i=0;i<ord.size();i++)
| ~^~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
13 ms |
696 KB |
Output is correct |
2 |
Correct |
12 ms |
716 KB |
Output is correct |
3 |
Correct |
18 ms |
724 KB |
Output is correct |
4 |
Correct |
13 ms |
1468 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
193 ms |
1944 KB |
Output is correct |
2 |
Correct |
135 ms |
1700 KB |
Output is correct |
3 |
Correct |
143 ms |
2000 KB |
Output is correct |
4 |
Correct |
228 ms |
1992 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
12 ms |
1240 KB |
too many queries |
2 |
Halted |
0 ms |
0 KB |
- |