Submission #1586684
Source Code Expand
#include <bits/stdc++.h>
#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)
#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=int(a)-1;i>=int(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)
#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define getidx(ary,key) lower_bound(_all(ary),key)-begin(ary)
#define clr(a,b) memset((a),(b),sizeof(a))
#define bit(n) (1LL<<(n))
#define popcount(n) (__builtin_popcountll(n))
using namespace std;
template<class T>bool chmax(T &a, const T &b) { return (a<b)?(a=b,1):0;}
template<class T>bool chmin(T &a, const T &b) { return (b<a)?(a=b,1):0;}
using ll=long long;
using R=long double;
const R EPS=1e-9L; // [-1000,1000]->EPS=1e-8 [-10000,10000]->EPS=1e-7
inline int sgn(const R& r){return(r > EPS)-(r < -EPS);}
inline R sq(R x){return sqrt(max(x,0.0L));}
const int dx[8]={1,0,-1,0,1,-1,-1,1};
const int dy[8]={0,1,0,-1,1,1,-1,-1};
// Problem Specific Parameter:
priority_queue<ll> lft;
priority_queue<ll,vector<ll>,greater<ll>> rht;
ll lo = 0LL, ro = 0LL;
ll ans = 0LL;
const int limit = 100010;
ll l[limit],r[limit],p[limit];
int main(void){
int n;
cin >> n;
rep(i,n){
cin >> l[i] >> r[i];
p[i] = r[i] - l[i];
}
lft.push(l[0]-lo);
rht.push(l[0]-ro);
rep(i,1,n){
lo -= p[i],ro += p[i-1];
lft.push(l[i]-lo);
rht.push(l[i]-ro);
while(lft.top() + lo > rht.top() + ro){
ll L = lft.top() + lo, R = rht.top() + ro;
lft.pop(),rht.pop();
ans += L - R;
lft.push(R - lo), rht.push(L - ro);
}
}
cout << ans << endl;
return 0;
}
Submission Info
Submission Time |
|
Task |
E - NarrowRectangles |
User |
Hec |
Language |
C++14 (GCC 5.4.1) |
Score |
1000 |
Code Size |
1837 Byte |
Status |
AC |
Exec Time |
102 ms |
Memory |
4340 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 |
76 ms |
4340 KB |
2_019.txt |
AC |
71 ms |
4340 KB |
2_020.txt |
AC |
67 ms |
4340 KB |
2_021.txt |
AC |
95 ms |
4340 KB |
2_022.txt |
AC |
101 ms |
4340 KB |
2_023.txt |
AC |
95 ms |
4340 KB |
2_024.txt |
AC |
96 ms |
4340 KB |
2_025.txt |
AC |
95 ms |
4340 KB |
2_026.txt |
AC |
95 ms |
4340 KB |
2_027.txt |
AC |
95 ms |
4340 KB |
2_028.txt |
AC |
95 ms |
4340 KB |
2_029.txt |
AC |
100 ms |
4340 KB |
2_030.txt |
AC |
95 ms |
4340 KB |
2_031.txt |
AC |
102 ms |
4340 KB |
2_032.txt |
AC |
102 ms |
4340 KB |
2_033.txt |
AC |
102 ms |
4340 KB |
2_034.txt |
AC |
102 ms |
4340 KB |
2_035.txt |
AC |
92 ms |
4340 KB |
2_036.txt |
AC |
86 ms |
4340 KB |