Submission #43442626
Source Code Expand
#include <bits/stdc++.h>
using namespace std;
// #define OPENIOBUF
namespace FastIO
{
class FastIOBase
{
protected:
#ifdef OPENIOBUF
static const int BUFSIZE=1<<16;
char buf[BUFSIZE+1];
int buf_p=0;
#endif
FILE *target;
FastIOBase(FILE *f): target(f){}
~FastIOBase()=default;
public:
#ifdef OPENIOBUF
virtual void flush()=0;
#endif
};
class FastOutput final: public FastIOBase
{
#ifdef OPENIOBUF
public:
void flush()
{ fwrite(buf,1,buf_p,target),buf_p=0; }
#endif
private:
void __putc(char x)
{
#ifdef OPENIOBUF
if(buf[buf_p++]=x,buf_p==BUFSIZE) flush();
#else
putc(x,target);
#endif
}
template<typename T>
void __write(T x)
{
char stk[64],*top=stk;
if(x<0) return __putc('-'),__write(-x);
do *(top++)=x%10,x/=10; while(x);
for(;top!=stk;__putc(*(--top)+'0'));
}
public:
FastOutput(FILE *f=stdout): FastIOBase(f){}
#ifdef OPENIOBUF
~FastOutput(){ flush(); }
#endif
FastOutput &operator <<(char x)
{ return __putc(x),*this; }
FastOutput &operator <<(const char *s)
{ for(;*s;__putc(*(s++)));return *this; }
FastOutput &operator <<(const string &s)
{ return (*this)<<s.c_str(); }
template<typename T>
enable_if_t<is_integral<T>::value,FastOutput&> operator <<(const T &x)
{ return __write(x),*this; }
template<typename ...T>
void writesp(const T &...x)
{ initializer_list<int>{(this->operator<<(x),__putc(' '),0)...}; }
template<typename ...T>
void writeln(const T &...x)
{ initializer_list<int>{(this->operator<<(x),__putc('\n'),0)...}; }
template<typename Iter>
void writesp(Iter begin,Iter end)
{ while(begin!=end) (*this)<<*(begin++)<<' '; }
template<typename Iter>
void writeln(Iter begin,Iter end)
{ while(begin!=end) (*this)<<*(begin++)<<'\n'; }
}qout;
class FastInput final: public FastIOBase
{
#ifdef OPENIOBUF
public:
void flush()
{ buf[fread(buf,1,BUFSIZE,target)]=EOF,buf_p=0; }
#endif
private:
bool __eof;
char __getc()
{
if(__eof) return EOF;
#ifdef OPENIOBUF
if(buf_p==BUFSIZE) flush();
char ch=buf[buf_p++];
#else
char ch=getc(target);
#endif
return ~ch?ch:(__eof=true,EOF);
}
void __ungetc(char c)
{
__eof=false;
#ifdef OPENIOBUF
buf_p--;
#else
ungetc(c,target);
#endif
}
public:
FastInput(FILE *f=stdin): FastIOBase(f),__eof(false)
#ifdef OPENIOBUF
{ buf_p=BUFSIZE; }
bool eof()const { return buf[buf_p]==EOF; }
#else
{}
bool eof()const { return feof(target); }
#endif
char peek() { return __getc(); }
explicit operator bool()const { return !__eof; }
FastInput &operator >>(char &x)
{ while(isspace(x=__getc()));return *this; }
template<typename T>
enable_if_t<is_integral<T>::value,FastInput&> operator >>(T &x)
{
char ch,sym=0;x=0;
while(isspace(ch=__getc()));
if(__eof) return *this;
if(ch=='-') sym=1,ch=__getc();
for(x=0;isdigit(ch);x=(x<<1)+(x<<3)+(ch^48),ch=__getc());
return __ungetc(ch),sym?x=-x:x,*this;
}
FastInput &operator >>(char *s)
{
while(isspace(*s=__getc()));
if(__eof) return *this;
for(;!isspace(*s) && !__eof;*(++s)=__getc());
return __ungetc(*s),*s='\0',*this;
}
FastInput &operator >>(string &s)
{
char str_buf[(1<<8)+1]={0},*p=str_buf;
char *const buf_end=str_buf+(1<<8);
while(isspace(*p=__getc()));
if(__eof) return *this;
for(s.clear(),p++;;p=str_buf)
{
for(;p!=buf_end && !isspace(*p=__getc()) && !__eof;p++);
if(p!=buf_end) break;
s.append(str_buf);
}
__ungetc(*p),*p='\0',s.append(str_buf);
return *this;
}
template<typename ...T>
void read(T &...x)
{ initializer_list<int>{(this->operator>>(x),0)...}; }
template<typename Iter>
void read(Iter begin,Iter end)
{ while(begin!=end) (*this)>>*(begin++); }
}qin;
} // namespace FastIO
using FastIO::qin,FastIO::qout;
using LL=long long;
using LD=long double;
using UI=unsigned int;
using ULL=unsigned long long;
constexpr int INF=1e9;
#ifndef DADALZY
#define FILEIO(file) freopen(file".in","r",stdin),freopen(file".out","w",stdout)
#else
#define FILEIO(file)
#endif
int n,m,nn,lsh[2000005];
struct Oper{ int l,r; }q[1000005];
int ans1,ans2,c1[4005],c2[4005],dp[4005][4005];
int main()
{
qin>>n>>m;
lsh[++nn]=1;
lsh[++nn]=n+1;
for(int i=1,l,r;i<=m;i++)
{
qin>>l>>r,q[i]=Oper{l,r};
lsh[++nn]=l;
lsh[++nn]=r+1;
}
sort(lsh+1,lsh+nn+1);
nn=unique(lsh+1,lsh+nn+1)-lsh-2;
if(nn==1) return qout<<0<<' '<<m<<'\n',0;
ans1=__lg(nn-1)+1;
for(int i=1,l,r;i<=m;i++)
{
l=q[i].l,r=q[i].r;
l=lower_bound(lsh+1,lsh+nn+1,l)-lsh;
r=lower_bound(lsh+1,lsh+nn+1,r+1)-lsh-1;
c1[l]++,c2[r]++;
}
int lim=nn-(1<<(ans1-1));
for(int i=0;i<=nn;i++) fill(dp[i],dp[i]+lim+1,INF);
dp[0][0]=0;
for(int i=1;i<=nn;i++) for(int j=0;j<=lim;j++)
{
if(i>=1)
dp[i][j]=min(dp[i][j],dp[i-1][j]);
if(i>=2 && j>0)
dp[i][j]=min(dp[i][j],dp[i-2][j-1]+2*(c1[i]+c2[i-1]));
}
ans2=dp[nn][lim];
qout<<ans1<<' '<<ans2<<'\n';
return 0;
}
Submission Info
| Submission Time |
|
| Task |
E - Segment-Tree Optimization |
| User |
balalida |
| Language |
C++ (GCC 9.2.1) |
| Score |
700 |
| Code Size |
5002 Byte |
| Status |
AC |
| Exec Time |
75 ms |
| Memory |
51560 KiB |
Judge Result
| Set Name |
Sample |
All |
| Score / Max Score |
0 / 0 |
700 / 700 |
| Status |
|
|
| Set Name |
Test Cases |
| Sample |
sample-01.txt, sample-02.txt |
| All |
in-01.txt, in-02.txt, in-03.txt, in-04.txt, in-05.txt, in-06.txt, in-07.txt, in-08.txt, in-09.txt, in-10.txt, in-11.txt, in-12.txt, in-13.txt, in-14.txt, in-15.txt, in-16.txt, in-17.txt, in-18.txt, in-19.txt, in-20.txt, in-21.txt, in-22.txt, in-23.txt, in-24.txt, in-25.txt, in-26.txt, in-27.txt, in-28.txt, in-29.txt, in-30.txt, in-31.txt, in-32.txt, in-33.txt, in-34.txt, in-35.txt, in-36.txt, in-37.txt, in-38.txt, in-39.txt, in-40.txt, in-41.txt, in-42.txt, in-43.txt, in-44.txt, in-45.txt, in-46.txt, in-47.txt, in-48.txt, in-49.txt, in-50.txt, in-51.txt, sample-01.txt, sample-02.txt |
| Case Name |
Status |
Exec Time |
Memory |
| in-01.txt |
AC |
75 ms |
51560 KiB |
| in-02.txt |
AC |
20 ms |
5032 KiB |
| in-03.txt |
AC |
55 ms |
21576 KiB |
| in-04.txt |
AC |
53 ms |
21564 KiB |
| in-05.txt |
AC |
54 ms |
21620 KiB |
| in-06.txt |
AC |
39 ms |
7276 KiB |
| in-07.txt |
AC |
33 ms |
6144 KiB |
| in-08.txt |
AC |
40 ms |
7160 KiB |
| in-09.txt |
AC |
40 ms |
7280 KiB |
| in-10.txt |
AC |
41 ms |
9244 KiB |
| in-11.txt |
AC |
43 ms |
7276 KiB |
| in-12.txt |
AC |
41 ms |
7108 KiB |
| in-13.txt |
AC |
35 ms |
5504 KiB |
| in-14.txt |
AC |
39 ms |
6328 KiB |
| in-15.txt |
AC |
36 ms |
5592 KiB |
| in-16.txt |
AC |
43 ms |
7692 KiB |
| in-17.txt |
AC |
47 ms |
11308 KiB |
| in-18.txt |
AC |
47 ms |
11252 KiB |
| in-19.txt |
AC |
31 ms |
5244 KiB |
| in-20.txt |
AC |
34 ms |
6184 KiB |
| in-21.txt |
AC |
33 ms |
5308 KiB |
| in-22.txt |
AC |
29 ms |
5304 KiB |
| in-23.txt |
AC |
41 ms |
7520 KiB |
| in-24.txt |
AC |
39 ms |
7056 KiB |
| in-25.txt |
AC |
33 ms |
5476 KiB |
| in-26.txt |
AC |
39 ms |
7452 KiB |
| in-27.txt |
AC |
41 ms |
7300 KiB |
| in-28.txt |
AC |
53 ms |
18444 KiB |
| in-29.txt |
AC |
39 ms |
13376 KiB |
| in-30.txt |
AC |
46 ms |
21392 KiB |
| in-31.txt |
AC |
11 ms |
4264 KiB |
| in-32.txt |
AC |
8 ms |
4008 KiB |
| in-33.txt |
AC |
2 ms |
3604 KiB |
| in-34.txt |
AC |
2 ms |
3556 KiB |
| in-35.txt |
AC |
24 ms |
5196 KiB |
| in-36.txt |
AC |
57 ms |
29724 KiB |
| in-37.txt |
AC |
69 ms |
46436 KiB |
| in-38.txt |
AC |
62 ms |
46532 KiB |
| in-39.txt |
AC |
47 ms |
15852 KiB |
| in-40.txt |
AC |
53 ms |
21312 KiB |
| in-41.txt |
AC |
18 ms |
18360 KiB |
| in-42.txt |
AC |
14 ms |
10116 KiB |
| in-43.txt |
AC |
12 ms |
9868 KiB |
| in-44.txt |
AC |
19 ms |
12292 KiB |
| in-45.txt |
AC |
16 ms |
14516 KiB |
| in-46.txt |
AC |
3 ms |
3684 KiB |
| in-47.txt |
AC |
2 ms |
3940 KiB |
| in-48.txt |
AC |
3 ms |
3600 KiB |
| in-49.txt |
AC |
3 ms |
3632 KiB |
| in-50.txt |
AC |
3 ms |
3768 KiB |
| in-51.txt |
AC |
16 ms |
5004 KiB |
| sample-01.txt |
AC |
3 ms |
3616 KiB |
| sample-02.txt |
AC |
3 ms |
3580 KiB |