#include<bits/stdc++.h>
using namespace std;
#define all(x) x.begin(), x.end()
#define ll long long
#define check(...) cerr << "[" << #__VA_ARGS__ << "]: "; cerr << 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 O, typename... C> string to_string(const O (&v), int x1 = 0, int x2 = 1e9, C... coords); int l_v_l_v_l = 0, t_a_b_s = 0; template <typename O, typename B> string to_string(const pair<O, 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 O, typename... C> string to_string(const O (&v), int x1, int x2, C... coords) { int rnk = rank<O>::value; string tab(t_a_b_s, ' '); string res = ""; bool first = true; if (l_v_l_v_l == 0) res += "\n"; 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"; 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"; return res; } void dbgm() {;} template<typename Heads, typename... Tails> void dbgm(Heads H, Tails... T) { cerr << to_string(H) << " | "; dbgm(T...); }
#define dbgm(...) cerr << "[" << #__VA_ARGS__ << "]: "; dbgm(__VA_ARGS__); cerr << endl
const int mod = 1e9+7;
const int INF = 1e9;
struct updnode{ // do this max(min(h, mn), mx)
int mn, mx;
updnode(){
mn = INF;
mx = -INF;
}
updnode(int _mn, int _mx){
mn = _mn;
mx = _mx;
}
};
inline bool operator==(const updnode &u1, const updnode &u2){
return (u1.mn == u2.mn) and (u1.mx == u2.mx);
}
// Template Credits: Harisam Sharma(https://youtu.be/dexE7JwxrMU)
#define ll long long
template<class T, class U>
// T -> node, U->update.
struct Lsegtree{
vector<T>st;
vector<U>lazy;
ll n;
T identity_element;
U identity_update;
Lsegtree(ll n, T identity_element, U identity_update)
{
this->n = n;
this->identity_element = identity_element;
this->identity_update = identity_update;
st.assign(4*n,identity_element);
lazy.assign(4*n, identity_update);
}
T combine(T l, T r)
{
// change this function as required.
T ans = max(l, r);
return ans;
}
void buildUtil(ll v, ll tl, ll tr, vector<T>&a)
{
if(tl == tr)
{
st[v] = a[tl];
return;
}
ll tm = (tl + tr)>>1;
buildUtil(2*v + 1, tl, tm,a);
buildUtil(2*v + 2,tm+1,tr,a);
st[v] = combine(st[2*v + 1], st[2*v + 2]);
}
// change the following 2 functions, and you're more or less done.
T apply(T curr, U upd, ll tl, ll tr)
{
T ans = max(min(upd.mn, curr), upd.mx);
return ans;
}
U combineUpdate(U old_upd, U new_upd, ll tl, ll tr)
{
U ans = old_upd;
ans.mn = min(ans.mn, new_upd.mn);
ans.mx = max(ans.mx, new_upd.mx);
return ans;
}
void push_down(ll v, ll tl, ll tr)
{
if(lazy[v] == identity_update)return;
st[v] = apply(st[v], lazy[v], tl, tr);
if(2*v + 2 < 4*n)
{
ll tm = (tl + tr)>>1;
lazy[2*v + 1] = combineUpdate(lazy[2*v+1], lazy[v], tl, tm);
lazy[2*v + 2] = combineUpdate(lazy[2*v+2], lazy[v], tm+1,tr);
}
lazy[v] = identity_update;
}
T queryUtil(ll v, ll tl, ll tr, ll l, ll r)
{
push_down(v,tl,tr);
if(l > r)return identity_element;
if(tr < l or tl > r)
{
return identity_element;
}
if(l <= tl and r >= tr)
{
return st[v];
}
ll tm = (tl + tr)>>1;
return combine(queryUtil(2*v+1,tl,tm,l,r), queryUtil(2*v+2,tm+1,tr,l,r));
}
void updateUtil(ll v, ll tl, ll tr, ll l, ll r, U upd)
{
push_down(v,tl,tr);
if(tr < l or tl > r)return;
if(tl >=l and tr <=r)
{
lazy[v] = combineUpdate(lazy[v],upd,tl,tr);
push_down(v,tl,tr);
}
else
{
ll tm = (tl + tr)>>1;
updateUtil(2*v+1,tl,tm,l,r,upd);
updateUtil(2*v+2,tm+1,tr,l,r,upd);
st[v] = combine(st[2*v + 1], st[2*v+2]);
}
}
void build(vector<T>a)
{
assert(size(a) == n);
buildUtil(0,0,n-1,a);
}
T query(ll l, ll r)
{
return queryUtil(0,0,n-1,l,r);
}
void update(ll l,ll r, U upd)
{
updateUtil(0,0,n-1,l,r,upd);
}
};
int main(){
int n, q; cin>>n>>q;
vector<int> arr(n, 0);
for(int i = 0; i<q; i++){
int t; cin>>t;
if(t == 1){
int l, r, h; cin>>l>>r>>h;
while(l<=r) {arr[l] = max(arr[l], h); l++;}
}else{
int l, r, h; cin>>l>>r>>h;
while(l<=r) {arr[l] = min(arr[l], h); l++;}
}
}
for(int i = 0; i<n; i++){
cout<<arr[i]<<"\n";
}
return 0;
}
Compilation message
wall.cpp: In function 'std::string to_string(std::string, int, int)':
wall.cpp:6:215: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
6 | 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 O, typename... C> string to_string(const O (&v), int x1 = 0, int x2 = 1e9, C... coords); int l_v_l_v_l = 0, t_a_b_s = 0; template <typename O, typename B> string to_string(const pair<O, 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 O, typename... C> string to_string(const O (&v), int x1, int x2, C... coords) { int rnk = rank<O>::value; string tab(t_a_b_s, ' '); string res = ""; bool first = true; if (l_v_l_v_l == 0) res += "\n"; 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"; 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"; return res; } void dbgm() {;} template<typename Heads, typename... Tails> void dbgm(Heads H, Tails... T) { cerr << to_string(H) << " | "; dbgm(T...); }
| ~~~^~~~~~~~~~
/usr/bin/ld: /tmp/ccZAGh6E.o: in function `main':
grader.cpp:(.text.startup+0x0): multiple definition of `main'; /tmp/ccRK5hqC.o:wall.cpp:(.text.startup+0x0): first defined here
/usr/bin/ld: /tmp/ccZAGh6E.o: in function `main':
grader.cpp:(.text.startup+0x133): undefined reference to `buildWall(int, int, int*, int*, int*, int*, int*)'
collect2: error: ld returned 1 exit status