이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "gift.h"
#include<bits/stdc++.h>
using namespace std;
struct point {
int s,e,u;
};
vector<int64_t>tree;
int64_t func(int64_t a,int64_t b){
return a+b;
}
void build(int& n ,vector<int64_t>&arr){
while(__builtin_popcount(n)!=1){
++n;
arr.push_back(0);
}
tree.resize(2*n);
for (int i = 0;i<n;++i){
tree[n+i]=arr[i];
}
for (int i =n-1;i>=1;--i){
tree[i]=func(tree[2*i],tree[2*i+1]);
}
}
int64_t rangesum(int node,int low_node,int high_node,int qlow,int qhigh){
if (qlow<=low_node&&high_node<=qhigh)return tree[node];
if (high_node<qlow||qhigh<low_node){
return 0;
}
int mid = (low_node+high_node)/2;
return func(rangesum(2*node,low_node,mid,qlow,qhigh),rangesum(2*node + 1,mid+1,high_node,qlow,qhigh));
}
void update(int i , int v,int n){
tree[n+i]=v;
for (int j = (n+i)/2;j>=1;j/=2){
tree[j]=func(tree[j*2],tree[j*2 + 1]);
}
}
int construct(int n, int r, std::vector<int> a, std::vector<int> b, std::vector<int> x) {
vector<point>arr,brr;
vector<int64_t>crr(n,0);
string s(n,'R');
while(__builtin_popcount(n)!=1){
++n;
crr.push_back(0);
}
build(n,crr);
for (int i =0;i<r;++i){
point p;
p.s=a[i];
p.e=b[i];
p.u=x[i];
if (p.u==2)arr.push_back(p);
else brr.push_back(p);
}
sort(arr.begin(),arr.end(),[&](point i,point j){
if (i.e==j.e)return i.s>j.s;
return i.e<j.e;
});
for (int i =0;i<arr.size();++i){
int temp = rangesum(1,0,n-1,arr[i].s,arr[i].e);
if (temp + 1<arr[i].u){
for (int j = arr[i].s;j<=arr[i].e;++j){
bool ok=true;
for (auto y:brr){
if (y.s<=j&&j<=y.e){
ok=false;break;
}
}
if (ok){
s[j]='B';
update(j,1,n);
break;
}
else if (j==arr[i].e)return 0;
}
}
}
for (int i =0;i<brr.size();++i){
if (rangesum(1,0,n-1,brr[i].s,brr[i].e)+1>brr[i].u)return 0;
}
craft(s);
return 1;
}
컴파일 시 표준 에러 (stderr) 메시지
gift.cpp: In function 'int construct(int, int, std::vector<int>, std::vector<int>, std::vector<int>)':
gift.cpp:61:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<point>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
61 | for (int i =0;i<arr.size();++i){
| ~^~~~~~~~~~~
gift.cpp:81:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<point>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
81 | for (int i =0;i<brr.size();++i){
| ~^~~~~~~~~~~
# | 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... |