# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
74121 |
2018-08-30T06:52:32 Z |
zscoder |
popa (BOI18_popa) |
C++17 |
|
181 ms |
788 KB |
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include "popa.h"
using namespace std;
using namespace __gnu_pbds;
#define fi first
#define se second
#define mp make_pair
#define pb push_back
typedef long long ll;
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef long double ld;
typedef tree<ii, null_type, less<ii>, rb_tree_tag, tree_order_statistics_node_update> pbds;
/*
int secret[1111];
int query(int a, int b, int c, int d)
{
int gd1=secret[a]; int gd2=secret[c];
for(int i=a;i<=b;i++) gd1=__gcd(gd1,secret[i]);
for(int i=c;i<=d;i++) gd2=__gcd(gd2,secret[i]);
return (gd1==gd2);
}
*/
int ansL[1111];
int ansR[1111];
int recurse(int l, int r) //returns root;
{
if(l>r) return -1;
if(l==r) return l;
int lo = l; int hi = r-1;
int ans = r;
while(lo<=hi)
{
int mid=(lo+hi)>>1;
if(query(l,mid,l,r))
{
ans=mid; hi=mid-1;
}
else lo=mid+1;
}
int rtl = recurse(l,ans-1);
int rtr = recurse(ans+1,r);
ansL[ans] = rtl; ansR[ans] = rtr;
return ans;
}
int solve(int n, int *L, int *R)
{
for(int i=0;i<n;i++) ansL[i]=ansR[i]=-1;
int rt = recurse(0,n-1);
for(int i=0;i<n;i++)
{
L[i] = ansL[i]; R[i] = ansR[i];
}
return rt;
}
/*
int n;
void read_input()
{
cin>>n;
for(int i=0;i<n;i++)
{
cin>>secret[i];
}
}
int secretL[1111];
int secretR[1111];
void process_case()
{
read_input();
int rt = solve(n, secretL, secretR);
cerr<<"ROOT : "<<secret[rt]<<'\n';
for(int i=0;i<n;i++)
{
cerr<<secret[i]<<' '<<(secretL[i]==-1?-1:secret[secretL[i]])<<' '<<(secretR[i]==-1?-1:secret[secretR[i]])<<'\n';
}
}
int main()
{
ios_base::sync_with_stdio(0); cin.tie(0);
process_case();
}
*/
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
15 ms |
248 KB |
Output is correct |
2 |
Correct |
18 ms |
452 KB |
Output is correct |
3 |
Correct |
10 ms |
452 KB |
Output is correct |
4 |
Correct |
18 ms |
452 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
181 ms |
560 KB |
Output is correct |
2 |
Correct |
175 ms |
560 KB |
Output is correct |
3 |
Correct |
95 ms |
576 KB |
Output is correct |
4 |
Correct |
156 ms |
788 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
51 ms |
788 KB |
too many queries |
2 |
Halted |
0 ms |
0 KB |
- |