# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
241284 |
2020-06-23T16:16:21 Z |
abacaba |
Wall (IOI14_wall) |
C++14 |
|
780 ms |
130808 KB |
#include <iostream>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <cstring>
#include <chrono>
#include <vector>
#include <map>
#include <random>
#include <set>
#include <algorithm>
#include <math.h>
#include <cstdio>
#include <stdio.h>
#include <queue>
#include <bitset>
#include "wall.h"
#include <cstdlib>
#include <deque>
#include <cassert>
#include <stack>
using namespace std;
#define mp make_pair
#define f first
#define se second
#define pb push_back
#define ppb pop_back
#define emb emplace_back
#define ll long long
#define ull unsigned long long
#define cntbit(x) __builtin_popcount(x)
#define endl '\n'
#define uset unordered_set
#define umap unordered_map
#define pii pair<int, int>
#define ld long double
#define pll pair<long long, long long>
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
template <typename T> inline T range(T l, T r) {
return uniform_int_distribution<T>(l, r)(rng);
}
inline void setin(string s) {
freopen(s.c_str(), "r", stdin);
}
inline void setout(string s) {
freopen(s.c_str(), "w", stdout);
}
template <typename T> void Min(T &a, T b) {
a = min(a, b);
}
template <typename T> void Max(T &a, T b) {
a = max(a, b);
}
const int inf = 0x3f3f3f3f;
const int mod = 998244353;
const int N = 2e6 + 15;
struct segment_tree {
int mn[N << 2], mx[N << 2], add[N << 2];
segment_tree() {
memset(mn, 0, sizeof(mx));
memset(mx, 0, sizeof(mx));
memset(add, -1, sizeof(add));
}
inline void upd(int v, int x) {
mn[v] = mx[v] = add[v] = x;
}
inline void push(int v) {
if(v < (N << 1) && add[v] != -1) {
upd(v << 1, add[v]);
upd(v << 1 | 1, add[v]);
add[v] = -1;
}
}
void max_equal(int v, int tl, int tr, int l, int r, int h) {
if(tl > r || tr < l || mn[v] >= h)
return;
push(v);
if(tl >= l && tr <= r && mx[v] <= h)
upd(v, h);
else {
int mid = tl + tr >> 1;
max_equal(v << 1, tl, mid, l, r, h);
max_equal(v << 1 | 1, mid + 1, tr, l, r, h);
mn[v] = min(mn[v << 1], mn[v << 1 | 1]);
mx[v] = max(mx[v << 1], mx[v << 1 | 1]);
}
}
void min_equal(int v, int tl, int tr, int l, int r, int h) {
if(tl > r || tr < l || mx[v] <= h)
return;
push(v);
if(tl >= l && tr <= r && mn[v] >= h)
upd(v, h);
else {
int mid = tl + tr >> 1;
min_equal(v << 1, tl, mid, l, r, h);
min_equal(v << 1 | 1, mid + 1, tr, l, r, h);
mn[v] = min(mn[v << 1], mn[v << 1 | 1]);
mx[v] = max(mx[v << 1], mx[v << 1 | 1]);
}
}
void output(int v, int tl, int tr, int finalHeight[]) {
if(tl == tr)
finalHeight[tl] = mn[v];
else {
push(v);
int mid = tl + tr >> 1;
output(v << 1, tl, mid, finalHeight);
output(v << 1 | 1, mid + 1, tr, finalHeight);
}
}
} t;
void buildWall(int n, int k, int op[], int left[], int right[], int height[], int finalHeight[]){
for(int i = 0; i < k; ++i) {
if(op[i] == 1)
t.max_equal(1, 0, n - 1, left[i], right[i], height[i]);
else
t.min_equal(1, 0, n - 1, left[i], right[i], height[i]);
}
t.output(1, 0, n - 1, finalHeight);
}
Compilation message
wall.cpp: In member function 'void segment_tree::max_equal(int, int, int, int, int, int)':
wall.cpp:91:26: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
int mid = tl + tr >> 1;
~~~^~~~
wall.cpp: In member function 'void segment_tree::min_equal(int, int, int, int, int, int)':
wall.cpp:105:26: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
int mid = tl + tr >> 1;
~~~^~~~
wall.cpp: In member function 'void segment_tree::output(int, int, int, int*)':
wall.cpp:117:26: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
int mid = tl + tr >> 1;
~~~^~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
53 ms |
94200 KB |
Output is correct |
2 |
Correct |
53 ms |
94328 KB |
Output is correct |
3 |
Correct |
52 ms |
94328 KB |
Output is correct |
4 |
Correct |
57 ms |
94584 KB |
Output is correct |
5 |
Correct |
56 ms |
94456 KB |
Output is correct |
6 |
Correct |
57 ms |
94456 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
52 ms |
94200 KB |
Output is correct |
2 |
Correct |
234 ms |
102136 KB |
Output is correct |
3 |
Correct |
142 ms |
101496 KB |
Output is correct |
4 |
Correct |
280 ms |
112248 KB |
Output is correct |
5 |
Correct |
270 ms |
113400 KB |
Output is correct |
6 |
Correct |
278 ms |
111800 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
60 ms |
94336 KB |
Output is correct |
2 |
Correct |
54 ms |
94336 KB |
Output is correct |
3 |
Correct |
56 ms |
94332 KB |
Output is correct |
4 |
Correct |
63 ms |
94584 KB |
Output is correct |
5 |
Correct |
58 ms |
94456 KB |
Output is correct |
6 |
Correct |
62 ms |
94544 KB |
Output is correct |
7 |
Correct |
62 ms |
94328 KB |
Output is correct |
8 |
Correct |
217 ms |
107872 KB |
Output is correct |
9 |
Correct |
153 ms |
101368 KB |
Output is correct |
10 |
Correct |
283 ms |
112248 KB |
Output is correct |
11 |
Correct |
263 ms |
113400 KB |
Output is correct |
12 |
Correct |
261 ms |
111864 KB |
Output is correct |
13 |
Correct |
53 ms |
94200 KB |
Output is correct |
14 |
Correct |
264 ms |
107896 KB |
Output is correct |
15 |
Correct |
93 ms |
95608 KB |
Output is correct |
16 |
Correct |
590 ms |
112528 KB |
Output is correct |
17 |
Correct |
356 ms |
111992 KB |
Output is correct |
18 |
Correct |
388 ms |
111992 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
56 ms |
94200 KB |
Output is correct |
2 |
Correct |
63 ms |
94328 KB |
Output is correct |
3 |
Correct |
54 ms |
94328 KB |
Output is correct |
4 |
Correct |
60 ms |
94588 KB |
Output is correct |
5 |
Correct |
59 ms |
94456 KB |
Output is correct |
6 |
Correct |
62 ms |
94456 KB |
Output is correct |
7 |
Correct |
56 ms |
94432 KB |
Output is correct |
8 |
Correct |
227 ms |
107896 KB |
Output is correct |
9 |
Correct |
148 ms |
101496 KB |
Output is correct |
10 |
Correct |
283 ms |
112376 KB |
Output is correct |
11 |
Correct |
262 ms |
113528 KB |
Output is correct |
12 |
Correct |
263 ms |
111736 KB |
Output is correct |
13 |
Correct |
59 ms |
94200 KB |
Output is correct |
14 |
Correct |
228 ms |
107896 KB |
Output is correct |
15 |
Correct |
88 ms |
95480 KB |
Output is correct |
16 |
Correct |
577 ms |
112504 KB |
Output is correct |
17 |
Correct |
354 ms |
112120 KB |
Output is correct |
18 |
Correct |
358 ms |
111992 KB |
Output is correct |
19 |
Correct |
740 ms |
130680 KB |
Output is correct |
20 |
Correct |
715 ms |
128252 KB |
Output is correct |
21 |
Correct |
724 ms |
130808 KB |
Output is correct |
22 |
Correct |
730 ms |
128120 KB |
Output is correct |
23 |
Correct |
780 ms |
128120 KB |
Output is correct |
24 |
Correct |
708 ms |
128248 KB |
Output is correct |
25 |
Correct |
731 ms |
128248 KB |
Output is correct |
26 |
Correct |
742 ms |
130680 KB |
Output is correct |
27 |
Correct |
747 ms |
130680 KB |
Output is correct |
28 |
Correct |
733 ms |
128248 KB |
Output is correct |
29 |
Correct |
706 ms |
128120 KB |
Output is correct |
30 |
Correct |
700 ms |
128120 KB |
Output is correct |