Submission #48273091


Source Code Expand

// LUOGU_RID: 138732569
#include<bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ldb;

#define rep(i,l,r) for(int i(l);i<=(r);++i)
#define per(i,r,l) for(int i(r);i>=(l);--i)
#define eb emplace_back
#define File(filename) freopen(filename ".in","r",stdin),freopen(filename ".out","w",stdout)

#ifdef EXODUS
	#define Debug(...) fprintf(stderr,__VA_ARGS__)
#else
	#define Debug(...) 0
#endif

//=========================================================================================================
// Something about IO

template<typename T>
void read(T &x){
	x=0;T flg=1;
	char ch=getchar();
	while(!isdigit(ch)){if(ch=='-')flg=-1;ch=getchar();}
	while(isdigit(ch))x=(x<<3)+(x<<1)+(ch^48),ch=getchar();
	x*=flg;
}
template<typename T,typename... Args>
void read(T &x,Args &...args){read(x),read(args...);}

//=========================================================================================================
// Define the global variables here.

bool membg=0;

constexpr int N=2e5+7,V=1e9;
int n;
int f[N];

struct Sgt{
#define ls(k) t[k].ls
#define rs(k) t[k].rs
	struct node{int ls,rs;int mxv;}t[N<<6];
	int tot;
	void modify(int l,int r,int &k,int p,int v){
		if(!k)k=++tot,t[k].mxv=-1e9;
		t[k].mxv=max(t[k].mxv,v);
		if(l==r)return;
		int mid=(l+r)>>1;
		if(p<=mid)modify(l,mid,ls(k),p,v);
		else modify(mid+1,r,rs(k),p,v);
	}
	int query(int l,int r,int k,int ql,int qr){
		if(ql>qr||!k)return -1e9;
		if(ql<=l&&r<=qr)return t[k].mxv;
		int mid=(l+r)>>1;int res=-1e9;
		if(ql<=mid)res=max(res,query(l,mid,ls(k),ql,qr));
		if(mid<qr)res=max(res,query(mid+1,r,rs(k),ql,qr));
		return res;
	}
#undef ls
#undef rs
}sgt[2];
int rt[2];
int l[N],r[N];

bool memed=0;

//=========================================================================================================
// Code here.

void solve(){
	read(n);
	for(int i=1;i<=n;i++)read(l[i],r[i]);
	for(int i=1;i<=n;i++){
		f[i]=max(0,sgt[0].query(1,V,rt[0],1,l[i]-1))+r[i]-l[i]+1;
		f[i]=max(f[i],sgt[1].query(1,V,rt[1],l[i],r[i])+r[i]);
		// printf("%d\n",f[i]);
		sgt[0].modify(1,V,rt[0],r[i],f[i]);
		sgt[1].modify(1,V,rt[1],r[i],f[i]-r[i]);
	}
	printf("%d\n",*max_element(f+1,f+n+1));
	return;
}


//=========================================================================================================

int main(){
	Debug("%.3lfMB\n",fabs(&memed-&membg)/1024.0/1024.0);
	int timbg=clock();
	int T=1;
	while(T--)solve();
	int timed=clock();
	Debug("%.3lfs\n",1.0*(timed-timbg)/CLOCKS_PER_SEC);
	fflush(stdout);
	return 0;
}

Submission Info

Submission Time
Task D - LIS 2
User EXODUS
Language C++ 17 (gcc 12.2)
Score 600
Code Size 2676 Byte
Status AC
Exec Time 309 ms
Memory 69228 KiB

Compile Error

Main.cpp: In function ‘int main()’:
Main.cpp:18:28: warning: statement has no effect [-Wunused-value]
   18 |         #define Debug(...) 0
      |                            ^
Main.cpp:94:9: note: in expansion of macro ‘Debug’
   94 |         Debug("%.3lfMB\n",fabs(&memed-&membg)/1024.0/1024.0);
      |         ^~~~~
Main.cpp:18:28: warning: statement has no effect [-Wunused-value]
   18 |         #define Debug(...) 0
      |                            ^
Main.cpp:99:9: note: in expansion of macro ‘Debug’
   99 |         Debug("%.3lfs\n",1.0*(timed-timbg)/CLOCKS_PER_SEC);
      |         ^~~~~
Main.cpp:95:13: warning: unused variable ‘timbg’ [-Wunused-variable]
   95 |         int timbg=clock();
      |             ^~~~~
