#include "molecules.h"
#include <iostream>
using namespace std;
long long int a[1000005],tree[1000005],c,d;
long long int buildtree(int l,int r,int t)
{
if(l==r)return tree[t]=a[l];
return tree[t]=buildtree(l,(l+r)/2,t*2)+buildtree((l+r)/2+1,r,t*2+1);
}
long long int findtree(int l,int r,int t)
{
//cout<<l<<" "<<r<<" "<<t<<" "<<c<<" "<<d<<endl;
if(d<l || c>r)return 0;
if(c<=l && r<=d)return tree[t];
return findtree(l,(l+r)/2,t*2)+findtree((l+r)/2+1,r,t*2+1);
}
long long int qs(int s,int e)
{
if(s==e)return 0;
int l=s,r=e,mid=(a[l]+a[r])/2;
while(l<=r)
{
while(a[l]<mid)l++;
while(a[r]>mid)r--;
if(l<=r)
{
swap(a[l],a[r]);
l++;
r--;
}
}
qs(s,r);
qs(l,e);
}
std::vector<int> find_subset(int l, int u, std::vector<int> w) {
long long int n=w.size();
for(int i=0;i<n;i++)a[i]=w[i];
int mi,ma;
qs(1,n);
buildtree(0,n-1,1);
long long int sum=0;
for(int i=1;i<=n;i++)
{
int s=i,e=n-1;
while(s<=e)
{
long long int mid=(s+e)/2;
c=mid-i+1,d=mid;
//cout<<c<<" "<<d<<endl;
long long int sum=findtree(0,n-1,1);
//cout<<sum<<endl;
if(l<=sum && sum<=u)
{
long long int m=d-c+1;
vector<int> ans(m);
for(int j=c;j<=d;j++)ans[j-c]=j;
return ans;
}
if(sum<l)s=mid+1;
else e=mid-1;
}
}
vector<int> ans;
return ans;
}
Compilation message
molecules.cpp: In function 'std::vector<int> find_subset(int, int, std::vector<int>)':
molecules.cpp:38:6: warning: unused variable 'mi' [-Wunused-variable]
int mi,ma;
^~
molecules.cpp:38:9: warning: unused variable 'ma' [-Wunused-variable]
int mi,ma;
^~
molecules.cpp:41:16: warning: unused variable 'sum' [-Wunused-variable]
long long int sum=0;
^~~
molecules.cpp: In function 'long long int qs(int, int)':
molecules.cpp:34:1: warning: control reaches end of non-void function [-Wreturn-type]
}
^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
OK (n = 1, answer = NO) |
2 |
Correct |
2 ms |
376 KB |
OK (n = 1, answer = NO) |
3 |
Incorrect |
2 ms |
376 KB |
Contestant can not find answer, jury can |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
OK (n = 12, answer = YES) |
2 |
Correct |
2 ms |
376 KB |
OK (n = 12, answer = YES) |
3 |
Correct |
2 ms |
376 KB |
OK (n = 12, answer = NO) |
4 |
Correct |
2 ms |
376 KB |
OK (n = 12, answer = NO) |
5 |
Incorrect |
2 ms |
376 KB |
Contestant can not find answer, jury can |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
OK (n = 1, answer = NO) |
2 |
Correct |
2 ms |
376 KB |
OK (n = 1, answer = NO) |
3 |
Incorrect |
2 ms |
376 KB |
Contestant can not find answer, jury can |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
OK (n = 1, answer = NO) |
2 |
Correct |
2 ms |
376 KB |
OK (n = 1, answer = NO) |
3 |
Incorrect |
2 ms |
376 KB |
Contestant can not find answer, jury can |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
OK (n = 1, answer = NO) |
2 |
Correct |
2 ms |
376 KB |
OK (n = 1, answer = NO) |
3 |
Incorrect |
2 ms |
376 KB |
Contestant can not find answer, jury can |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
OK (n = 1, answer = NO) |
2 |
Correct |
2 ms |
376 KB |
OK (n = 1, answer = NO) |
3 |
Incorrect |
2 ms |
376 KB |
Contestant can not find answer, jury can |
4 |
Halted |
0 ms |
0 KB |
- |