# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
743601 |
2023-05-17T14:20:28 Z |
josanneo22 |
Wall (IOI14_wall) |
C++17 |
|
0 ms |
0 KB |
#include "wall.h"
#include <bits/stdc++.h>
#include<unordered_map>
#include<algorithm>
using namespace std;
#define mp make_pair
#define pb push_back
#define pii pair<int,int>
#define fi first
#define se second
#define int long long
struct node {
int mx = 0, mn = 0;
};
node tree[2000005];
vector<int> ans(2000005);
void lazy(int pos) {
tree[2 * pos].mn = min(tree[2 * pos].mn, tree[pos].mn);
tree[2 * pos].mn = max(tree[2 * pos].mn, tree[pos].mx);
tree[2 * pos].mx = min(tree[2 * pos].mx, tree[pos].mn);
tree[2 * pos].mx = max(tree[2 * pos].mx, tree[pos].mx);
tree[2 * pos+1].mn = min(tree[2 * pos+1].mn, tree[pos].mn);
tree[2 * pos+1].mn = max(tree[2 * pos+1].mn, tree[pos].mx);
tree[2 * pos+1].mx = min(tree[2 * pos+1].mx, tree[pos].mn);
tree[2 * pos+1].mx = max(tree[2 * pos+1].mx, tree[pos].mx);
return;
}
void update(int tree_index, int tl, int tr, int l, int r, int type, int heigh) {
if (tr<l || tl>r) return;
if (tl <= l && r >= tr) {
if (type == 1) {
tree[tree_index].mn = max(tree[tree_index].mn, heigh);
tree[tree_index].mx = max(tree[tree_index].mx, heigh);
}
else {
tree[tree_index].mn = min(tree[tree_index].mn, heigh);
tree[tree_index].mx = min(tree[tree_index].mx, heigh);
}
return;
}
lazy(tree_index);
tree[tree_index].mn= 2000010;
tree[tree_index].mx = 0;
update(tree_index * 2, tl, (tl + tr) / 2, l, r, type, heigh);
update(tree_index * 2+1, (tl + tr) / 2+1,tr, l, r, type, heigh);
}
void get(int l,int r,int tree_index) {
if (l == r) {
ans[l] = tree[tree_index].mn;
}
lazy(tree_index);
get(l, (l + r) / 2, tree_index * 2);
get((l + r) / 2+1,r, tree_index * 2+1);
}
#include "wall.h"
#include <bits/stdc++.h>
#include<unordered_map>
#include<algorithm>
using namespace std;
#define mp make_pair
#define pb push_back
#define pii pair<int,int>
#define fi first
#define se second
#define int long long
struct node {
int mx = 0, mn = 0;
};
node tree[2000005];
vector<int> ans(2000005);
void lazy(int pos) {
tree[2 * pos].mn = min(tree[2 * pos].mn, tree[pos].mn);
tree[2 * pos].mn = max(tree[2 * pos].mn, tree[pos].mx);
tree[2 * pos].mx = min(tree[2 * pos].mx, tree[pos].mn);
tree[2 * pos].mx = max(tree[2 * pos].mx, tree[pos].mx);
tree[2 * pos + 1].mn = min(tree[2 * pos + 1].mn, tree[pos].mn);
tree[2 * pos + 1].mn = max(tree[2 * pos + 1].mn, tree[pos].mx);
tree[2 * pos + 1].mx = min(tree[2 * pos + 1].mx, tree[pos].mn);
tree[2 * pos + 1].mx = max(tree[2 * pos + 1].mx, tree[pos].mx);
return;
}
void update(int tree_index, int tl, int tr, int l, int r, int type, int heigh) {
if (tr<l || tl>r) return;
if (tl <= l && r >= tr) {
if (type == 1) {
tree[tree_index].mn = max(tree[tree_index].mn, heigh);
tree[tree_index].mx = max(tree[tree_index].mx, heigh);
}
else {
tree[tree_index].mn = min(tree[tree_index].mn, heigh);
tree[tree_index].mx = min(tree[tree_index].mx, heigh);
}
return;
}
lazy(tree_index);
tree[tree_index].mn = 2000010;
tree[tree_index].mx = 0;
update(tree_index * 2, tl, (tl + tr) / 2, l, r, type, heigh);
update(tree_index * 2 + 1, (tl + tr) / 2 + 1, tr, l, r, type, heigh);
}
void get(int l, int r, int tree_index) {
if (l == r) {
ans[l] = tree[tree_index].mn;
}
lazy(tree_index);
get(l, (l + r) / 2, tree_index * 2);
get((l + r) / 2 + 1, r, tree_index * 2 + 1);
}
void buildWall(int n, int k, int* op, int* left, int* right, int* height, int* finalheight) {
for (int i = 0; i < k; i++) {
update(1, 0, n - 1, left[i], right[i], op[i], height[i]);
}
get(0, n - 1, 1);
for (int i = 0; i < n; i++) {
finalheight[i] = ans[i];
}
}
Compilation message
wall.cpp:72:8: error: redefinition of 'struct node'
72 | struct node {
| ^~~~
wall.cpp:14:8: note: previous definition of 'struct node'
14 | struct node {
| ^~~~
wall.cpp:75:6: error: redefinition of 'node tree [2000005]'
75 | node tree[2000005];
| ^~~~
wall.cpp:17:6: note: 'node tree [2000005]' previously defined here
17 | node tree[2000005];
| ^~~~
wall.cpp:76:13: error: redefinition of 'std::vector<long long int> ans'
76 | vector<int> ans(2000005);
| ^~~
wall.cpp:18:13: note: 'std::vector<long long int> ans' previously declared here
18 | vector<int> ans(2000005);
| ^~~
wall.cpp:77:6: error: redefinition of 'void lazy(long long int)'
77 | void lazy(int pos) {
| ^~~~
wall.cpp:19:6: note: 'void lazy(long long int)' previously defined here
19 | void lazy(int pos) {
| ^~~~
wall.cpp:89:6: error: redefinition of 'void update(long long int, long long int, long long int, long long int, long long int, long long int, long long int)'
89 | void update(int tree_index, int tl, int tr, int l, int r, int type, int heigh) {
| ^~~~~~
wall.cpp:31:6: note: 'void update(long long int, long long int, long long int, long long int, long long int, long long int, long long int)' previously defined here
31 | void update(int tree_index, int tl, int tr, int l, int r, int type, int heigh) {
| ^~~~~~
wall.cpp:109:6: error: redefinition of 'void get(long long int, long long int, long long int)'
109 | void get(int l, int r, int tree_index) {
| ^~~
wall.cpp:51:6: note: 'void get(long long int, long long int, long long int)' previously defined here
51 | void get(int l,int r,int tree_index) {
| ^~~