이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "teams.h"
#include <bits/stdc++.h>
using namespace std ;
#define ii pair<int,int>
#define fi first
#define se second
#define vi vector<int>
#define vii vector<ii>
typedef long long ll ;
int st[10000010] , le[1000010] , r[10000010] , n , qs[500010] , rt[500010] , ncnt = 1 ;
vii srt ;
void upd(int prev , int node , int f , int l ,int x){
if(f == l){
st[node] = st[prev] + 1 ;
return ;
}
int mid = (f+l)>>1 ;
if(mid < x){
le[node] = le[prev] ; r[node] = ncnt++ ;
upd( r[prev] , r[node] , mid+1 , l , x ) ;
}
else{
le[node] = ncnt++ ; r[node] = r[prev] ;
upd( le[prev] , le[node] , f , mid , x ) ;
}
st[node] = st[le[node]] + st[r[node]] ;
}
int qr(int prev , int node , int f ,int l , int x ){
if(x == 0) return 0 ;
if(x >= l) return st[node] - st[prev] ;
int mid = (f+l)>>1 ;
if(mid < x) return st[le[node]] - st[le[prev]] + qr(r[prev] , r[node] , mid+1 , l , x ) ;
else return qr(le[prev] , le[node] , f , mid , x ) ;
}
void init(int N, int A[], int B[]) {
n = N ;
for(int i=0;i<n;i++) {
qs[A[i]]++ ; qs[B[i]+1]-- ;
srt.push_back( { B[i] + 1 , i } ) ;
}
sort(srt.begin() , srt.end() ) ;
for(int i=1;i<=n;i++) qs[i] += qs[i-1] ;
// printf("%d ", qs[i]) ;
// cout << endl ;
int j = 0 , tmp , num ;
rt[0] = 0 ;
for(int i=1;i<=n;i++){
rt[i] = rt[i-1] ;
while( j<srt.size() && i >= srt[j].fi ) {
printf("%d %d\n" , srt[j].fi , srt[j].se) ;
num = srt[j].se ;
tmp = ncnt++ ;
upd(rt[i] , tmp , 1 , n , A[num] ) ;
rt[i] = tmp ;
j++ ;
}
// for(int j=1 ; j<=n ;j++) printf("%d " , qr(rt[i-1] , rt[i] , 1 , n , j) ) ;
// cout << endl ;
}
}
int can(int m, int arr[]) {
int sum = 0 ;
for(int i=0;i<m;i++) {
sum += arr[i] ;
if(sum > n) return 0 ;
}
sort(arr , arr+m) ;
int lst = 0 , mn = 0 ;
// printf("--------\n") ;
for(int i=0;i<m;i++){
mn = mn - qr(rt[lst] , rt[arr[i]] , 1 , n , lst ) ;
if(mn < 0) printf("%d" , 1/0) ;
// printf("%d %d\n" , mn , arr[i]) ;
if(qs[arr[i]] - mn < arr[i]) return 0 ;
mn += arr[i] ;
lst = arr[i] ;
}
return 1;
}
컴파일 시 표준 에러 (stderr) 메시지
teams.cpp: In function 'void init(int, int*, int*)':
teams.cpp:53:11: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
while( j<srt.size() && i >= srt[j].fi ) {
^
teams.cpp: In function 'int can(int, int*)':
teams.cpp:77:29: warning: division by zero [-Wdiv-by-zero]
if(mn < 0) printf("%d" , 1/0) ;
^
# | 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... |