#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include "wall.h"
using namespace std;
const int MAX_POS = 2e6;
const int TAILLE_MAX = 1e5 + 1;
const int MAX_NOEUD = 1 << 22;
const int MID = 1 << 21;
const int RACINE = 1;
pair<int, int> lazy[MAX_NOEUD];
int hauteursFinales[MAX_POS];
void propage(int noeud)
{
for(int nxtNoeud = noeud * 2; nxtNoeud <= noeud * 2 + 1; nxtNoeud++)
{
lazy[nxtNoeud].first = max(lazy[nxtNoeud].first, lazy[noeud].first);
lazy[nxtNoeud].first = min(lazy[nxtNoeud].first, lazy[noeud].second);
lazy[nxtNoeud].second = min(lazy[nxtNoeud].second, lazy[noeud].second);
lazy[nxtNoeud].second = max(lazy[nxtNoeud].second, lazy[noeud].first);
}
lazy[noeud].first = 0;
lazy[noeud].second = MAX_POS;
}
void update(int noeud, int curDeb, int curFin, int deb, int fin, int tp, int val)
{
if(curDeb > fin || curFin < deb)
{
return;
}
if(curDeb >= deb && curFin <= fin)
{
if(tp == 1)
{
lazy[noeud].first = max(lazy[noeud].first, val);
lazy[noeud].second = max(lazy[noeud].second, val);
}
else
{
lazy[noeud].second = min(lazy[noeud].second, val);
lazy[noeud].first = min(lazy[noeud].first, val);
}
return;
}
if(curDeb == curFin)
{
return;
}
propage(noeud);
int mid = (curDeb + curFin) / 2;
update(noeud * 2, curDeb, mid, deb, fin, tp, val);
update(noeud * 2 + 1, mid + 1, curFin, deb, fin, tp, val);
}
void get_Hauteurs_Finales(int noeud, int deb, int fin, int n, int maxi)
{
//cout << noeud << " " << deb << " " << fin << " " << lazy[noeud].first << " " << lazy[noeud].second << endl;
if(lazy[noeud].first <= lazy[noeud].second)
{
maxi = max(maxi, lazy[noeud].first);
}
if(deb == fin || deb > n)
{
if(deb < n)
{
hauteursFinales[deb] = maxi;
}
return;
}
propage(noeud);
int mid = (deb + fin) / 2;
get_Hauteurs_Finales(noeud * 2, deb, mid, n, maxi);
get_Hauteurs_Finales(noeud * 2 + 1, mid + 1, fin, n, maxi);
}
void buildWall(int n, int k, int op[], int left[], int right[], int height[], int finalHeight[])
{
for(int i = 0; i < MAX_NOEUD; i++)
{
lazy[i].first = 0;
lazy[i].second = MAX_POS;
}
for(int i = 0; i < k; i++)
{
update(1, 0, MID - 1, left[i], right[i], op[i], height[i]);
}
get_Hauteurs_Finales(1, 0, MID - 1, n, 0);
for(int i = 0; i < n; i++)
{
finalHeight[i] = hauteursFinales[i];
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
23 ms |
33152 KB |
Output is correct |
2 |
Correct |
27 ms |
33280 KB |
Output is correct |
3 |
Correct |
24 ms |
33280 KB |
Output is correct |
4 |
Correct |
30 ms |
33408 KB |
Output is correct |
5 |
Correct |
27 ms |
33408 KB |
Output is correct |
6 |
Correct |
27 ms |
33408 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
22 ms |
33152 KB |
Output is correct |
2 |
Correct |
318 ms |
46940 KB |
Output is correct |
3 |
Correct |
218 ms |
40568 KB |
Output is correct |
4 |
Correct |
560 ms |
51660 KB |
Output is correct |
5 |
Correct |
382 ms |
52652 KB |
Output is correct |
6 |
Correct |
359 ms |
51320 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
25 ms |
33152 KB |
Output is correct |
2 |
Correct |
25 ms |
33280 KB |
Output is correct |
3 |
Correct |
24 ms |
33272 KB |
Output is correct |
4 |
Correct |
29 ms |
33532 KB |
Output is correct |
5 |
Correct |
29 ms |
33400 KB |
Output is correct |
6 |
Correct |
29 ms |
33408 KB |
Output is correct |
7 |
Correct |
23 ms |
33152 KB |
Output is correct |
8 |
Correct |
320 ms |
46840 KB |
Output is correct |
9 |
Correct |
217 ms |
40440 KB |
Output is correct |
10 |
Correct |
553 ms |
51704 KB |
Output is correct |
11 |
Correct |
368 ms |
52728 KB |
Output is correct |
12 |
Correct |
358 ms |
51064 KB |
Output is correct |
13 |
Correct |
21 ms |
33152 KB |
Output is correct |
14 |
Correct |
326 ms |
46972 KB |
Output is correct |
15 |
Correct |
52 ms |
34424 KB |
Output is correct |
16 |
Correct |
562 ms |
51832 KB |
Output is correct |
17 |
Correct |
367 ms |
51320 KB |
Output is correct |
18 |
Correct |
361 ms |
51420 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
21 ms |
33152 KB |
Output is correct |
2 |
Correct |
24 ms |
33280 KB |
Output is correct |
3 |
Correct |
24 ms |
33280 KB |
Output is correct |
4 |
Correct |
26 ms |
33408 KB |
Output is correct |
5 |
Correct |
26 ms |
33408 KB |
Output is correct |
6 |
Correct |
28 ms |
33408 KB |
Output is correct |
7 |
Correct |
21 ms |
33152 KB |
Output is correct |
8 |
Correct |
323 ms |
46840 KB |
Output is correct |
9 |
Correct |
214 ms |
40440 KB |
Output is correct |
10 |
Correct |
528 ms |
51704 KB |
Output is correct |
11 |
Correct |
360 ms |
52728 KB |
Output is correct |
12 |
Correct |
342 ms |
51192 KB |
Output is correct |
13 |
Correct |
22 ms |
33152 KB |
Output is correct |
14 |
Correct |
321 ms |
46840 KB |
Output is correct |
15 |
Correct |
53 ms |
34424 KB |
Output is correct |
16 |
Correct |
532 ms |
51836 KB |
Output is correct |
17 |
Correct |
360 ms |
51320 KB |
Output is correct |
18 |
Correct |
369 ms |
51320 KB |
Output is correct |
19 |
Correct |
727 ms |
77436 KB |
Output is correct |
20 |
Correct |
729 ms |
75000 KB |
Output is correct |
21 |
Correct |
732 ms |
77560 KB |
Output is correct |
22 |
Correct |
723 ms |
75000 KB |
Output is correct |
23 |
Correct |
711 ms |
74936 KB |
Output is correct |
24 |
Correct |
728 ms |
75064 KB |
Output is correct |
25 |
Correct |
716 ms |
75000 KB |
Output is correct |
26 |
Correct |
726 ms |
77560 KB |
Output is correct |
27 |
Correct |
739 ms |
77432 KB |
Output is correct |
28 |
Correct |
714 ms |
75000 KB |
Output is correct |
29 |
Correct |
722 ms |
75128 KB |
Output is correct |
30 |
Correct |
734 ms |
74932 KB |
Output is correct |