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 <iostream>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <cstring>
#include <chrono>
#include <vector>
#include <map>
#include <random>
#include <set>
#include <algorithm>
#include <math.h>
#include <cstdio>
#include <stdio.h>
#include <queue>
#include <bitset>
#include <cstdlib>
#include <deque>
#include <cassert>
#include <stack>
using namespace std;
#define mp make_pair
#define f first
#define se second
#define ll long long
#define endl '\n'
#define pii pair<int, int>
inline void setin(string s) {
freopen(s.c_str(), "r", stdin);
}
inline void setout(string s) {
freopen(s.c_str(), "w", stdout);
}
const int inf = 2e9 + 5;
const int mod = 1e9 + 7;
const int N = 1e6 + 15;
int n;
ll p[N];
pii a[N];
inline bool lie(ll l, ll x, ll r) {
return l <= x && x <= r;
}
vector<int> find_subset(int l, int u, vector<int> w) {
n = w.size();
for(int i = 0; i < n; ++i)
a[i+1] = {w[i], i};
sort(a + 1, a + 1 + n);
for(int i = 1; i <= n; ++i)
p[i] = p[i-1] + a[i].f;
vector <int> ans = {};
for(int i = 1; i <= n; ++i) {
int low = 0, up = i - 1, res1 = -1, res2 = -1;
while(low <= up) {
int mid = low + up >> 1;
if(p[i] - p[mid] >= l)
low = mid + 1, res1 = mid;
else
up = mid - 1;
}
low = 0, up = i - 1;
while(low <= up) {
int mid = low + up >> 1;
if(p[i] - p[mid] <= u)
up = mid - 1, res2 = mid;
else
low = mid + 1;
}
if(res1 != -1 && res2 != -1) {
if(res1 >= res2) {
for(int j = res1 + 1; j <= i; ++j)
ans.push_back(a[j].se);
return ans;
}
}
}
return ans;
}
Compilation message (stderr)
molecules.cpp: In function 'std::vector<int> find_subset(int, int, std::vector<int>)':
molecules.cpp:60:18: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
int mid = low + up >> 1;
~~~~^~~~
molecules.cpp:68:18: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
int mid = low + up >> 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... |