#include <iostream>
#include <algorithm>
#include <vector>
#define MAXD 1000005
#define MAXP 400005
using namespace std;
struct event {int x, ylo, yhi, c, type;};
int N, M, B, P, O[MAXP][5];
vector <event> Sweep, Sweep2[MAXD];
class Segtree {
int ST[MAXD * 4][4], Lazy[MAXD * 4]; //range add, query longest sequence of 0s
bool Z[MAXD * 4]; //is everything all same
//longest running chain of min element, prefix, suffix, min
public:
void reset(int l, int r, int cur) {
ST[cur][0] = ST[cur][1] = ST[cur][2] = r-l+1;
ST[cur][3] = 0, Z[cur] = 1, Lazy[cur] = 0;
if (l != r) {
int mid = (l + r) >> 1;
reset(l, mid, 2*cur);
reset(mid+1, r, 2*cur+1);
}
}
void pushup(int cur) {
if (ST[2*cur][3] == ST[2*cur+1][3]) {
ST[cur][0] = max(ST[2*cur][0], ST[2*cur+1][0]);
ST[cur][1] = ST[2*cur][1] + (Z[2*cur] ? ST[2*cur+1][1] : 0);
ST[cur][2] = ST[2*cur+1][2] + (Z[2*cur+1] ? ST[2*cur][2] : 0);
ST[cur][0] = max(ST[cur][0], ST[2*cur][2] + ST[2*cur+1][1]);
} else if (ST[2*cur][3] > ST[2*cur+1][3]) {
ST[cur][0] = ST[2*cur+1][0];
ST[cur][1] = 0;
ST[cur][2] = ST[2*cur+1][2];
} else {
ST[cur][0] = ST[2*cur][0];
ST[cur][1] = ST[2*cur][1];
ST[cur][2] = 0;
}
ST[cur][3] = min(ST[2*cur][3], ST[2*cur+1][3]);
Z[cur] = Z[2*cur] && Z[2*cur + 1] && (ST[2*cur][3] == ST[2*cur+1][3]);
}
void pushdown(int cur, bool b) {
ST[cur][3] += Lazy[cur];
if (!b) {
Lazy[2*cur] += Lazy[cur];
Lazy[2*cur+1] += Lazy[cur];
}
Lazy[cur] = 0;
}
void upd(int val, int lo, int hi, int l, int r, int cur) {
pushdown(cur, l == r);
if (hi < l || lo > r) {return;}
if (lo <= l && hi >= r) {
Lazy[cur] += val;
pushdown(cur, l == r);
return;
} else {
int mid = (l + r) >> 1;
upd(val, lo, hi, l, mid, 2*cur);
upd(val, lo, hi, mid+1, r, 2*cur+1);
pushup(cur);
}
}
int Min() {
pushdown(1,M == 1);
return(ST[1][3]);
}
int Run() {
pushdown(1,M == 1);
return(ST[1][0]);
}
} ST;
void disp(event e) {
printf("Event: %d %d %d %d %d\n",e.x,e.ylo,e.yhi, e.c, e.type);
}
void Case1() { //B > 0
}
void Case2() {
ST.reset(1, M, 1);
for (int i=0; i<P; i++) {
Sweep2[O[i][0]].push_back({O[i][0], O[i][1], O[i][3], O[i][4], 1}); //add
Sweep2[O[i][2]].push_back({O[i][2], O[i][1], O[i][3], O[i][4], 0}); //remove
}
int pL = 1, pR = 0, Ans = 0;
while (pL <= N || pR <= N) {
//code
//printf("%d %d %d %d\n",pL,pR,ST.Min(),ST.Run());
if (ST.Min() == 0 && ST.Run() >= pR - pL + 1) {
if (pR == N) {break;}
Ans = max(Ans, pR-pL+1),pR++;
for (auto e: Sweep2[pR]) {
if (e.type) {
//disp(e);
ST.upd(1, e.ylo, e.yhi, 1, M, 1);
//printf("%d %d %d %d\n",pL,pR,ST.Min(),ST.Run());
}
}
} else {
if (pL == N) {break;}
for (auto e: Sweep2[pL]) {
if (!e.type) {
//printf("DEBUG\n");
//disp(e);
ST.upd(-1, e.ylo, e.yhi, 1, M, 1);
}
}
pL++;
}
}
printf("%d", Ans);
}
int main() {
//freopen("pyin.txt","r",stdin);
scanf("%d %d\n%d\n%d",&N,&M,&B, &P);
for (int i=0; i<P; i++) {
scanf("%d %d %d %d %d",&O[i][0], &O[i][1], &O[i][2], &O[i][3], &O[i][4]); //x1 y1 x2 y2 c
}
if (B) {Case1();}
else {Case2();}
}
Compilation message
pyramid_base.cpp: In function 'int main()':
pyramid_base.cpp:119:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d %d\n%d\n%d",&N,&M,&B, &P);
~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
pyramid_base.cpp:121:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d %d %d %d %d",&O[i][0], &O[i][1], &O[i][2], &O[i][3], &O[i][4]); //x1 y1 x2 y2 c
~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
18 ms |
23808 KB |
Output isn't correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
18 ms |
23808 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
19 ms |
23936 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
19 ms |
24576 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
24 ms |
29312 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
57 ms |
66936 KB |
Output is correct |
2 |
Correct |
56 ms |
67064 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
54 ms |
67064 KB |
Output is correct |
2 |
Correct |
57 ms |
67064 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
23 ms |
23936 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
27 ms |
24064 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
30 ms |
24184 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
32 ms |
24320 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
46 ms |
24440 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
749 ms |
82496 KB |
Output is correct |
2 |
Correct |
356 ms |
48508 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
960 ms |
89848 KB |
Output is correct |
2 |
Incorrect |
701 ms |
96664 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1165 ms |
93824 KB |
Output is correct |
2 |
Correct |
1000 ms |
107668 KB |
Output is correct |
3 |
Incorrect |
1014 ms |
107424 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |