# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
828944 |
2023-08-17T21:23:48 Z |
Lobo |
Wall (IOI14_wall) |
C++17 |
|
905 ms |
162368 KB |
#include "wall.h"
#include<bits/stdc++.h>
using namespace std;
#define mp make_pair
#define fr first
#define sc second
#define pb push_back
const int maxk = 5e5+10;
const int maxn = 2e6+10;
const int inf = 1e9+10;
int tra[4*maxk], trb[4*maxk];
vector<int> adds[maxn], rems[maxn];
void build(int no, int l, int r) {
tra[no] = -inf;
trb[no] = inf;
if(l == r) return;
int lc=2*no,rc=2*no+1,mid=(l+r)>>1;
build(lc,l,mid);
build(rc,mid+1,r);
}
void upd(int no, int l, int r, int pos, int newa, int newb) {
if(l > pos || r < pos) return;
if(l == r) {
if(newa != -1) tra[no] = newa;
if(newb != -1) trb[no] = newb;
return;
}
int lc=2*no,rc=2*no+1,mid=(l+r)>>1;
upd(lc,l,mid,pos,newa,newb);
upd(rc,mid+1,r,pos,newa,newb);
tra[no] = max(tra[lc],tra[rc]);
trb[no] = min(trb[lc],trb[rc]);
}
pair<int,pair<int,int>> find(int no, int l, int r, int maxa, int minb) {
if(l == r) return mp(l+1,mp(maxa,minb));
int lc=2*no,rc=2*no+1,mid=(l+r)>>1;
if(max(maxa,tra[rc]) < min(minb,trb[rc])) return find(lc,l,mid,max(maxa,tra[rc]),min(minb,trb[rc]));
else return find(rc,mid+1,r,maxa,minb);
}
void buildWall(int n, int k, int op[], int lf[], int rg[], int h[], int finalHeight[]){
for(int i = 0; i < k; i++) {
adds[lf[i]].pb(i);
rems[rg[i]].pb(i);
}
build(1,0,k);
for(int i = 0; i < n; i++) {
for(auto j : adds[i]) {
if(op[j] == 1) {
upd(1,0,k,j+1,h[j],-1);
}
else {
upd(1,0,k,j+1,-1,h[j]);
}
}
upd(1,0,k,0,0,0);
auto aux = find(1,0,k,-inf,inf);
int hcur;
if(aux.fr-1 == 0) hcur = 0;
else hcur = h[aux.fr-2];
int maxa = aux.sc.fr;
int minb = aux.sc.sc;
hcur = min(hcur,minb);
hcur = max(hcur,maxa);
finalHeight[i] = hcur;
for(auto j : rems[i]) {
if(op[j] == 1) {
upd(1,0,k,j+1,-inf,-1);
}
else {
upd(1,0,k,j+1,-1,inf);
}
}
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
46 ms |
94344 KB |
Output is correct |
2 |
Correct |
46 ms |
94456 KB |
Output is correct |
3 |
Correct |
46 ms |
94248 KB |
Output is correct |
4 |
Correct |
49 ms |
94752 KB |
Output is correct |
5 |
Correct |
48 ms |
94796 KB |
Output is correct |
6 |
Correct |
50 ms |
94748 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
44 ms |
94236 KB |
Output is correct |
2 |
Correct |
364 ms |
116984 KB |
Output is correct |
3 |
Correct |
197 ms |
107536 KB |
Output is correct |
4 |
Correct |
630 ms |
129884 KB |
Output is correct |
5 |
Correct |
365 ms |
128776 KB |
Output is correct |
6 |
Correct |
363 ms |
126796 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
47 ms |
94168 KB |
Output is correct |
2 |
Correct |
48 ms |
94564 KB |
Output is correct |
3 |
Correct |
46 ms |
94284 KB |
Output is correct |
4 |
Correct |
52 ms |
94768 KB |
Output is correct |
5 |
Correct |
51 ms |
94744 KB |
Output is correct |
6 |
Correct |
51 ms |
94796 KB |
Output is correct |
7 |
Correct |
52 ms |
94232 KB |
Output is correct |
8 |
Correct |
315 ms |
120228 KB |
Output is correct |
9 |
Correct |
198 ms |
108792 KB |
Output is correct |
10 |
Correct |
630 ms |
129872 KB |
Output is correct |
11 |
Correct |
372 ms |
128740 KB |
Output is correct |
12 |
Correct |
360 ms |
126796 KB |
Output is correct |
13 |
Correct |
48 ms |
94156 KB |
Output is correct |
14 |
Correct |
363 ms |
120228 KB |
Output is correct |
15 |
Correct |
73 ms |
96716 KB |
Output is correct |
16 |
Correct |
535 ms |
130156 KB |
Output is correct |
17 |
Correct |
375 ms |
127096 KB |
Output is correct |
18 |
Correct |
366 ms |
126736 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
46 ms |
94124 KB |
Output is correct |
2 |
Correct |
51 ms |
94572 KB |
Output is correct |
3 |
Correct |
47 ms |
94364 KB |
Output is correct |
4 |
Correct |
56 ms |
94996 KB |
Output is correct |
5 |
Correct |
51 ms |
94800 KB |
Output is correct |
6 |
Correct |
54 ms |
94796 KB |
Output is correct |
7 |
Correct |
49 ms |
94228 KB |
Output is correct |
8 |
Correct |
315 ms |
120228 KB |
Output is correct |
9 |
Correct |
200 ms |
108788 KB |
Output is correct |
10 |
Correct |
578 ms |
129912 KB |
Output is correct |
11 |
Correct |
374 ms |
128960 KB |
Output is correct |
12 |
Correct |
358 ms |
126844 KB |
Output is correct |
13 |
Correct |
47 ms |
94152 KB |
Output is correct |
14 |
Correct |
354 ms |
120104 KB |
Output is correct |
15 |
Correct |
72 ms |
96772 KB |
Output is correct |
16 |
Correct |
558 ms |
130100 KB |
Output is correct |
17 |
Correct |
368 ms |
127100 KB |
Output is correct |
18 |
Correct |
386 ms |
126824 KB |
Output is correct |
19 |
Correct |
862 ms |
162368 KB |
Output is correct |
20 |
Correct |
854 ms |
159728 KB |
Output is correct |
21 |
Correct |
905 ms |
162356 KB |
Output is correct |
22 |
Correct |
876 ms |
159884 KB |
Output is correct |
23 |
Correct |
858 ms |
159764 KB |
Output is correct |
24 |
Correct |
856 ms |
159780 KB |
Output is correct |
25 |
Correct |
869 ms |
159752 KB |
Output is correct |
26 |
Correct |
862 ms |
162360 KB |
Output is correct |
27 |
Correct |
899 ms |
162280 KB |
Output is correct |
28 |
Correct |
850 ms |
159928 KB |
Output is correct |
29 |
Correct |
860 ms |
159868 KB |
Output is correct |
30 |
Correct |
865 ms |
159920 KB |
Output is correct |