Submission #1967081
Source Code Expand
//84104971101048411497 - Can you guess what does this mean?
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef complex<double> point;
#define mapii map<int, int>
#define debug(a) cout << #a << ": " << a << endl
#define debuga1(a, l, r) fto(i, l, r) cout << a[i] << " "; cout << endl
#define fdto(i, r, l) for(int i = (r); i >= (l); --i)
#define fto(i, l, r) for(int i = (l); i <= (r); ++i)
#define forit(it, var) for(__typeof(var.begin()) it = var.begin(); it != var.end(); it++)
#define forrit(rit, var) for(__typeof(var.rbegin()) rit = var.rbegin(); rit != var.rend(); rit++)
#define ii pair<int, int>
#define iii pair<int, ii>
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define maxN 2005
#define oo 1000000000000000007LL
#define sz(a) (int)a.size()
#define left aofnojaef
#define right aionfeoangrou
const double PI = acos(-1.0);
double fRand(double fMin, double fMax)
{
double f = (double)rand() / RAND_MAX;
return fMin + f * (fMax - fMin);
}
template <class T>
T min(T a, T b, T c) {
return min(a, min(b, c));
}
template <class T>
T max(T a, T b, T c) {
return max(a, max(b, c));
}
template<typename T>
struct slopeQueue {
private:
T pq;
ll delta;
public:
void push(ll x) {pq.push(x-delta);}
void update(ll x) {delta += x;}
ll top() {return pq.top() + delta;}
void pop() {pq.pop();}
void print() {
T tmp = pq;
while (!tmp.empty()) {
cout << tmp.top() + delta << " ";
tmp.pop();
}
cout << endl;
}
};
ll cost(ll l, ll r, ll x) {
if (x < l) return l-x;
if (x > r) return x-r;
return 0;
}
int main () {
int n; scanf("%d", &n);
vector<int> l(n), r(n);
fto(i, 0, n-1) scanf("%d%d", &l[i], &r[i]);
slopeQueue<priority_queue<ll> > left;
slopeQueue<priority_queue<ll, vector<ll>, greater<ll> > > right;
left.push(l[0]);
right.push(l[0]);
ll ans = 0;
fto(i, 1, n-1) {
left.update(l[i]-r[i]);
right.update(r[i-1]-l[i-1]);
ans += cost(left.top(), right.top(), l[i]);
left.push(l[i]);
right.push(l[i]);
while (left.top() > right.top()) {
ll x = left.top(); left.pop();
ll y = right.top(); right.pop();
left.push(y); right.push(x);
}
}
cout << ans;
return 0;
}
Submission Info
Submission Time |
|
Task |
E - NarrowRectangles |
User |
xuanquang1999 |
Language |
C++14 (GCC 5.4.1) |
Score |
1000 |
Code Size |
2484 Byte |
Status |
AC |
Exec Time |
44 ms |
Memory |
2804 KB |
Compile Error
./Main.cpp: In function ‘int main()’:
./Main.cpp:72:27: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
int n; scanf("%d", &n);
^
./Main.cpp:74:47: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
fto(i, 0, n-1) scanf("%d%d", &l[i], &r[i]);
^
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 |
33 ms |
2804 KB |
2_019.txt |
AC |
32 ms |
2804 KB |
2_020.txt |
AC |
26 ms |
2804 KB |
2_021.txt |
AC |
37 ms |
2804 KB |
2_022.txt |
AC |
37 ms |
2804 KB |
2_023.txt |
AC |
37 ms |
2804 KB |
2_024.txt |
AC |
37 ms |
2804 KB |
2_025.txt |
AC |
37 ms |
2804 KB |
2_026.txt |
AC |
37 ms |
2804 KB |
2_027.txt |
AC |
37 ms |
2804 KB |
2_028.txt |
AC |
37 ms |
2804 KB |
2_029.txt |
AC |
37 ms |
2804 KB |
2_030.txt |
AC |
37 ms |
2804 KB |
2_031.txt |
AC |
44 ms |
2804 KB |
2_032.txt |
AC |
44 ms |
2804 KB |
2_033.txt |
AC |
44 ms |
2804 KB |
2_034.txt |
AC |
44 ms |
2804 KB |
2_035.txt |
AC |
35 ms |
2804 KB |
2_036.txt |
AC |
29 ms |
2804 KB |