Main.cpp:98:13: warning: unused variable ‘timed’ [-Wunused-variable]
   98 |         int timed=clock();
      |             ^~~~~

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 600 / 600
Status
AC × 3
AC × 48
Set Name Test Cases
Sample 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt
All 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt, 01_srnd_00.txt, 01_srnd_01.txt, 01_srnd_02.txt, 01_srnd_03.txt, 01_srnd_04.txt, 01_srnd_05.txt, 01_srnd_06.txt, 01_srnd_07.txt, 01_srnd_08.txt, 01_srnd_09.txt, 02_rnd_00.txt, 02_rnd_01.txt, 02_rnd_02.txt, 02_rnd_03.txt, 02_rnd_04.txt, 02_rnd_05.txt, 02_rnd_06.txt, 02_rnd_07.txt, 02_rnd_08.txt, 02_rnd_09.txt, 03_fixlen_00.txt, 03_fixlen_01.txt, 03_fixlen_02.txt, 03_fixlen_03.txt, 03_fixlen_04.txt, 03_fixlen_05.txt, 03_fixlen_06.txt, 03_fixlen_07.txt, 04_sorted_00.txt, 04_sorted_01.txt, 04_sorted_02.txt, 04_sorted_03.txt, 05_max_00.txt, 05_max_01.txt, 05_max_02.txt, 05_max_03.txt, 05_max_04.txt, 06_one_00.txt, 06_one_01.txt, 07_hand_00.txt, 07_hand_01.txt, 07_hand_02.txt, 08_sqrt_00.txt, 08_sqrt_01.txt, 08_sqrt_02.txt
Case Name Status Exec Time Memory
00_sample_00.txt AC 1 ms 3800 KiB
00_sample_01.txt AC 1 ms 3940 KiB
00_sample_02.txt AC 1 ms 3816 KiB
01_srnd_00.txt AC 1 ms 3820 KiB
01_srnd_01.txt AC 1 ms 3900 KiB
01_srnd_02.txt AC 1 ms 3776 KiB
01_srnd_03.txt AC 1 ms 3920 KiB
01_srnd_04.txt AC 1 ms 3856 KiB
01_srnd_05.txt AC 1 ms 3744 KiB
01_srnd_06.txt AC 1 ms 3908 KiB
01_srnd_07.txt AC 1 ms 3860 KiB
01_srnd_08.txt AC 1 ms 3908 KiB
01_srnd_09.txt AC 1 ms 3908 KiB
02_rnd_00.txt AC 148 ms 41904 KiB
02_rnd_01.txt AC 148 ms 40864 KiB
02_rnd_02.txt AC 180 ms 46880 KiB
02_rnd_03.txt AC 309 ms 65412 KiB
02_rnd_04.txt AC 264 ms 60984 KiB
02_rnd_05.txt AC 290 ms 63512 KiB
02_rnd_06.txt AC 227 ms 54428 KiB
02_rnd_07.txt AC 212 ms 52088 KiB
02_rnd_08.txt AC 219 ms 53452 KiB
02_rnd_09.txt AC 255 ms 59012 KiB
03_fixlen_00.txt AC 232 ms 69180 KiB
03_fixlen_01.txt AC 226 ms 69216 KiB
03_fixlen_02.txt AC 231 ms 69080 KiB
03_fixlen_03.txt AC 232 ms 69132 KiB
03_fixlen_04.txt AC 228 ms 69044 KiB
03_fixlen_05.txt AC 234 ms 69228 KiB
03_fixlen_06.txt AC 227 ms 69092 KiB
03_fixlen_07.txt AC 227 ms 69044 KiB
04_sorted_00.txt AC 81 ms 15408 KiB
04_sorted_01.txt AC 82 ms 15600 KiB
04_sorted_02.txt AC 80 ms 13108 KiB
04_sorted_03.txt AC 79 ms 13068 KiB
05_max_00.txt AC 29 ms 6136 KiB
05_max_01.txt AC 32 ms 6228 KiB
05_max_02.txt AC 32 ms 6128 KiB
05_max_03.txt AC 69 ms 15564 KiB
05_max_04.txt AC 66 ms 15480 KiB
06_one_00.txt AC 2 ms 3804 KiB
06_one_01.txt AC 1 ms 3796 KiB
07_hand_00.txt AC 59 ms 10768 KiB
07_hand_01.txt AC 42 ms 6232 KiB
07_hand_02.txt AC 80 ms 13260 KiB
08_sqrt_00.txt AC 139 ms 18856 KiB
08_sqrt_01.txt AC 141 ms 18780 KiB
08_sqrt_02.txt AC 141 ms 18644 KiB