이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "teams.h"
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif
int gcd(int a, int b) {return b == 0 ? a : gcd(b, a % b);}
#define ll int
#define pb push_back
#define ld long double
#define mp make_pair
#define F first
#define S second
#define pii pair<ll,ll>
using namespace :: std;
const ll maxn=1e5+500;
const ll inf=1e9+800;
const ll mod=1e9+7;
const ll maxm=1e5+500;
const ll sq=700;
ll n;
pii c[maxn];
ll mx[maxn*4];
ll mn[maxn*4];
vector<ll> vec[maxn*4];
vector<ll> lowerR[maxn*4];
vector<ll> lowerL[maxn*4];
void bild(ll l,ll r,ll node){
mx[node]=c[r-1].F;
mn[node]=c[l].F;
if(l+1!=r){
ll mid=(l+r)/2;
bild(l,mid,2*node);
bild(mid,r,2*node+1);
vec[node].resize(r-l);
lowerR[node].resize(r-l);
lowerL[node].resize(r-l);
ll p2=0;
for(ll i=0;i<vec[2*node].size();i++){
ll v=vec[2*node][i];
while(p2<vec[2*node+1].size() && vec[2*node+1][p2]<=v){
vec[node].pb(vec[2*node+1][p2]);
lowerR[node].pb(p2);
lowerL[node].pb(i);
p2++;
}
lowerR[node].pb(p2);
lowerL[node].pb(i);
vec[node].pb(v);
}
while(p2<vec[2*node+1].size()){
vec[node].pb(vec[2*node+1][p2]);
lowerR[node].pb(p2);
lowerL[node].pb(-1);
p2++;
}
return ;
}
vec[node].pb(c[l].S);
}
ll findNum(ll l,ll r,ll node,ll x){
if(x==-1)return 0;
if(x==-2)x=lower_bound(vec[node].begin(),vec[node].end(),r)-vec[node].begin();
if(mx[node]<=l){
return vec[node].size()-x;
}
if(mn[node]>l)return 0;
return findNum(l,r,2*node,lowerL[node][x])+findNum(l,r,2*node+1,lowerR[node][x]);
}
void init(int N, int A[], int B[]) {
n=N;
for(ll i=0;i<N;i++){
c[i]=mp(A[i],B[i]);
}
sort(c,c+N);
bild(0,n,1);
}
ll ger[sq][sq];
void makeGer(ll m,ll k[]){
memset(ger,0,sizeof ger);
for(ll i=0;i<m;i++){
for(ll j=i;j<m;j++){
ger[i][j]=findNum(k[i],k[j],1,-2);
}
}
for(ll t=1;t<=m;t++){
for(ll l=0;l+t-1<m;l++){
ll r=l+t-1;
if(l!=0){
ger[l][r]-=ger[l-1][r];
}
if(r!=m-1){
ger[l][r]-=ger[l][r+1];
}
if(l!=0 && r!=m-1){
ger[l][r]+=ger[l-1][r+1];
}
}
}
}
ll comp[maxm];
ll tmp[sq];
ll gri[sq];
int can(int m, int k[]) {
ll sum=0;
for(ll i=0;i<m;i++){
sum+=k[i];
}
if(sum>n){
return 0;
}
sort(k,k+m);
memset(gri,0,sizeof gri);
memset(tmp,0,sizeof tmp);
for(ll i=0;i<m;i++){
comp[i]=(k[i]);
}
ll sz=unique(comp,comp+m)-comp;
makeGer(sz,comp);
for(ll i=0;i<m;i++){
tmp[lower_bound(comp,comp+sz,k[i])-comp]++;
}
for(ll i=0;i<sz;i++){
comp[i]*=tmp[i];
}
for(ll i=0;i<sz;i++){
for(ll j=i;j<sz;j++){
gri[j]+=ger[i][j];
}
for(ll j=i;j<sz && 0<comp[i];j++){
ll res=min(comp[i],gri[j]);
comp[i]-=res;
gri[j]-=res;
}
if(comp[i])return 0;
}
return 1;
}
컴파일 시 표준 에러 (stderr) 메시지
teams.cpp: In function 'void bild(int, int, int)':
teams.cpp:96:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(ll i=0;i<vec[2*node].size();i++){
~^~~~~~~~~~~~~~~~~~~
teams.cpp:98:12: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
while(p2<vec[2*node+1].size() && vec[2*node+1][p2]<=v){
~~^~~~~~~~~~~~~~~~~~~~~
teams.cpp:109:11: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
while(p2<vec[2*node+1].size()){
~~^~~~~~~~~~~~~~~~~~~~~
teams.cpp: In function 'int findNum(int, int, int, int)':
teams.cpp:121:61: warning: conversion to 'int' from '__gnu_cxx::__normal_iterator<int*, std::vector<int> >::difference_type {aka long int}' may alter its value [-Wconversion]
if(x==-2)x=lower_bound(vec[node].begin(),vec[node].end(),r)-vec[node].begin();
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~
teams.cpp:123:26: warning: conversion to 'int' from 'std::vector<int>::size_type {aka long unsigned int}' may alter its value [-Wconversion]
return vec[node].size()-x;
~~~~~~~~~~~~~~~~^~
teams.cpp: In function 'int can(int, int*)':
teams.cpp:178:27: warning: conversion to 'int' from 'long int' may alter its value [-Wconversion]
ll sz=unique(comp,comp+m)-comp;
~~~~~~~~~~~~~~~~~~~^~~~~
# | 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... |