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>
#include "molecules.h"
#define inf 1000000007
#define mod 1000000007
#define rnd() rand_num()
#define bigrnd() dis(rand_num)
//#pragma GCC optimize("Ofast","inline","-ffast-math")
//#pragma GCC target("avx,sse2,sse3,sse4,mmx")
//#define int long long
using namespace std;
unsigned sed=std::chrono::system_clock::now().time_since_epoch().count();
mt19937 rand_num(sed);
uniform_int_distribution<long long> dis(0,inf);
template <typename T> void read(T &x){
x=0;char ch=getchar();int fh=1;
while (ch<'0'||ch>'9'){if (ch=='-')fh=-1;ch=getchar();}
while (ch>='0'&&ch<='9')x=x*10+ch-'0',ch=getchar();
x*=fh;
}
template <typename T> void write(T x) {
if (x<0) x=-x,putchar('-');
if (x>9) write(x/10);
putchar(x%10+'0');
}
template <typename T> void writeln(T x) {
write(x);
puts("");
}
int n;
pair<int,int> p[200005];
int sum[200005];
vector<int> find_subset(int L,int R,vector<int> w)
{
n=w.size();
for(int i=1;i<=n;++i)
{
p[i].first=w[i-1];
p[i].second=i-1;
}
sort(p+1,p+n+1);
for(int i=1;i<=n;++i)
sum[i]=sum[i-1]+p[i].first;
for(int i=1;i<=n;++i)
{
int l=i,r=n;
while(l<r)
{
int mid=l+r>>1;
int val=sum[mid]-sum[i-1];
if(val>=L) r=mid;
else l=mid+1;
}
int val=sum[l]-sum[i-1];
if(val>=L&&val<=R)
{
vector<int> ans;
for(int j=i;j<=l;++j)
ans.push_back(p[j].second);
return ans;
}
}
vector<int> ans;
return ans;
}
Compilation message (stderr)
molecules.cpp: In function 'std::vector<int> find_subset(int, int, std::vector<int>)':
molecules.cpp:48:13: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
48 | int mid=l+r>>1;
| ~^~
# | 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... |