이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "molecules.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
struct segtree{
int size;
vector<ll> values;
void build(vector<int> &a,int x,int lx,int rx){
if(rx-lx==1){
if(lx<(int)a.size()){
values[x]=a[lx];
}
return;
}
int m=(lx+rx)/2;
build(a,2*x+1,lx,m);
build(a,2*x+2,m,rx);
values[x]=min(values[2*x+1],values[2*x+2]);
}
void build(vector<int> &a){
build(a,0,0,size);
}
void init(int n){
size=1;
while(size<n){
size*=2;
}
values.assign(2*size,0LL);
}
ll calc(int l,int r,int x,int lx,int rx){
if(lx>=r || rx<=l){
return INT_MAX;
}
if(lx>=l && rx<=r){
return values[x];
}
ll s1,s2;
int m=(lx+rx)/2;
s1=calc(l,r,2*x+1,lx,m);
s2=calc(l,r,2*x+2,m,rx);
return min(s1,s2);
}
ll calc(int l,int r){
return calc(l,r,0,0,size);
}
};
struct segtree1{
int size;
vector<ll> values;
void build(vector<int> &a,int x,int lx,int rx){
if(rx-lx==1){
if(lx<(int)a.size()){
values[x]=a[lx];
}
return;
}
int m=(lx+rx)/2;
build(a,2*x+1,lx,m);
build(a,2*x+2,m,rx);
values[x]=max(values[2*x+1],values[2*x+2]);
}
void build(vector<int> &a){
build(a,0,0,size);
}
void init(int n){
size=1;
while(size<n){
size*=2;
}
values.assign(2*size,INT_MIN);
}
ll calc(int l,int r,int x,int lx,int rx){
if(lx>=r || rx<=l){
return INT_MIN;
}
if(lx>=l && rx<=r){
return values[x];
}
ll s1,s2;
int m=(lx+rx)/2;
s1=calc(l,r,2*x+1,lx,m);
s2=calc(l,r,2*x+2,m,rx);
return max(s1,s2);
}
ll calc(int l,int r){
return calc(l,r,0,0,size);
}
};
vector<int> find_subset(int l, int u, std::vector<int> w) {
vector<int> ans;
ll n=w.size();
ll a[n+5];
segtree st;
vector<pair<ll,ll>> v;
sort(w.begin(),w.end());
for(int i =0;i<n;i++)
{
v.push_back({w[i],i});
}
int j =0;
ll sum=0;
for(int i =0;i<n;i++)
{
sum+=v[i].first;
while(sum>u)
{
sum-=v[j++].first;
}
if(sum>=l)
{
for(int k =j;k<=i;k++)
{
ans.push_back(k);
}
break;
}
}
return ans;
}
컴파일 시 표준 에러 (stderr) 메시지
molecules.cpp: In function 'std::vector<int> find_subset(int, int, std::vector<int>)':
molecules.cpp:92:8: warning: unused variable 'a' [-Wunused-variable]
92 | ll a[n+5];
| ^
# | 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... |