# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1017667 |
2024-07-09T09:24:53 Z |
dosts |
Wall (IOI14_wall) |
C++17 |
|
1464 ms |
151724 KB |
#include "wall.h"
#include <bits/stdc++.h>
using namespace std;
//#define int long long
#define pii pair<int,int>
#define vi vector<int>
#define ff first
#define ss second
#define sp << " " <<
#define all(xx) xx.begin(),xx.end()
pii propmini(pii state,int minimise) {
if (minimise == -1) return state;
if (state.ss != -1) {
if (state.ss <= minimise) return state;
}
if (state.ff < minimise) return {state.ff,minimise};
return {minimise,minimise};
}
pii propmaxi(pii state,int maximise) {
if (maximise == -1) return state;
if (state.ff == -1) {
if (state.ss != -1 && state.ss <= maximise) return {maximise,maximise};
return {maximise,state.ss};
}
if (state.ss == -1) {
if (state.ff >= maximise) return state;
return {maximise,state.ss};
}
if (maximise < state.ff) return state;
if (maximise > state.ss) return {maximise,maximise};
return {maximise,state.ss};
}
struct ST {
vector<pii> lazy;
vector<pii> t;
ST(int nn) {
lazy.assign(4*nn+1,pii{-1,-1});
t.assign(4*nn+1,pii{-1,-1});
}
void push(int node,bool leaf) {
t[node] = propmaxi(t[node],lazy[node].ff);
t[node] = propmini(t[node],lazy[node].ss);
if (!leaf) {
lazy[2*node] = propmaxi(lazy[2*node],lazy[node].ff);
lazy[2*node] = propmini(lazy[2*node],lazy[node].ss);
lazy[2*node+1] = propmaxi(lazy[2*node+1],lazy[node].ff);
lazy[2*node+1] = propmini(lazy[2*node+1],lazy[node].ss);
}
lazy[node] = {-1,-1};
}
void mini(int node,int l,int r,int L,int R,int v) {
push(node,l==r);
if (l > R || r < L) return;
if (l >= L && r <= R) {
lazy[node] = propmini(lazy[node],v);
push(node,l==r);
return;
}
int m = (l+r) >> 1;
mini(2*node,l,m,L,R,v);
mini(2*node+1,m+1,r,L,R,v);
}
void maxi(int node,int l,int r,int L,int R,int v) {
push(node,l==r);
if (l > R || r < L) return;
if (l >= L && r <= R) {
lazy[node] = propmaxi(lazy[node],v);
push(node,l==r);
return;
}
int m = (l+r) >> 1;
maxi(2*node,l,m,L,R,v);
maxi(2*node+1,m+1,r,L,R,v);
}
pii query(int node,int l,int r,int p) {
push(node,l==r);
if (l == r) return t[node];
int m = (l+r) >> 1;
if (p<=m) return query(2*node,l,m,p);
return query(2*node+1,m+1,r,p);
}
};
void buildWall(int n, int k, int op[], int left[], int right[], int height[], int finalHeight[]){
ST st(n);
pii p = {-1,-1};
for (int i=0;i<k;i++){
if (op[i] == 1) {
//ADD
st.maxi(1,1,n,left[i]+1,right[i]+1,height[i]);
}
else {
//REM
st.mini(1,1,n,left[i]+1,right[i]+1,height[i]);
}
}
for (int i=0;i<n;i++) {
pii p = st.query(1,1,n,i+1);
if (p.ff!=-1) finalHeight[i] = p.ff;
else finalHeight[i] = 0;
}
return;
}
Compilation message
wall.cpp: In function 'void buildWall(int, int, int*, int*, int*, int*, int*)':
wall.cpp:95:7: warning: variable 'p' set but not used [-Wunused-but-set-variable]
95 | pii p = {-1,-1};
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
2 ms |
348 KB |
Output is correct |
3 |
Correct |
2 ms |
348 KB |
Output is correct |
4 |
Correct |
11 ms |
1272 KB |
Output is correct |
5 |
Correct |
7 ms |
1116 KB |
Output is correct |
6 |
Correct |
7 ms |
1288 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
123 ms |
8044 KB |
Output is correct |
3 |
Correct |
311 ms |
4692 KB |
Output is correct |
4 |
Correct |
892 ms |
24484 KB |
Output is correct |
5 |
Correct |
379 ms |
24912 KB |
Output is correct |
6 |
Correct |
361 ms |
23424 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
512 KB |
Output is correct |
3 |
Correct |
2 ms |
348 KB |
Output is correct |
4 |
Correct |
11 ms |
1220 KB |
Output is correct |
5 |
Correct |
9 ms |
1276 KB |
Output is correct |
6 |
Correct |
7 ms |
1216 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
124 ms |
14004 KB |
Output is correct |
9 |
Correct |
278 ms |
8528 KB |
Output is correct |
10 |
Correct |
838 ms |
24308 KB |
Output is correct |
11 |
Correct |
381 ms |
24912 KB |
Output is correct |
12 |
Correct |
359 ms |
23380 KB |
Output is correct |
13 |
Correct |
1 ms |
348 KB |
Output is correct |
14 |
Correct |
91 ms |
14000 KB |
Output is correct |
15 |
Correct |
50 ms |
2392 KB |
Output is correct |
16 |
Correct |
922 ms |
24356 KB |
Output is correct |
17 |
Correct |
362 ms |
23888 KB |
Output is correct |
18 |
Correct |
350 ms |
23816 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
344 KB |
Output is correct |
3 |
Correct |
2 ms |
348 KB |
Output is correct |
4 |
Correct |
10 ms |
1280 KB |
Output is correct |
5 |
Correct |
7 ms |
1116 KB |
Output is correct |
6 |
Correct |
7 ms |
1116 KB |
Output is correct |
7 |
Correct |
0 ms |
344 KB |
Output is correct |
8 |
Correct |
87 ms |
13868 KB |
Output is correct |
9 |
Correct |
299 ms |
8784 KB |
Output is correct |
10 |
Correct |
770 ms |
24404 KB |
Output is correct |
11 |
Correct |
330 ms |
24976 KB |
Output is correct |
12 |
Correct |
333 ms |
23364 KB |
Output is correct |
13 |
Correct |
0 ms |
344 KB |
Output is correct |
14 |
Correct |
94 ms |
13840 KB |
Output is correct |
15 |
Correct |
49 ms |
2392 KB |
Output is correct |
16 |
Correct |
914 ms |
24400 KB |
Output is correct |
17 |
Correct |
352 ms |
23740 KB |
Output is correct |
18 |
Correct |
355 ms |
23892 KB |
Output is correct |
19 |
Correct |
1259 ms |
151604 KB |
Output is correct |
20 |
Correct |
1232 ms |
151636 KB |
Output is correct |
21 |
Correct |
1294 ms |
151568 KB |
Output is correct |
22 |
Correct |
1464 ms |
151636 KB |
Output is correct |
23 |
Correct |
1389 ms |
151556 KB |
Output is correct |
24 |
Correct |
1421 ms |
151588 KB |
Output is correct |
25 |
Correct |
1410 ms |
151628 KB |
Output is correct |
26 |
Correct |
1425 ms |
151624 KB |
Output is correct |
27 |
Correct |
1412 ms |
151636 KB |
Output is correct |
28 |
Correct |
1243 ms |
151724 KB |
Output is correct |
29 |
Correct |
1231 ms |
151592 KB |
Output is correct |
30 |
Correct |
1271 ms |
151636 KB |
Output is correct |