이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "bits/stdc++.h"
using namespace std;
int NODES = 0;
int L[3000001],R[3000001],ST[3000001];
int newleaf(int val){
NODES++;
L[NODES] = -1;
R[NODES] = -1;
ST[NODES] = val;
return NODES;
}
int newparent(int l,int r){
NODES++;
L[NODES] = l;
R[NODES] = r;
ST[NODES] = ST[l]+ST[r];
return NODES;
}
int build(int l,int r){
if(l==r)return newleaf(0);
int md = (l+r)/2;
return newparent(build(l,md),build(md+1,r));
}
int update(int p,int l,int r,int idx){
if(l==r)return newleaf(1+ST[p]);
int md = (l+r)/2;
if(idx<=md)return newparent(update(L[p],l,md,idx),R[p]);
else return newparent(L[p],update(R[p],md+1,r,idx));
}
int query(int p1,int p2,int l,int r,int lq,int rq){
if(l>=lq&&r<=rq){
return ST[p2]-ST[p1];
}
if(r<lq||l>rq)return 0;
int md = (l+r)/2;
return query(L[p1],L[p2],l,md,lq,rq)+query(R[p1],R[p2],md+1,r,lq,rq);
}
int root[100001],n;
vector<pair<int,int>> v;
void init(int N,int A[],int B[]){
n = N;
for(int i = 0;i<N;i++){
v.push_back({A[i],B[i]});
}
sort(v.begin(),v.end());
root[0] = build(1,n);
for(int i = 1;i<=v.size();i++){
root[i] = update(root[i-1],1,n,v[i-1].second);
}
}
int w(int a,int b){
int it = lower_bound(v.begin(),v.end(),make_pair(a+1,0))-v.begin();
int it2 = lower_bound(v.begin(),v.end(),make_pair(b+1,0))-v.begin();
return query(root[it],root[it2],1,n,b,n);
}
bool can(int m,int k[]){
vector<int> K;
K.push_back(0);
for(int i = 0;i<m;i++){
K.push_back(k[i]);
}
sort(K.begin(),K.end());
long long dp[m+1]; dp[0] =0;
for (int x=1; x <= m; x++) {
dp[x] = 1e9;
for(int i = 0;i<x;i++){
dp[x] = min(dp[x],dp[i]+w(K[i],K[x])-K[x]);
}
}
for(int i = 1;i<=m;i++){
if(dp[i]<0)return 0;
}
return 1;
}
컴파일 시 표준 에러 (stderr) 메시지
teams.cpp: In function 'void init(int, int*, int*)':
teams.cpp:47:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
47 | for(int i = 1;i<=v.size();i++){
| ~^~~~~~~~~~
teams.cpp: In function 'int w(int, int)':
teams.cpp:52:61: warning: conversion from '__gnu_cxx::__normal_iterator<std::pair<int, int>*, std::vector<std::pair<int, int> > >::difference_type' {aka 'long int'} to 'int' may change value [-Wconversion]
52 | int it = lower_bound(v.begin(),v.end(),make_pair(a+1,0))-v.begin();
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~
teams.cpp:53:62: warning: conversion from '__gnu_cxx::__normal_iterator<std::pair<int, int>*, std::vector<std::pair<int, int> > >::difference_type' {aka 'long int'} to 'int' may change value [-Wconversion]
53 | int it2 = lower_bound(v.begin(),v.end(),make_pair(b+1,0))-v.begin();
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~
# | 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... |