#include <bits/stdc++.h>
#define left_son (node<<1)
#define right_son ((node<<1)|1)
#define mid ((st+dr)>>1)
using namespace std;
const int Nmax = 1e6 + 5;
int n, N, M, money;
vector< pair<int,int> > start[Nmax], finish[Nmax];
class SegmentTree
{
int lazy[Nmax<<2], L[Nmax<<2], R[Nmax<<2], best[Nmax<<2], mn[Nmax<<2];
public:
void update(int node, int st, int dr, int Left, int Right, int add)
{
if(Left<=st && dr<=Right)
{
mn[node] += add;
lazy[node] += add;
return;
}
if(lazy[node])
{
lazy[left_son] += lazy[node];
lazy[right_son] += lazy[node];
mn[left_son] += lazy[node];
mn[right_son] += lazy[node];
lazy[node] = 0;
}
if(Left<=mid) update(left_son, st, mid, Left, Right, add);
if(mid<Right) update(right_son, mid+1, dr, Left, Right, add);
mn[node] = min(mn[left_son], mn[right_son]);
if(mn[left_son] == mn[right_son])
{
L[node] = L[left_son] + (L[left_son] == mid-st+1 ? L[right_son] : 0);
R[node] = R[right_son] + (R[right_son] == dr-mid ? R[left_son] : 0);
best[node] = max(best[left_son], best[right_son]);
best[node] = max(best[node], R[left_son] + L[right_son]);
}
else if(mn[node] == mn[left_son])
{
L[node] = L[left_son];
R[node] = 0;
best[node] = best[left_son];
}
else
{
L[node] = 0;
R[node] = R[right_son];
best[node] = best[right_son];
}
}
int query()
{
return mn[1] == 0 ? best[1] : 0;
}
void build(int node, int st, int dr)
{
mn[node] = lazy[node] = 0;
L[node] = R[node] = best[node] = dr-st+1;
if(st == dr) return;
build(left_son, st, mid);
build(right_son, mid+1, dr);
}
} aint;
void solve0()
{
int i, j, X1, Y1, X2, Y2, C;
int ans = 0;
aint.build(1, 1, M);
for(i=1; i<=n; ++i)
{
cin >> X1 >> Y1 >> X2 >> Y2 >> C;
start[X1].push_back({Y1, Y2});
finish[X2].push_back({Y1, Y2});
}
j = 0;
for(i=1; i<=N; ++i)
if(i==1 || !finish[i-1].empty())
{
for(auto e : finish[i-1])
aint.update(1, 1, M, e.first, e.second, -1);
while(j+1 <= N && aint.query() >= j-i+1)
{
++j;
for(auto e : start[j])
aint.update(1, 1, M, e.first, e.second, 1);
}
if(j == N)
{
ans = max(ans, N-i+1);
break;
}
ans = max(ans, j-i);
}
cout << ans << '\n';
}
int main()
{
// freopen("input", "r", stdin);
// freopen("output", "w", stdout);
cin.sync_with_stdio(false);
cin >> N >> M >> money >> n;
if(!money) solve0(); /// subtask 1 + 3
// else solve(); /// subtask 2
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
44 ms |
47352 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
45 ms |
47360 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
50 ms |
47500 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
46 ms |
48060 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
63 ms |
52540 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
112 ms |
88624 KB |
Output is correct |
2 |
Correct |
108 ms |
88764 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
105 ms |
88764 KB |
Output is correct |
2 |
Correct |
107 ms |
88764 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
43 ms |
88764 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
42 ms |
88764 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
40 ms |
88764 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
42 ms |
88764 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
42 ms |
88764 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1054 ms |
100044 KB |
Output is correct |
2 |
Correct |
433 ms |
100044 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1448 ms |
105048 KB |
Output is correct |
2 |
Correct |
1600 ms |
109812 KB |
Output is correct |
3 |
Incorrect |
696 ms |
109812 KB |
Output isn't correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1894 ms |
120444 KB |
Output is correct |
2 |
Correct |
2521 ms |
120444 KB |
Output is correct |
3 |
Correct |
2871 ms |
120444 KB |
Output is correct |
4 |
Correct |
1903 ms |
120444 KB |
Output is correct |
5 |
Correct |
1233 ms |
120444 KB |
Output is correct |