Submission #134168

#TimeUsernameProblemLanguageResultExecution timeMemory
134168ckodserTeams (IOI15_teams)C++14
34 / 100
4025 ms103184 KiB
#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 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]; 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); ll p2=0; for(auto v:vec[2*node]){ while(p2<vec[2*node+1].size() && vec[2*node+1][p2]<=v){ vec[node].pb(vec[2*node+1][p2]); p2++; } vec[node].pb(v); } while(p2<vec[2*node+1].size()){ vec[node].pb(vec[2*node+1][p2]); p2++; } return ; } vec[node].pb(c[l].S); } ll findNum(ll l,ll r,ll node){ if(mx[node]<=l){ return vec[node].end()-lower_bound(vec[node].begin(),vec[node].end(),r); } if(mn[node]>l)return 0; return findNum(l,r,2*node)+findNum(l,r,2*node+1); } 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); } } 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; }

Compilation message (stderr)

teams.cpp: In function 'void bild(int, int, int)':
teams.cpp:90: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:97: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)':
teams.cpp:107:25: warning: conversion to 'int' from '__gnu_cxx::__normal_iterator<int*, std::vector<int> >::difference_type {aka long int}' may alter its value [-Wconversion]
   return vec[node].end()-lower_bound(vec[node].begin(),vec[node].end(),r);
          ~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
teams.cpp: In function 'int can(int, int*)':
teams.cpp:162:27: warning: conversion to 'int' from 'long int' may alter its value [-Wconversion]
  ll sz=unique(comp,comp+m)-comp;
        ~~~~~~~~~~~~~~~~~~~^~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...