Submission #23220

#TimeUsernameProblemLanguageResultExecution timeMemory
23220RockyBWall (IOI14_wall)C++14
0 / 100
3000 ms154772 KiB
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #include <ext/pb_ds/detail/standard_policies.hpp> #include "wall.h" #define f first #define s second #define pb push_back #define pp pop_back #define mp make_pair #define sz(x) (int)x.size() #define sqr(x) ((x) * 1ll * (x)) #define all(x) x.begin(), x.end() #define rep(i, l, r) for (int i = l; i <= r; i++) #define per(i, l, r) for (int i = l; i >= r; i--) #define dbg(x) cerr << (#x) << " --> " << (x) << nl; #define Kazakhstan ios_base :: sync_with_stdio(0), cin.tie(0), cout.tie(0); #define nl '\n' #define ioi exit(0); #define Toktama "" using namespace std; using namespace __gnu_pbds; typedef long long ll; typedef long double ld; typedef unsigned long long ull; typedef tree < pair <int, int>, null_type, less < pair <int, int> >, rb_tree_tag, tree_order_statistics_node_update> ordered_set; const int N = 1e6 + 7, inf = 1e9 + 7, mod = 1e9 + 7; const ll linf = (ll)1e18 + 7; const int dx[] = {-1, 0, 1, 0, 1, -1, -1, 1}, dy[] = {0, 1, 0, -1, 1, -1, 1, -1}; int n, k; int type[N], l[N], r[N], x[N], ans[N]; pair <int, int> t[N << 2]; struct node { int x, id; node() {} node(int x, int id) : x(x), id(id) {} }; struct _upd { node u[3]; _upd() { u[1] = node(-inf, -1); u[2] = node(inf, -1); } } u[N << 2]; pair <int, int> combo(pair <int, int> l, pair <int, int> r) { return {min(l.f, r.f), max(l.s, r.s)}; } void push(int v, int tl, int tr, int deep = 0) { if (!deep && tl != tr) { int tm = tl + tr >> 1; push(v + v, tl, tm, 1); push(v + v + 1, tm + 1, tr); } bool ok = 0; if (u[v].u[2].id == 4 && tl == 4 && tr == 6) ok = 1; if (u[v].u[1].id != -1 && u[v].u[2].id != -1) { if (u[v].u[1].id > u[v].u[2].id) { int x = u[v].u[2].x; t[v + v].s = min(t[v + v].s, x); t[v + v].f = min(t[v + v].f, t[v + v].s); t[v + v + 1].s = min(t[v + v + 1].s, x); t[v + v + 1].f = min(t[v + v + 1].f, t[v + v + 1].s); x = u[v].u[1].x; t[v + v].f = max(t[v + v].f, x); t[v + v].s = max(t[v + v].s, t[v + v].f); t[v + v + 1].f = max(t[v + v + 1].f, x); t[v + v + 1].s = max(t[v + v + 1].s, t[v + v + 1].f); } else { int x = u[v].u[1].x; t[v + v].f = max(t[v + v].f, x); t[v + v].s = max(t[v + v].s, t[v + v].f); t[v + v + 1].f = max(t[v + v + 1].f, x); t[v + v + 1].s = max(t[v + v + 1].s, t[v + v + 1].f); x = u[v].u[2].x; t[v + v].s = min(t[v + v].s, x); t[v + v].f = min(t[v + v].f, t[v + v].s); t[v + v + 1].s = min(t[v + v + 1].s, x); t[v + v + 1].f = min(t[v + v + 1].f, t[v + v + 1].s); } //if (ok) cout << u[v].u[2].x << ' ' << u[v + v].u[2].x << nl; if (u[v + v].u[1].x <= u[v].u[1].x) u[v + v].u[1] = u[v].u[1]; if (u[v + v].u[2].x >= u[v].u[2].x) u[v + v].u[2] = u[v].u[2]; if (u[v + v + 1].u[1].x <= u[v].u[1].x) u[v + v + 1].u[1] = u[v].u[1]; if (u[v + v + 1].u[2].x >= u[v].u[2].x) u[v + v + 1].u[2] = u[v].u[2]; /* { u[v + v].u[1] = u[v].u[1]; u[v + v].u[2] = u[v].u[2]; u[v + v + 1].u[1] = u[v].u[1]; u[v + v + 1].u[2] = u[v].u[2]; }*/ u[v] = _upd(); } else if (u[v].u[1].id != -1) { int x = u[v].u[1].x; t[v + v].f = max(t[v + v].f, x); t[v + v].s = max(t[v + v].s, t[v + v].f); t[v + v + 1].f = max(t[v + v + 1].f, x); t[v + v + 1].s = max(t[v + v + 1].s, t[v + v + 1].f); if (u[v + v].u[1].x <= u[v].u[1].x) u[v + v].u[1] = u[v].u[1]; if (u[v + v + 1].u[1].x <= u[v].u[1].x) u[v + v + 1].u[1] = u[v].u[1]; /* { u[v + v].u[1] = u[v].u[1]; u[v + v + 1].u[1] = u[v].u[1]; }*/ u[v] = _upd(); } else if (u[v].u[2].id != -1) { int x = u[v].u[2].x; t[v + v].s = min(t[v + v].s, x); t[v + v].f = min(t[v + v].f, t[v + v].s); t[v + v + 1].s = min(t[v + v + 1].s, x); t[v + v + 1].f = min(t[v + v + 1].f, t[v + v + 1].s); if (u[v + v].u[2].x >= u[v].u[2].x) u[v + v].u[2] = u[v].u[2]; if (u[v + v + 1].u[2].x >= u[v].u[2].x) u[v + v + 1].u[2] = u[v].u[2]; /* { u[v + v].u[2] = u[v].u[2]; u[v + v + 1].u[2] = u[v].u[2]; }*/ u[v] = _upd(); } } void upd(int l, int r, int type, int x, int id, int v, int tl, int tr) { if (l <= tl && tr <= r) { if (type == 1) { t[v].f = max(t[v].f, x); t[v].s = max(t[v].s, t[v].f); if (u[v].u[1].x <= x) u[v].u[1] = node(x, id), u[v].u[2] = node(inf, -1); } else { t[v].s = min(t[v].s, x); t[v].f = min(t[v].f, t[v].s); if (u[v].u[2].x >= x) u[v].u[2] = node(x, id), u[v].u[1] = node(-inf, -1); } return; } if (tl > r || tr < l) return; int tm = tl + tr >> 1; push(v, tl, tr); upd(l, r, type, x, id, v + v, tl, tm); upd(l, r, type, x, id, v + v + 1, tm + 1, tr); t[v] = combo(t[v + v], t[v + v + 1]); } pair <int, int> get(int l, int r, int v, int tl, int tr) { if (l <= tl && tr <= r) return t[v]; if (tl > r || tr < l) return {inf, -inf}; int tm = tl + tr >> 1; push(v, tl, tr); return combo(get(l, r, v + v, tl, tm), get(l, r, v + v + 1, tm + 1, tr)); } void bye(int v, int tl, int tr) { //cout << tl << ' ' << tr << ' ' << u[v].u[1].x << ' ' << u[v].u[2].x << nl; if (tl == tr) { return; } int tm = tl + tr >> 1; bye(v + v, tl, tm); bye(v + v + 1, tm + 1, tr); } void buildWall(int n, int k, int op[], int left[], int right[], int height[], int finalHeight[]) { rep(i, 0, k - 1) { upd(left[i], right[i], op[i], height[i], i, 1, 0, n - 1); //if (i == 4) break; } // cout << get(2, 3, 1, 0, n - 1).s << nl; // ioi rep(i, 0, n - 1) finalHeight[i] = get(i, i, 1, 0, n - 1).f; } /* int main() { #ifndef Toktama freopen (Toktama".in", "r", stdin); freopen (Toktama".out", "w", stdout); #endif freopen (".in", "r", stdin); //freopen ("gen.in", "r", stdin); //freopen ("a.out", "w", stdout); scanf ("%d%d", &n, &k); rep(i, 0, k - 1) scanf ("%d%d%d%d", &type[i], &l[i], &r[i], &x[i]); buildWall(n, k, type, l, r, x, ans); rep(i, 0, n - 1) printf ("%d ", ans[i]); { cout << nl; //bye(1, 0, n - 1); } ioi } */

Compilation message (stderr)

wall.cpp: In function 'void push(int, int, int, int)':
wall.cpp:65:17: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
     int tm = tl + tr >> 1;
                 ^
wall.cpp:70:8: warning: variable 'ok' set but not used [-Wunused-but-set-variable]
   bool ok = 0;
        ^
wall.cpp: In function 'void upd(int, int, int, int, int, int, int, int)':
wall.cpp:165:15: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   int tm = tl + tr >> 1;
               ^
wall.cpp: In function 'std::pair<int, int> get(int, int, int, int, int)':
wall.cpp:174:15: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   int tm = tl + tr >> 1;
               ^
wall.cpp: In function 'void bye(int, int, int)':
wall.cpp:185:15: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   int tm = tl + tr >> 1;
               ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...