이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include"teams.h"
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
#define chmin(a,b) a=min(a,b)
#define chmax(a,b) a=max(a,b)
#define all(x) x.begin(),x.end()
#define rep(i,n) for(int i=0;i<n;i++)
#define mod 1000000007
#define mad(a,b) a=(a+b)%mod
#define NS 100010
vector<P> v;
int dat[NS*2],laz1[2*NS],laz2[2*NS],correctA;
vector<ll> as[NS*2];
void add(int K){
correctA=K;
}
ll eval(ll k){
if(k==0)return 0;
if(k<NS){
chmax(laz2[k*2],laz2[k]);
chmax(laz2[k*2+1],laz2[k]);
}
if(laz1[k]<=laz2[k])dat[k]=0;
dat[k]+=upper_bound(all(as[k]),correctA)-upper_bound(all(as[k]),max(laz1[k],laz2[k]));
//cout<<"eval:"<<k<<" "<<correctA<<" "<<laz1[k]<<" "<<laz2[k]<<" "<<dat[k]<<endl;
laz1[k]=correctA;
return dat[k];
}
void erase(ll l,ll r){
l+=NS,r+=NS+1;
for(ll a=l,b=r;a<b;a>>=1,b>>=1){
if(a&1)laz2[a]=correctA,a++;
if(b&1)b--,laz2[b]=correctA;
}
for(ll a=l,b=r;a+b;a>>=1,b>>=1){
dat[a/2]=eval(a)+eval(a^1);
dat[b/2]=eval(b)+eval(b^1);
}
}
int sum(ll l,ll r){
l+=NS,r+=NS+1;
ll res=0;
for(ll d=20;~d;d--){
eval(l>>d);
eval(r>>d);
}
for(ll a=l,b=r;a<b;a>>=1,b>>=1){
if(a&1){res+=eval(a);a++;}
if(b&1){b--;res+=eval(b);}
}
return res;
}
void init(int N,int A[],int B[]){
rep(i,N)v.push_back(make_pair(B[i],A[i]));
sort(v.begin(),v.end());
rep(i,NS){
if(i<N)as[i+NS].push_back(v[i].second);
}
for(int i=NS-1;i>0;i--){
for(auto t:as[i*2])as[i].push_back(t);
for(auto t:as[i*2+1])as[i].push_back(t);
sort(as[i].begin(),as[i].end());
}
}
int can(int M,int K[]){
rep(i,2*NS)dat[i]=0,laz1[i]=0,laz2[i]=0; correctA=0;
sort(K,K+M);
rep(i,M){
add(K[i]);
ll l,r,mid;
l=-1,r=v.size();
while(l<r-1){
mid=(l+r)>>1;
(v[mid].first<K[i]?l:r)=mid;
}
//cerr<<"##"<<sum(0,v.size()-1)<<endl;
erase(0,l);//cerr<<"$"<<l<<endl;
l=-1,r=v.size();
//cerr<<"#"<<sum(0,v.size()-1)<<endl;
while(l<r-1){
mid=(l+r)>>1;
(sum(0,mid)>=K[i]?r:l)=mid;
}
if(r==v.size())return 0;
erase(0,r);
}
return 1;
}
/*
int main(){
int n,a[110],b[110];
cin>>n;
rep(i,n)cin>>a[i]>>b[i];
init(n,a,b);
while(1){
int m,k[110];
cin>>m;
rep(i,m)cin>>k[i];
cout<<(can(m,k)?"YES":"NO")<<endl;
}
}*/
컴파일 시 표준 에러 (stderr) 메시지
teams.cpp: In function 'll eval(ll)':
teams.cpp:30:86: warning: conversion to 'int' from '__gnu_cxx::__normal_iterator<long long int*, std::vector<long long int> >::difference_type {aka long int}' may alter its value [-Wconversion]
dat[k]+=upper_bound(all(as[k]),correctA)-upper_bound(all(as[k]),max(laz1[k],laz2[k]));
^
teams.cpp: In function 'void erase(ll, ll)':
teams.cpp:42:19: warning: conversion to 'int' from 'll {aka long long int}' may alter its value [-Wconversion]
dat[a/2]=eval(a)+eval(a^1);
~~~~~~~^~~~~~~~~~
teams.cpp:43:19: warning: conversion to 'int' from 'll {aka long long int}' may alter its value [-Wconversion]
dat[b/2]=eval(b)+eval(b^1);
~~~~~~~^~~~~~~~~~
teams.cpp: In function 'int sum(ll, ll)':
teams.cpp:57:9: warning: conversion to 'int' from 'll {aka long long int}' may alter its value [-Wconversion]
return res;
^~~
teams.cpp: In function 'int can(int, int*)':
teams.cpp:12:18: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
#define rep(i,n) for(int i=0;i<n;i++)
^
teams.cpp:74:2: note: in expansion of macro 'rep'
rep(i,2*NS)dat[i]=0,laz1[i]=0,laz2[i]=0; correctA=0;
^~~
teams.cpp:74:43: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
rep(i,2*NS)dat[i]=0,laz1[i]=0,laz2[i]=0; correctA=0;
^~~~~~~~
teams.cpp:92:7: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
if(r==v.size())return 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... |