Submission #42209585
Source Code Expand
#include<cstdio>
#include<cstring>
#include<algorithm>
#define N 210000
#define M 410000
#define MM 810000
#define fep(i,x,y) for(int i=x;i<=y;i++)
#define feq(i,x,y) for(int i=x;i>=y;i--)
using namespace std;
typedef long long LL;
template<class T>
inline T mymin(T x,T y){return x<y?x:y;}
template<class T>
inline T mymax(T x,T y){return x>y?x:y;}
struct node{
int lc,rc;
LL k1,k2;
}tr[MM];int len;
inline void updata(int x){
tr[x].k1=mymax(tr[tr[x].lc].k1,tr[tr[x].rc].k1);
tr[x].k2=mymax(tr[tr[x].lc].k2,tr[tr[x].rc].k2);
}
void bt(int l,int r){
int x=++len;
tr[x].k1=tr[x].k2=-999999999;
if(l<r){
int mid=(l+r)>>1;
tr[x].lc=len+1;bt(l,mid);
tr[x].rc=len+1;bt(mid+1,r);
}
}
LL findans(int x,int l,int r,int ll,int rr,int type){
if(r<ll || l>rr)return -999999999;
if(ll<=l && rr>=r)return type==1?tr[x].k1:tr[x].k2;
int mid=(l+r)>>1;
return mymax(findans(tr[x].lc,l,mid,ll,rr,type),findans(tr[x].rc,mid+1,r,ll,rr,type));
}
void change(int x,int l,int r,int id,LL k,int type){
if(l==r){
if(type==1)tr[x].k1=mymax(tr[x].k1,k);
else tr[x].k2=mymax(tr[x].k2,k);
return ;
}
int mid=(l+r)>>1;
if(id<=mid)change(tr[x].lc,l,mid,id,k,type);
else change(tr[x].rc,mid+1,r,id,k,type);
updata(x);
}
int a[N],b[N],*id[M],n,m,be[M];
inline bool cmp(int *x,int *y){return (*x)<(*y);}
int main(){
scanf("%d",&n);
fep(i,1,n){
scanf("%d%d",&a[i],&b[i]);
id[i]=&a[i];id[i+n]=&b[i];
}
sort(id+1,id+n+n+1,cmp);
m=1;
fep(i,1,n+n){
if((*id[i])!=be[m])be[++m]=(*id[i]);
(*id[i])=m;
}
bt(1,m);
change(1,1,m,1,0,1);
LL zans=0;
fep(i,1,n){
LL ans=mymax(findans(1,1,m,1,a[i]-1,1)+be[b[i]]-be[a[i]]+1,findans(1,1,m,a[i],b[i],2)+be[b[i]]);
change(1,1,m,b[i],ans,1);
change(1,1,m,b[i],ans-be[b[i]],2);
zans=mymax(zans,ans);
}
printf("%lld\n",zans);
return 0;
}
Submission Info
| Submission Time |
|
| Task |
D - LIS 2 |
| User |
juruozjj |
| Language |
C++ (GCC 9.2.1) |
| Score |
600 |
| Code Size |
1865 Byte |
| Status |
AC |
| Exec Time |
356 ms |
| Memory |
26716 KiB |
Compile Error
./Main.cpp: In function ‘int main()’:
./Main.cpp:52:7: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
52 | scanf("%d",&n);
| ~~~~~^~~~~~~~~
./Main.cpp:54:8: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
54 | scanf("%d%d",&a[i],&b[i]);
| ~~~~~^~~~~~~~~~~~~~~~~~~~
Judge Result
| Set Name |
Sample |
All |
| Score / Max Score |
0 / 0 |
600 / 600 |
| Status |
|
|
| 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 |
5 ms |
1676 KiB |
| 00_sample_01.txt |
AC |
1 ms |
1732 KiB |
| 00_sample_02.txt |
AC |
1 ms |
1632 KiB |
| 01_srnd_00.txt |
AC |
2 ms |
1628 KiB |
| 01_srnd_01.txt |
AC |
1 ms |
1640 KiB |
| 01_srnd_02.txt |
AC |
1 ms |
1660 KiB |
| 01_srnd_03.txt |
AC |
1 ms |
1692 KiB |
| 01_srnd_04.txt |
AC |
1 ms |
1676 KiB |
| 01_srnd_05.txt |
AC |
1 ms |
1736 KiB |
| 01_srnd_06.txt |
AC |
1 ms |
1680 KiB |
| 01_srnd_07.txt |
AC |
1 ms |
1660 KiB |
| 01_srnd_08.txt |
AC |
1 ms |
1732 KiB |
| 01_srnd_09.txt |
AC |
1 ms |
1732 KiB |
| 02_rnd_00.txt |
AC |
183 ms |
15684 KiB |
| 02_rnd_01.txt |
AC |
164 ms |
15332 KiB |
| 02_rnd_02.txt |
AC |
199 ms |
17680 KiB |
| 02_rnd_03.txt |
AC |
356 ms |
25564 KiB |
| 02_rnd_04.txt |
AC |
324 ms |
23720 KiB |
| 02_rnd_05.txt |
AC |
318 ms |
24820 KiB |
| 02_rnd_06.txt |
AC |
254 ms |
20844 KiB |
| 02_rnd_07.txt |
AC |
253 ms |
19876 KiB |
| 02_rnd_08.txt |
AC |
259 ms |
20412 KiB |
| 02_rnd_09.txt |
AC |
285 ms |
22888 KiB |
| 03_fixlen_00.txt |
AC |
297 ms |
26624 KiB |
| 03_fixlen_01.txt |
AC |
300 ms |
26672 KiB |
| 03_fixlen_02.txt |
AC |
325 ms |
26624 KiB |
| 03_fixlen_03.txt |
AC |
319 ms |
26716 KiB |
| 03_fixlen_04.txt |
AC |
310 ms |
26636 KiB |
| 03_fixlen_05.txt |
AC |
291 ms |
26664 KiB |
| 03_fixlen_06.txt |
AC |
316 ms |
26664 KiB |
| 03_fixlen_07.txt |
AC |
296 ms |
26700 KiB |
| 04_sorted_00.txt |
AC |
213 ms |
16568 KiB |
| 04_sorted_01.txt |
AC |
215 ms |
16564 KiB |
| 04_sorted_02.txt |
AC |
209 ms |
16488 KiB |
| 04_sorted_03.txt |
AC |
213 ms |
16528 KiB |
| 05_max_00.txt |
AC |
63 ms |
6324 KiB |
| 05_max_01.txt |
AC |
168 ms |
16472 KiB |
| 05_max_02.txt |
AC |
184 ms |
16528 KiB |
| 05_max_03.txt |
AC |
209 ms |
16496 KiB |
| 05_max_04.txt |
AC |
188 ms |
16468 KiB |
| 06_one_00.txt |
AC |
1 ms |
1684 KiB |
| 06_one_01.txt |
AC |
1 ms |
1636 KiB |
| 07_hand_00.txt |
AC |
167 ms |
11492 KiB |
| 07_hand_01.txt |
AC |
165 ms |
11440 KiB |
| 07_hand_02.txt |
AC |
175 ms |
11468 KiB |
| 08_sqrt_00.txt |
AC |
158 ms |
8012 KiB |
| 08_sqrt_01.txt |
AC |
157 ms |
7940 KiB |
| 08_sqrt_02.txt |
AC |
158 ms |
7920 KiB |