Submission #1230816
Source Code Expand
/*
СТРОИМ СТЕНУ РАБОТЯГИ!
█▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀█
█═╩═╦═╩═╦═╩═╦═╩═╦═╩═╦═╩═╦═╩═█
█═╦═╩═╦═╩═╦═╩═╦═╩═╦═╩═╦═╩═╦═█
█═╩═╦═╩═╦═╩═╦═╩═╦═╩═╦═╩═╦═╩═█
█═╦═╩═╦═╩═╦═╩═╦═╩═╦═╩═╦═╩═╦═█
█═╩═╦═╩═╦═╩═╦═╩═╦═╩═╦═╩═╦═╩═█
█═╦═╩═╦═╩═╦═╩═╦═╩═╦═╩═╦═╩═╦═█
█═╩═╦═╩═╦═╩═╦═╩═╦═╩═╦═╩═╦═╩═█
█═╦═╩═╦═╩═╦═╩═╦═╩═╦═╩═╦═╩═╦═█
█▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄█
*/
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <numeric>
#include <cstring>
#include <ctime>
#include <cstdlib>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <cmath>
#include <bitset>
#include <cassert>
#include <queue>
#include <stack>
#include <deque>
using namespace std;
template<typename T1, typename T2>inline void chkmin(T1 &x, T2 y) { if (x > y) x = y; }
template<typename T1, typename T2>inline void chkmax(T1 &x, T2 y) { if (x < y) x = y; }
/** Interface */
inline int readChar();
template <class T = int> inline T readInt();
template <class T> inline void writeInt( T x, char end = 0 );
inline void writeChar( int x );
inline void writeWord( const char *s );
/** Read */
static const int buf_size = 4096;
inline int getChar() {
static char buf[buf_size];
static int len = 0, pos = 0;
if (pos == len) {
pos = 0, len = fread(buf, 1, buf_size, stdin);
}
if (pos == len) {
return -1;
}
return buf[pos++];
}
inline int readChar() {
int c = getChar();
while (c <= 32) {
c = getChar();
}
return c;
}
template <class T>
inline T readInt() {
int s = 1, c = readChar();
T x = 0;
if (c == '-')
s = -1, c = getChar();
while ('0' <= c && c <= '9')
x = x * 10 + c - '0', c = getChar();
return s == 1 ? x : -x;
}
/** Write */
static int write_pos = 0;
static char write_buf[buf_size];
inline void writeChar( int x ) {
if (write_pos == buf_size)
fwrite(write_buf, 1, buf_size, stdout), write_pos = 0;
write_buf[write_pos++] = x;
}
template <class T>
inline void writeInt( T x, char end ) {
if (x < 0)
writeChar('-'), x = -x;
char s[24];
int n = 0;
while (x || !n)
s[n++] = '0' + x % 10, x /= 10;
while (n--)
writeChar(s[n]);
if (end)
writeChar(end);
}
inline void writeWord( const char *s ) { while (*s)
writeChar(*s++); }
struct Flusher {
~Flusher() {
if (write_pos)
fwrite(write_buf, 1, write_pos, stdout), write_pos = 0;
}
} flusher;
using namespace std;
#define sz(c) (int)(c).size()
#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
#define left left228
#define right right228
#define rank rank228
#define L(__) (__ << 1)
#define R(__) (L(__)|1)
#define LL long long
#define oo (1<<30)
#define N 300005
int st1[N],top1,st2[N],top2;
int n,w,h,m,z[N],ans,A[4*N],add[4*N];
struct dot{
int x,y;
dot(int _x=0,int _y=0){ x=_x,y=_y;}
}a[N],b[N];
bool cmp(const dot &p,const dot &q){ return p.x<q.x||(p.x==q.x&&p.y<q.y);}
int find(int x) {
return lower_bound(z + 1, z + m + 1, x) - z;
}
void update(int t){
A[t] = max(A[L(t)], A[R(t)]);
}
void build(int t, int l, int r) {
int mid = (l + r) >> 1;
add[t] = 0;
if (l == r) {
A[t] = -z[l];
return;
}
build(L(t), l, mid);
build(R(t), mid + 1, r);
update(t);
}
void Add(int t, int d) {
add[t] += d;
A[t] += d;
}
void push(int t) {
if (add[t] == 0) {
return;
}
Add(L(t), add[t]);
Add(R(t), add[t]);
add[t] = 0;
}
void modify(int t, int l, int r, int l1, int r1, int d) {
int mid = (l + r) >> 1;
if (l > r1 || r < l1 || l1 > r1) {
return;
}
if (l >= l1 && r <= r1) {
return Add(t, d);
}
push(t);
modify(L(t), l, mid, l1, r1, d);
modify(R(t), mid + 1, r, l1, r1, d);
update(t);
}
void solve() {
int mid = (h >> 1);
for (int i = 1; i <= n; i++) {
a[i] = b[i];
}
sort(a + 1,a + n + 1,cmp);
if (a[n].x < w) {
a[++n] = dot(w, 0);
}
top1 = top2 = 0;
for (int i = 1; i <= n; i++) {
z[i] = a[i].x;
}
m = n, z[++m] = 0, z[++m] = w;
sort(z + 1, z + m + 1);
m = unique(z + 1, z + m + 1) - z - 1;
for (int i = 1; i <= n; i++) {
a[i].x = find(a[i].x);
}
build(1, 1, m);
if (a[1].x > 1) {
modify(1, 1, m, 1, 1, h);
}
a[0].x = 1;
for (int i = 1; i <= n; i++) {
if (a[i].y <= mid) {
modify(1, 1, m, a[i].x, a[i].x, h);
chkmax(ans, A[1] + z[a[i].x]);
modify(1, 1, m, a[st1[top1]].x, a[i].x - 1, -a[i].y);
while (top1 && a[st1[top1]].y <= a[i].y) {
modify(1, 1, m, a[st1[top1 - 1]].x, a[st1[top1]].x - 1, a[st1[top1]].y - a[i].y);
top1--;
}
st1[++top1] = i;
} else {
modify(1, 1, m, a[i].x, a[i].x, h);
chkmax(ans, A[1] + z[a[i].x]);
modify(1, 1, m, a[st2[top2]].x,a[i].x - 1, a[i].y - h);
while (top2 && a[st2[top2]].y >= a[i].y) {
modify(1, 1, m, a[st2[top2 - 1]].x,a[st2[top2]].x - 1, a[i].y - a[st2[top2]].y);
top2--;
}
st2[++top2] = i;
}
}
}
int main() {
w = readInt(), h = readInt(), n = readInt();
for (int i = 1; i <= n; i++) {
b[i].x = readInt(), b[i].y = readInt();
}
solve();
for (int i = 1; i <= n; i++) {
swap(b[i].x, b[i].y);
}
swap(w, h);
solve();
cout << ans * 2LL << endl;
return 0;
}
Submission Info
Submission Time |
|
Task |
F - Snuke's Coloring 2 |
User |
EgorLifar |
Language |
C++14 (GCC 5.4.1) |
Score |
0 |
Code Size |
6507 Byte |
Status |
WA |
Exec Time |
587 ms |
Memory |
16896 KB |
Judge Result
Set Name |
sample |
All |
Score / Max Score |
0 / 0 |
0 / 1600 |
Status |
|
|
Set Name |
Test Cases |
sample |
sample_01.txt, sample_02.txt, sample_03.txt, sample_04.txt |
All |
dia_01.txt, dia_02.txt, dia_03.txt, dia_04.txt, dial_01.txt, dial_02.txt, dial_03.txt, dial_04.txt, dial_05.txt, dial_06.txt, dialr_01.txt, dialr_02.txt, dialr_03.txt, dialr_04.txt, diar_01.txt, diar_02.txt, diar_03.txt, hand_01.txt, hand_02.txt, hand_03.txt, hand_04.txt, hand_05.txt, poc_t_1.txt, poc_t_2.txt, poc_t_3.txt, poc_t_4.txt, poc_t_5.txt, poc_w_1.txt, poc_w_2.txt, random0_01.txt, random0_02.txt, random0_03.txt, random1_01.txt, random1_02.txt, random1_03.txt, random1_04.txt, random1_05.txt, random1_06.txt, random1_07.txt, rect_01.txt, rect_02.txt, rect_03.txt, rect_04.txt, rect_05.txt, rect_06.txt, rect_07.txt, rect_08.txt, rect_09.txt, rect_10.txt, sample_01.txt, sample_02.txt, sample_03.txt, sample_04.txt, x_01.txt, x_02.txt, x_03.txt, x_04.txt |
Case Name |
Status |
Exec Time |
Memory |
dia_01.txt |
WA |
584 ms |
16896 KB |
dia_02.txt |
WA |
582 ms |
16896 KB |
dia_03.txt |
WA |
584 ms |
16896 KB |
dia_04.txt |
WA |
583 ms |
16896 KB |
dial_01.txt |
AC |
584 ms |
16896 KB |
dial_02.txt |
AC |
584 ms |
16896 KB |
dial_03.txt |
AC |
587 ms |
16896 KB |
dial_04.txt |
AC |
586 ms |
16896 KB |
dial_05.txt |
AC |
585 ms |
16896 KB |
dial_06.txt |
AC |
585 ms |
16896 KB |
dialr_01.txt |
AC |
547 ms |
16640 KB |
dialr_02.txt |
AC |
552 ms |
16640 KB |
dialr_03.txt |
AC |
550 ms |
16640 KB |
dialr_04.txt |
AC |
549 ms |
16640 KB |
diar_01.txt |
AC |
585 ms |
16896 KB |
diar_02.txt |
AC |
587 ms |
16896 KB |
diar_03.txt |
AC |
587 ms |
16896 KB |
hand_01.txt |
AC |
4 ms |
12544 KB |
hand_02.txt |
WA |
4 ms |
12544 KB |
hand_03.txt |
AC |
4 ms |
12544 KB |
hand_04.txt |
AC |
4 ms |
12544 KB |
hand_05.txt |
AC |
4 ms |
12544 KB |
poc_t_1.txt |
AC |
4 ms |
12544 KB |
poc_t_2.txt |
AC |
4 ms |
12544 KB |
poc_t_3.txt |
AC |
4 ms |
12544 KB |
poc_t_4.txt |
WA |
4 ms |
12544 KB |
poc_t_5.txt |
AC |
4 ms |
12544 KB |
poc_w_1.txt |
AC |
4 ms |
12544 KB |
poc_w_2.txt |
AC |
4 ms |
12544 KB |
random0_01.txt |
AC |
551 ms |
16640 KB |
random0_02.txt |
AC |
549 ms |
16640 KB |
random0_03.txt |
AC |
551 ms |
16640 KB |
random1_01.txt |
AC |
549 ms |
16640 KB |
random1_02.txt |
WA |
549 ms |
16640 KB |
random1_03.txt |
AC |
550 ms |
16640 KB |
random1_04.txt |
AC |
549 ms |
16640 KB |
random1_05.txt |
AC |
560 ms |
16640 KB |
random1_06.txt |
WA |
548 ms |
16640 KB |
random1_07.txt |
AC |
546 ms |
16640 KB |
rect_01.txt |
AC |
547 ms |
16640 KB |
rect_02.txt |
AC |
550 ms |
16640 KB |
rect_03.txt |
WA |
549 ms |
16640 KB |
rect_04.txt |
AC |
543 ms |
16640 KB |
rect_05.txt |
AC |
544 ms |
16640 KB |
rect_06.txt |
AC |
540 ms |
16640 KB |
rect_07.txt |
WA |
550 ms |
16640 KB |
rect_08.txt |
AC |
547 ms |
16640 KB |
rect_09.txt |
WA |
549 ms |
16640 KB |
rect_10.txt |
WA |
548 ms |
16640 KB |
sample_01.txt |
AC |
4 ms |
12544 KB |
sample_02.txt |
AC |
4 ms |
12544 KB |
sample_03.txt |
AC |
4 ms |
12544 KB |
sample_04.txt |
AC |
4 ms |
12544 KB |
x_01.txt |
AC |
454 ms |
16896 KB |
x_02.txt |
AC |
454 ms |
16896 KB |
x_03.txt |
AC |
454 ms |
16896 KB |
x_04.txt |
AC |
456 ms |
16896 KB |