# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
900239 |
2024-01-08T00:11:27 Z |
asdasdqwer |
Wall (IOI14_wall) |
C++14 |
|
0 ms |
0 KB |
#include "wall.h"
#include <bits/stdc++.h>
using namespace std;
struct Segtree {
int n;
vector<int> mn;
vector<int> mx;
// 0 : no updates
// 1 : last update was maximum
// 2 : last update was minimum
vector<int> lastUpdate;
Segtree(int sz) {
n=1;
while(n<sz)n*=2;
mn.assign(2*n,0);
mx.assign(2*n,0);
lastUpdate.assign(2*n,0);
}
void pushdown(int x, bool secPush) {
if (lastUpdate[x] == 0) return;
if (secPush) {
pushdown(2*x+1,false);
pushdown(2*x+2,false);
}
if (lastUpdate[x] == 1) {
if (mx[2*x+1] > mx[x]) {
mx[2*x+1] = mx[x];
lastUpdate[2*x+1] = 1;
}
if (mx[2*x+2] > mx[x]) {
mx[2*x+2] = mx[x];
lastUpdate[2*x+2] = 1;
}
mn[2*x+1]=min(mn[2*x+1], mx[x]);
mn[2*x+2]=min(mn[2*x+2], mx[x]);
}
else if (lastUpdate[x] == 2) {
if (mn[2*x+1] < mn[x]) {
mn[2*x+1] = mn[x];
lastUpdate[2*x+1] = 2;
}
if (mn[2*x+2] < mn[x]) {
mn[2*x+2] = mn[x];
lastUpdate[2*x+2] = 2;
}
mx[2*x+1]=max(mx[2*x+1], mn[x]);
mx[2*x+2]=max(mx[2*x+2], mn[x]);
}
lastUpdate[x]=0;
}
void setMax(int l, int r, int v, int x, int lx, int rx) {
if (lx >= r || rx <= l) return;
if (rx-lx==1) {
if (mx[x] > v) {
// cout<<lx<<" "<<rx<<"\n";
mx[x]=mn[x]=v;
lastUpdate[x]=1;
}
return;
}
pushdown(x, ((rx-lx)!=2));
if (lx >= l && rx <= r) {
if (mx[x] > v) {
// cout<<lx<<" "<<rx<<"\n";
lastUpdate[x]=1;
mx[x]=v;
if (mn[x] > v)mn[x]=v;
}
return;
}
int m=(lx+rx)/2;
setMax(l,r,v,2*x+1,lx,m);
setMax(l,r,v,2*x+2,m,rx);
mx[x]=max(mx[2*x+1],mx[2*x+2]);
mn[x]=min(mn[2*x+1],mn[2*x+2]);
}
void setMax(int l, int r, int v) {
setMax(l, r, v, 0, 0, n);
}
void setMin(int l, int r, int v, int x, int lx, int rx) {
if (lx >= r || rx <= l) return;
if (rx-lx==1) {
if (mn[x] < v) {
mn[x]=mx[x]=v;
lastUpdate[x]=2;
}
return;
}
pushdown(x, ((rx-lx)!=2));
if (lx >= l && rx <= r) {
if (mn[x] < v) {
lastUpdate[x]=2;
mn[x]=v;
if (mx[x] < v) mx[x]=v;
}
return;
}
int m=(lx+rx)/2;
setMin(l,r,v,2*x+1,lx,m);
setMin(l,r,v,2*x+2,m,rx);
mx[x]=max(mx[2*x+1],mx[2*x+2]);
mn[x]=min(mn[2*x+1],mn[2*x+2]);
}
void setMin(int l, int r, int v) {
setMin(l, r, v, 0, 0, n);
}
int get(int i, int x, int lx, int rx) {
if (rx-lx==1) {
// cout<<mx[x]<<" "<<mn[x]<<" ";
return mx[x];
}
pushdown(x, ((rx-lx)!=2));
int m=(lx+rx)/2;
if (i<m)return get(i,2*x+1,lx,m);
else return get(i,2*x+2,m,rx);
}
int get(int i) {
return get(i,0,0,n);
}
};
void buildWall(int n, int k, int op[], int left[], int right[], int height[], int finalHeight) {
Segtree sg(n);
for (int i=0;i<k;i++) {
int jj=0;
if (op[i] == 1) {
sg.setMin(left[i], right[i]+1, height[i]);
}
else {
sg.setMax(left[i], right[i]+1, height[i]);
}
for (int i=0;i<n;i++) sg.get(i);
}
// cout<<"\n";
for (int i=0;i<n;i++) {
finalHeight[i] = sg.get(i);
}
}
Compilation message
wall.cpp: In function 'void buildWall(int, int, int*, int*, int*, int*, int)':
wall.cpp:160:13: warning: unused variable 'jj' [-Wunused-variable]
160 | int jj=0;
| ^~
wall.cpp:174:20: error: invalid types 'int[int]' for array subscript
174 | finalHeight[i] = sg.get(i);
| ^