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 "molecules.h"
#include <bits/stdc++.h>
typedef long long ll;
#define mp make_pair
#define F first
#define S second
using namespace std;
using pii = pair<int,int>;
const int N = 2e5 + 5;
pii A[N];
int m;
ll qs[N], cp[N], bit[2*N];
int pos(ll x){ return upper_bound(cp, cp+m, x) - cp;}
int qry(int i){ int res = 0; for(; i; i-=i&-i) res += bit[i]; return res;}
void upd(int i, int v){ for(; i<=m; i+=i&-i) bit[i] += v;}
vector<int> find_subset(int L, int R, vector<int> w){
int n = w.size();
for(int i = 0; i<n; ++i) A[i] = mp(w[i], i);
sort(A, A+n);
for(int i = 0; i<n; ++i) qs[i] = A[i].F;
for(int i = 1; i<n; ++i) qs[i] += qs[i-1];
m = 0;
cp[m++] = 0; for(int i = 0; i<n; ++i){ cp[m++] = qs[i]; cp[m++] = qs[i] - R; }
sort(cp, cp+m); m = unique(cp, cp+m) - cp;
memset(bit, 0, sizeof(bit));
upd(pos(0), +1);
vector<int> I;
for(int i = 0; i<n; ++i){
if(qry(pos(qs[i] - L)) > qry(pos(qs[i] - R) - 1)){
if(qs[i]-R <= 0 && 0 <= qs[i]-L){
m = 0;
I.resize(i+1);
for(int j = 0; j<=i; ++j) I[m++] = A[j].S;
return I;
}
for(int j = 0; j<i; ++j){
if(qs[i]-R <= qs[j] && qs[j] <= qs[i]-L){
m = 0;
I.resize(i-j);
for(int k = j+1; k<=i; ++k) I[m++] = A[k].S;
return I;
}
}
}
upd(pos(qs[i]), +1);
}
return vector<int>();
}
# | 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... |