이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "teams.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(v) v.begin(), v.end()
vector<vector<int>> st;
int len = 1;
int qry(int l, int r, int val, int i = 1, int s = 0, int e = len){
if(l >= e || s >= r) return 0;
if(l <= s && e <= r){
return upper_bound(all(st[i]), val) - st[i].begin();
}
return qry(l, r, val, i * 2, s, (s + e) / 2) +
qry(l, r, val, i * 2 + 1,(s + e) / 2, e);
}
void init(int N, int A[], int B[]) {
while(len < N + 1) len *= 2;
st.resize(2 * len);
for (int i = 0; i < N; i++) {
st[len + B[i]].push_back(A[i]);
}
for (int i = len - 1; i > 0; i--) {
int j = 0, k = 0;
st[i].reserve(st[i * 2].size() + st[i * 2 + 1].size());
while(j < st[i * 2].size() && i < st[i * 2 + 1].size()){
if(st[i * 2][j] < st[i * 2 + 1][k]){
st[i].push_back(st[i * 2][j++]);
}
else{
st[i].push_back(st[i * 2 + 1][k++]);
}
}
for (; j < st[i * 2].size(); j++) st[i].push_back(st[i * 2][j]);
for (; k < st[i * 2 + 1].size(); k++) st[i].push_back(st[i * 2 + 1][k]);
}
}
int can(int M, int K[]) {
sort(K, K + M, greater<int>());
int rem = 0;
for (int i = 0; i < M; i++) {
int my, a, b;
a = qry(K[i], len + 1, K[i]);
if(i != M - 1) b = qry(K[i], len + 1, K[i + 1]);
else b = 0;
my = a - b;
rem += K[i];
if(rem > a) return 0;
rem -= my;
}
return 1;
}
컴파일 시 표준 에러 (stderr) 메시지
teams.cpp: In function 'int qry(int, int, int, int, int, int)':
teams.cpp:14:39: warning: conversion from '__gnu_cxx::__normal_iterator<int*, std::vector<int> >::difference_type' {aka 'long int'} to 'int' may change value [-Wconversion]
14 | return upper_bound(all(st[i]), val) - st[i].begin();
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~
teams.cpp: In function 'void init(int, int*, int*)':
teams.cpp:30:11: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
30 | while(j < st[i * 2].size() && i < st[i * 2 + 1].size()){
| ~~^~~~~~~~~~~~~~~~~~
teams.cpp:30:35: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
30 | while(j < st[i * 2].size() && i < st[i * 2 + 1].size()){
| ~~^~~~~~~~~~~~~~~~~~~~~~
teams.cpp:38:12: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
38 | for (; j < st[i * 2].size(); j++) st[i].push_back(st[i * 2][j]);
| ~~^~~~~~~~~~~~~~~~~~
teams.cpp:39:12: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
39 | for (; k < st[i * 2 + 1].size(); k++) st[i].push_back(st[i * 2 + 1][k]);
| ~~^~~~~~~~~~~~~~~~~~~~~~
# | 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... |