Submission #9664138
Source Code Expand
#include <iostream> #include <algorithm> #include <cstring> #include <cstdio> #include <queue> using namespace std; #define LL long long const int N=1e5+50; int n,L[N],R[N]; LL ans,tl,tr,lq,rq; priority_queue < LL,vector<LL>,less<LL> > Left; priority_queue < LL,vector<LL>,greater<LL> > Right; template<typename elemType> inline void Read(elemType &T){ elemType X=0,w=0; char ch=0; while(!isdigit(ch)) {w|=ch=='-';ch=getchar();} while(isdigit(ch)) X=(X<<3)+(X<<1)+(ch^48),ch=getchar(); T=(w?-X:X); } int main() { Read(n); for(register int i=1;i<=n;++i){ Read(L[i]);Read(R[i]); L[i]=R[i]-L[i]; } Left.push(R[1]); Right.push(R[1]); for(register int i=2;i<=n;++i){ tl-=L[i-1]; tr+=L[i]; lq=Left.top()+tl; rq=Right.top()+tr; if(lq<=R[i] && R[i]<=rq){ Left.push(R[i]-tl); Right.push(R[i]-tr); } else if(R[i]>=lq){ ans+=R[i]-rq; Right.pop(); Left.push(rq-tl); Right.push(R[i]-tr); Right.push(R[i]-tr); } else{ ans+=lq-R[i]; Left.pop(); Right.push(lq-tr); Left.push(R[i]-tl); Left.push(R[i]-tl); } } cout<<ans<<endl; return 0; }
Submission Info
Submission Time | |
---|---|
Task | E - NarrowRectangles |
User | Contna |
Language | C++ (GCC 5.4.1) |
Score | 1000 |
Code Size | 1383 Byte |
Status | AC |
Exec Time | 31 ms |
Memory | 2804 KB |
Judge Result
Set Name | Sample | Subtask | All | ||||||
---|---|---|---|---|---|---|---|---|---|
Score / Max Score | 0 / 0 | 300 / 300 | 700 / 700 | ||||||
Status |
|
|
|
Set Name | Test Cases |
---|---|
Sample | 0_000.txt, 0_001.txt, 0_002.txt, 0_003.txt, 0_004.txt |
Subtask | 0_000, 0_001, 0_004, 1_005.txt, 1_006.txt, 1_007.txt, 1_008.txt, 1_009.txt, 1_010.txt, 1_011.txt, 1_012.txt, 1_013.txt, 1_014.txt, 1_015.txt, 1_016.txt, 1_017.txt |
All | 0_000.txt, 0_001.txt, 0_002.txt, 0_003.txt, 0_004.txt, 1_005.txt, 1_006.txt, 1_007.txt, 1_008.txt, 1_009.txt, 1_010.txt, 1_011.txt, 1_012.txt, 1_013.txt, 1_014.txt, 1_015.txt, 1_016.txt, 1_017.txt, 2_018.txt, 2_019.txt, 2_020.txt, 2_021.txt, 2_022.txt, 2_023.txt, 2_024.txt, 2_025.txt, 2_026.txt, 2_027.txt, 2_028.txt, 2_029.txt, 2_030.txt, 2_031.txt, 2_032.txt, 2_033.txt, 2_034.txt, 2_035.txt, 2_036.txt |
Case Name | Status | Exec Time | Memory |
---|---|---|---|
0_000.txt | AC | 1 ms | 256 KB |
0_001.txt | AC | 1 ms | 256 KB |
0_002.txt | AC | 1 ms | 256 KB |
0_003.txt | AC | 1 ms | 256 KB |
0_004.txt | AC | 1 ms | 256 KB |
1_005.txt | AC | 1 ms | 256 KB |
1_006.txt | AC | 1 ms | 256 KB |
1_007.txt | AC | 1 ms | 256 KB |
1_008.txt | AC | 1 ms | 256 KB |
1_009.txt | AC | 1 ms | 256 KB |
1_010.txt | AC | 1 ms | 256 KB |
1_011.txt | AC | 1 ms | 256 KB |
1_012.txt | AC | 1 ms | 256 KB |
1_013.txt | AC | 1 ms | 256 KB |
1_014.txt | AC | 1 ms | 256 KB |
1_015.txt | AC | 1 ms | 256 KB |
1_016.txt | AC | 1 ms | 256 KB |
1_017.txt | AC | 1 ms | 256 KB |
2_018.txt | AC | 22 ms | 2804 KB |
2_019.txt | AC | 20 ms | 2804 KB |
2_020.txt | AC | 19 ms | 2804 KB |
2_021.txt | AC | 29 ms | 2756 KB |
2_022.txt | AC | 29 ms | 2712 KB |
2_023.txt | AC | 29 ms | 2708 KB |
2_024.txt | AC | 29 ms | 2752 KB |
2_025.txt | AC | 29 ms | 2708 KB |
2_026.txt | AC | 29 ms | 2804 KB |
2_027.txt | AC | 29 ms | 2804 KB |
2_028.txt | AC | 29 ms | 2752 KB |
2_029.txt | AC | 29 ms | 2756 KB |
2_030.txt | AC | 29 ms | 2772 KB |
2_031.txt | AC | 31 ms | 2756 KB |
2_032.txt | AC | 31 ms | 2772 KB |
2_033.txt | AC | 31 ms | 2740 KB |
2_034.txt | AC | 31 ms | 2744 KB |
2_035.txt | AC | 27 ms | 2804 KB |
2_036.txt | AC | 24 ms | 2804 KB |