# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
766012 |
2023-06-25T08:45:21 Z |
emad234 |
Wall (IOI14_wall) |
C++17 |
|
383 ms |
22400 KB |
#include <bits/stdc++.h>
#define aint(v) ((v).bvin(),(v).end())
#define ll long long
using namespace std;
const int mod = 1e9 + 7;
const int mxN = 8e6 + 1;
int seg[mxN],lazyMx[mxN],lazyMn[mxN];
int N,s,e,val;
void spread(int l,int r, int ind){
if(l != r){
seg[ind * 2] = max(seg[ind * 2],lazyMx[ind]);
seg[ind * 2] = min(seg[ind * 2],lazyMn[ind]);
lazyMx[ind * 2] = max(lazyMx[ind * 2],lazyMx[ind]);
lazyMn[ind * 2] = min(lazyMn[ind * 2],lazyMn[ind]);
seg[ind * 2 + 1] = max(seg[ind * 2 + 1],lazyMx[ind]);
seg[ind * 2 + 1] = min(seg[ind * 2 + 1],lazyMn[ind]);
lazyMx[ind * 2 + 1] = max(lazyMx[ind * 2 + 1],lazyMx[ind]);
lazyMn[ind * 2 + 1] = min(lazyMn[ind * 2 + 1],lazyMn[ind]);
}
lazyMn[ind] = 1e9;
lazyMx[ind] = 0;
}
void updateMn(int l = 1,int r = N,int ind = 1){
if(l > e || r < s) return;
if(l >= s && r <= e){
spread(l,r,ind);
lazyMn[ind] = min(lazyMn[ind],val);
seg[ind] = min(seg[ind],val);
spread(l,r,ind);
return;
}
int md = (l + r) / 2;
updateMn(l,md,ind * 2);updateMn(md + 1,r,ind * 2 + 1);
}
void updateMx(int l = 1,int r = N,int ind = 1){
if(l > e || r < s) return;
if(l >= s && r <= e){
spread(l,r,ind);
lazyMx[ind] = max(lazyMx[ind],val);
seg[ind] = max(seg[ind],val);
spread(l,r,ind);
return;
}
int md = (l + r) / 2;
updateMx(l,md,ind * 2);updateMx(md + 1,r,ind * 2 + 1);
}
int query(int l = 1,int r = N,int ind = 1){
spread(l,r,ind);
if(l > e || r < s) return 0;
if(l >= s && r <= e) {
spread(l,r,ind);
return seg[ind];
}
int md = (l + r) / 2;
return max(query(l,md,ind * 2),query(md + 1,r,ind * 2 + 1));
}
void printseg(){
int p2 = 1;
for(int i = 1;i <= N;i++){
spread(1,2,i);
// cout<<seg[i]<<' ';
// if(p2 * 2 - 1 == i){
// cout<<'\n';
// p2 = p2 * 2;
// }
}
}
void buildWall(int n,int k,int op[],int left[],int right[],int height[],int finalHeight[]){
N = exp2(ceil(log2(n)));
for(int i = 0; i<= N;i++){
lazyMn[i] = 1e9;
}
bool sec = 0;
for(int i = 0;i < k;i++){
s = left[i] + 1,e = right[i] + 1;
val = height[i];
if(op[i] == 1){
updateMx();
}else{
if(!sec){
printseg();
sec = 1;
}
updateMn();
}
}
for(int i = 0 ; i <n;i++){
s = e = i + 1;
finalHeight[i] = query();
}
}
// main()
// {
// int n;
// int k;
//
// int i, j;
// int status = 0;
//
// status = scanf("%d%d", &n, &k);
// assert(status == 2);
//
// int* op = (int*)calloc(sizeof(int), k);
// int* left = (int*)calloc(sizeof(int), k);
// int* right = (int*)calloc(sizeof(int), k);
// int* height = (int*)calloc(sizeof(int), k);
// int* finalHeight = (int*)calloc(sizeof(int), n);
//
// for (i = 0; i < k; i++){
// status = scanf("%d%d%d%d", &op[i], &left[i], &right[i], &height[i]);
// assert(status == 4);
// }
//
// buildWall(n, k, op, left, right, height, finalHeight);
//
// for (j = 0; j < n; j++)
// printf("%d ", finalHeight[j]);
//
// return 0;
// }
Compilation message
wall.cpp: In function 'void printseg()':
wall.cpp:58:7: warning: unused variable 'p2' [-Wunused-variable]
58 | int p2 = 1;
| ^~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
2 ms |
468 KB |
Output is correct |
3 |
Incorrect |
2 ms |
340 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
312 KB |
Output is correct |
2 |
Correct |
110 ms |
13956 KB |
Output is correct |
3 |
Correct |
126 ms |
8204 KB |
Output is correct |
4 |
Correct |
383 ms |
21336 KB |
Output is correct |
5 |
Correct |
227 ms |
22400 KB |
Output is correct |
6 |
Correct |
212 ms |
20832 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
2 ms |
468 KB |
Output is correct |
3 |
Incorrect |
2 ms |
468 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
316 KB |
Output is correct |
2 |
Correct |
2 ms |
340 KB |
Output is correct |
3 |
Incorrect |
2 ms |
328 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |