#include <bits/stdc++.h>
#include "wall.h"
using namespace std;
#define n_l '\n'
#define dbg(...) cout << "[" << #__VA_ARGS__ << "]: "; cout << to_string(__VA_ARGS__) << endl
template <typename T, size_t N> int SIZE(const T (&t)[N]){ return N; } template<typename T> int SIZE(const T &t){ return t.size(); } string to_string(const string s, int x1=0, int x2=1e9){ return '"' + ((x1 < s.size()) ? s.substr(x1, x2-x1+1) : "") + '"'; } string to_string(const char* s) { return to_string((string) s); } string to_string(const bool b) { return (b ? "true" : "false"); } string to_string(const char c){ return string({c}); } template<size_t N> string to_string(const bitset<N> &b, int x1=0, int x2=1e9){ string t = ""; for(int __iii__ = min(x1,SIZE(b)), __jjj__ = min(x2, SIZE(b)-1); __iii__ <= __jjj__; ++__iii__){ t += b[__iii__] + '0'; } return '"' + t + '"'; } template <typename A, typename... C> string to_string(const A (&v), int x1=0, int x2=1e9, C... coords); int l_v_l_v_l = 0, t_a_b_s = 0; template <typename A, typename B> string to_string(const pair<A, B> &p) { l_v_l_v_l++; string res = "(" + to_string(p.first) + ", " + to_string(p.second) + ")"; l_v_l_v_l--; return res; } template <typename A, typename... C> string to_string(const A (&v), int x1, int x2, C... coords) { int rnk = rank<A>::value; string tab(t_a_b_s, ' '); string res = ""; bool first = true; if(l_v_l_v_l == 0) res += n_l; res += tab + "["; x1 = min(x1, SIZE(v)), x2 = min(x2, SIZE(v)); auto l = begin(v); advance(l, x1); auto r = l; advance(r, (x2-x1) + (x2 < SIZE(v))); for (auto e = l; e != r; e = next(e)) { if (!first) { res += ", "; } first = false; l_v_l_v_l++; if(e != l){ if(rnk > 1) { res += n_l; t_a_b_s = l_v_l_v_l; }; } else{ t_a_b_s = 0; } res += to_string(*e, coords...); l_v_l_v_l--; } res += "]"; if(l_v_l_v_l == 0) res += n_l; return res; } void dbgm(){;} template<typename Heads, typename... Tails> void dbgm(Heads H, Tails... T){ cout << to_string(H) << " | "; dbgm(T...); }
#define dbgm(...) cout << "[" << #__VA_ARGS__ << "]: "; dbgm(__VA_ARGS__); cout << endl
#define lli long long int
#define MP make_pair
#define pb push_back
#define REP(i,n) for(int (i) = 0; (i) < (n); (i)++)
void fastio() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
}
const double EPS = 0.00001;
const int INF = 1e9+500;
const int N = 3e5+5;
const int ALPH = 26;
const int LGN = 25;
const int MOD = 1e9+7;
int n,m,q;
struct Node {
int opmin, opmax;
Node *lc, *rc;
int tl, tr;
Node(int tl, int tr) {
opmax = 0;
opmin = INF;
lc = NULL;
rc = NULL;
this->tl = tl;
this->tr = tr;
}
void extend() {
int tm = (tl + tr) >> 1;
if(lc == NULL) lc = new Node(tl, tm);
if(rc == NULL) rc = new Node(tm + 1, tr);
}
void push() {
lc->minimize(lc->tl, lc->tr, opmin);
lc->maximize(lc->tl, lc->tr, opmax);
rc->minimize(rc->tl, rc->tr, opmin);
rc->maximize(rc->tl, rc->tr, opmax);
opmin = INF;
opmax = 0;
}
void maximize(int l, int r, int val) {
if(tl >= l && tr <= r) {
opmax = max(opmax, val);
opmin = max(opmin, val);
return;
}
if(tl > r || tr < l) {
return;
}
extend();
push();
int tm = (tl + tr) >> 1;
lc->maximize(l, r, val);
rc->maximize(l, r, val);
}
void minimize(int l, int r, int val) {
if(tl >= l && tr <= r) {
opmax = min(opmax, val);
opmin = min(opmin, val);
return;
}
if(tl > r || tr < l) {
return;
}
extend();
push();
int tm = (tl + tr) >> 1;
lc->minimize(l, r, val);
rc->minimize(l, r, val);
}
int query(int ind) {
if(tl == tr) {
return min(opmin, max(0, opmax) );
}
extend();
push();
int tm = (tl + tr) >> 1;
if(ind <= tm) {
return lc->query(ind);
}
else {
return rc->query(ind);
}
}
};
void buildWall(int n, int k, int op[], int left[], int right[], int height[], int finalHeight[]){
Node st(0, n);
for(int i = 0; i<k; i++) {
if(op[i] == 1) {
st.maximize(left[i], right[i], height[i]);
}
else {
st.minimize(left[i], right[i], height[i]);
}
}
for(int i = 0; i<n; i++) {
finalHeight[i] = st.query(i);
}
return;
}
Compilation message
wall.cpp: In function 'std::string to_string(std::string, int, int)':
wall.cpp:7:208: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
7 | template <typename T, size_t N> int SIZE(const T (&t)[N]){ return N; } template<typename T> int SIZE(const T &t){ return t.size(); } string to_string(const string s, int x1=0, int x2=1e9){ return '"' + ((x1 < s.size()) ? s.substr(x1, x2-x1+1) : "") + '"'; } string to_string(const char* s) { return to_string((string) s); } string to_string(const bool b) { return (b ? "true" : "false"); } string to_string(const char c){ return string({c}); } template<size_t N> string to_string(const bitset<N> &b, int x1=0, int x2=1e9){ string t = ""; for(int __iii__ = min(x1,SIZE(b)), __jjj__ = min(x2, SIZE(b)-1); __iii__ <= __jjj__; ++__iii__){ t += b[__iii__] + '0'; } return '"' + t + '"'; } template <typename A, typename... C> string to_string(const A (&v), int x1=0, int x2=1e9, C... coords); int l_v_l_v_l = 0, t_a_b_s = 0; template <typename A, typename B> string to_string(const pair<A, B> &p) { l_v_l_v_l++; string res = "(" + to_string(p.first) + ", " + to_string(p.second) + ")"; l_v_l_v_l--; return res; } template <typename A, typename... C> string to_string(const A (&v), int x1, int x2, C... coords) { int rnk = rank<A>::value; string tab(t_a_b_s, ' '); string res = ""; bool first = true; if(l_v_l_v_l == 0) res += n_l; res += tab + "["; x1 = min(x1, SIZE(v)), x2 = min(x2, SIZE(v)); auto l = begin(v); advance(l, x1); auto r = l; advance(r, (x2-x1) + (x2 < SIZE(v))); for (auto e = l; e != r; e = next(e)) { if (!first) { res += ", "; } first = false; l_v_l_v_l++; if(e != l){ if(rnk > 1) { res += n_l; t_a_b_s = l_v_l_v_l; }; } else{ t_a_b_s = 0; } res += to_string(*e, coords...); l_v_l_v_l--; } res += "]"; if(l_v_l_v_l == 0) res += n_l; return res; } void dbgm(){;} template<typename Heads, typename... Tails> void dbgm(Heads H, Tails... T){ cout << to_string(H) << " | "; dbgm(T...); }
| ~~~^~~~~~~~~~
wall.cpp: In member function 'void Node::maximize(int, int, int)':
wall.cpp:67:13: warning: unused variable 'tm' [-Wunused-variable]
67 | int tm = (tl + tr) >> 1;
| ^~
wall.cpp: In member function 'void Node::minimize(int, int, int)':
wall.cpp:82:13: warning: unused variable 'tm' [-Wunused-variable]
82 | int tm = (tl + tr) >> 1;
| ^~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
2 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
6 ms |
1628 KB |
Output is correct |
5 |
Correct |
5 ms |
1628 KB |
Output is correct |
6 |
Correct |
5 ms |
1612 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
113 ms |
8012 KB |
Output is correct |
3 |
Correct |
132 ms |
5444 KB |
Output is correct |
4 |
Correct |
401 ms |
25920 KB |
Output is correct |
5 |
Correct |
230 ms |
26564 KB |
Output is correct |
6 |
Correct |
229 ms |
25528 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
2 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
6 ms |
1628 KB |
Output is correct |
5 |
Correct |
5 ms |
1880 KB |
Output is correct |
6 |
Correct |
5 ms |
1624 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
115 ms |
14088 KB |
Output is correct |
9 |
Correct |
132 ms |
9236 KB |
Output is correct |
10 |
Correct |
397 ms |
27636 KB |
Output is correct |
11 |
Correct |
237 ms |
28728 KB |
Output is correct |
12 |
Correct |
225 ms |
27116 KB |
Output is correct |
13 |
Correct |
0 ms |
600 KB |
Output is correct |
14 |
Correct |
119 ms |
13908 KB |
Output is correct |
15 |
Correct |
24 ms |
3160 KB |
Output is correct |
16 |
Correct |
413 ms |
27984 KB |
Output is correct |
17 |
Correct |
232 ms |
27668 KB |
Output is correct |
18 |
Correct |
226 ms |
27444 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
6 ms |
1628 KB |
Output is correct |
5 |
Correct |
5 ms |
1628 KB |
Output is correct |
6 |
Correct |
5 ms |
1628 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
114 ms |
13904 KB |
Output is correct |
9 |
Correct |
130 ms |
9180 KB |
Output is correct |
10 |
Correct |
396 ms |
27728 KB |
Output is correct |
11 |
Correct |
226 ms |
28752 KB |
Output is correct |
12 |
Correct |
224 ms |
27220 KB |
Output is correct |
13 |
Correct |
0 ms |
344 KB |
Output is correct |
14 |
Correct |
116 ms |
13900 KB |
Output is correct |
15 |
Correct |
23 ms |
3164 KB |
Output is correct |
16 |
Correct |
399 ms |
28072 KB |
Output is correct |
17 |
Correct |
241 ms |
27492 KB |
Output is correct |
18 |
Correct |
227 ms |
27472 KB |
Output is correct |
19 |
Correct |
976 ms |
224884 KB |
Output is correct |
20 |
Correct |
940 ms |
222076 KB |
Output is correct |
21 |
Correct |
920 ms |
224740 KB |
Output is correct |
22 |
Correct |
912 ms |
222292 KB |
Output is correct |
23 |
Correct |
917 ms |
222032 KB |
Output is correct |
24 |
Correct |
918 ms |
222152 KB |
Output is correct |
25 |
Correct |
952 ms |
222220 KB |
Output is correct |
26 |
Correct |
926 ms |
224860 KB |
Output is correct |
27 |
Correct |
920 ms |
224596 KB |
Output is correct |
28 |
Correct |
948 ms |
222100 KB |
Output is correct |
29 |
Correct |
996 ms |
222032 KB |
Output is correct |
30 |
Correct |
940 ms |
222144 KB |
Output is correct |