# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1062789 |
2024-08-17T10:49:35 Z |
YassirSalama |
Wall (IOI14_wall) |
C++17 |
|
3000 ms |
37968 KB |
#include "wall.h"
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int maxn = 2e6 + 100;
template<typename T>
void dbg(const T& t){
cout<<t<<endl;
return;
}
template<typename T,typename... Args>
void dbg(const T& t,const Args&... args){
cout<<t<<" , ";
dbg(args...);
}
#define dbg(...) cout<<"("<<#__VA_ARGS__<<") : "<<endl;dbg(__VA_ARGS__);
struct Node
{
ll min;
ll max;
ll smin;
ll smax;
ll cntmin;
ll cntmax;
ll lzmin=-1,lzmax=-1;
bool lazy=false;
Node* left,*right;
Node() : left(nullptr),right(nullptr){}
};
void pull(Node* node){
//for min
node->min=min(node->left->min,node->right->min);
if(node->min==node->left->min){
if(node->min==node->right->min){
node->cntmin=node->left->cntmin+node->right->cntmin;
node->smin=min(node->left->smin,node->right->min);
}else {
node->smin=min({node->left->smin,node->right->min});
node->cntmin=node->left->cntmin;
}
}else{
node->smin=min({node->right->smin,node->left->min});
node->cntmin=node->right->cntmin;
}
//for max
node->max=max(node->left->max,node->right->max);
if(node->max==node->left->max){
if(node->max==node->right->max){
node->cntmax=node->left->cntmax+node->right->cntmax;
node->smax=max(node->left->smax,node->right->max);
}else {
node->smax=max({node->left->smax,node->right->max});
node->cntmax=node->left->cntmax;
}
}else{
node->smax=max({node->right->smax,node->left->max});
node->cntmax=node->right->cntmax;
}
}
void build(Node* node,int l,int r){
if(l==r){
node->min=node->max=0;
node->cntmin=node->cntmax=1;
node->smin=1e18;
node->smax=-1e18;
return;
}
int mid=(l+r)/2;
node->left=new Node();
node->right=new Node();
build(node->left,l,mid);
build(node->right,mid+1,r);
pull(node);
}
void pmin(Node* node,int l,int r){
if(node->smax<=node->lzmin&&node->lzmin<node->max){
node->max=node->lzmin;
node->min=min(node->min,node->lzmin);
if(l==r) return;
node->left->lazy=1;
node->right->lazy=1;
node->left->lzmin=node->lzmin;
node->right->lzmin=node->lzmin;
}
return;
}
void pmax(Node* node,int l,int r){
if(node->smin>=node->lzmax&&node->lzmax>node->min){
node->min=node->lzmax;
node->max=max(node->max,node->lzmax);
if(l==r) return;
node->left->lazy=1;
node->right->lazy=1;
node->left->lzmax=node->lzmax;
node->right->lzmax=node->lzmax;
}
return;
}
void push(Node* node,int l,int r){
if(node->lazy==false) return;
if(node->lzmin!=-1){
pmin(node,l,r);
}
if(node->lzmax!=-1){
pmax(node,l,r);
}
node->lazy=false;
node->lzmin=node->lzmax=-1;
}
void p(Node* node,int l,int r){
push(node,l,r);
if(l==r) return;
push(node->left,l,(l+r)/2);
push(node->right,(l+r)/2+1,r);
pull(node);
}
void setmin(Node* node,int l,int r,int ql,int qr,int x){
p(node,l,r);
if(l>qr||r<ql) return;
if(node->max<=x) return;
if(ql<=l&&r<=qr&&node->smax<=x&&x<node->max){
//put tag
node->lazy=1;
node->lzmin=x;
p(node,l,r);
return;
}
int mid=(l+r)/2;
setmin(node->left,l,mid,ql,qr,x);
setmin(node->right,mid+1,r,ql,qr,x);
p(node,l,r);
}
void setmax(Node* node,int l,int r,int ql,int qr,int x){
p(node,l,r);
if(l>qr||r<ql) return;
if(node->min>=x) return;
if(ql<=l&&r<=qr&&node->smin>=x&&x>node->min){
//put tag
node->lazy=1;
node->lzmax=x;
p(node,l,r);
return;
}
int mid=(l+r)/2;
setmax(node->left,l,mid,ql,qr,x);
setmax(node->right,mid+1,r,ql,qr,x);
p(node,l,r);
}
int query(Node* node,int l,int r,int ql){
push(node,l,r);
if(l==r) return node->min;
int mid = (l+r)/2;
if(ql<=mid) return query(node->left,l,mid,ql);
else return query(node->right,mid+1,r,ql);
}
void buildWall(int n, int k, int op[], int left[], int right[], int height[], int ans[])
{
Node* root=new Node();
build(root,0,n-1);
for(int i=0;i<k;i++){
int t=op[i];
int l=left[i];
int r=right[i];
int x=height[i];
if(t==1){
setmax(root,0,n-1,l,r,x);
}else{
setmin(root,0,n-1,l,r,x);
}
}
for(int i=0;i<n;i++){
ans[i]=query(root,0,n-1,i);
}
return;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
3 ms |
348 KB |
Output is correct |
4 |
Correct |
211 ms |
2492 KB |
Output is correct |
5 |
Correct |
343 ms |
2504 KB |
Output is correct |
6 |
Correct |
334 ms |
2392 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
82 ms |
13064 KB |
Output is correct |
3 |
Correct |
63 ms |
10324 KB |
Output is correct |
4 |
Correct |
181 ms |
35360 KB |
Output is correct |
5 |
Correct |
159 ms |
36268 KB |
Output is correct |
6 |
Correct |
185 ms |
35012 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
3 ms |
348 KB |
Output is correct |
4 |
Correct |
189 ms |
2508 KB |
Output is correct |
5 |
Correct |
331 ms |
2392 KB |
Output is correct |
6 |
Correct |
328 ms |
2488 KB |
Output is correct |
7 |
Correct |
0 ms |
344 KB |
Output is correct |
8 |
Correct |
80 ms |
14036 KB |
Output is correct |
9 |
Correct |
65 ms |
10832 KB |
Output is correct |
10 |
Correct |
198 ms |
36996 KB |
Output is correct |
11 |
Correct |
145 ms |
37968 KB |
Output is correct |
12 |
Correct |
190 ms |
36568 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
88 ms |
13872 KB |
Output is correct |
15 |
Correct |
2036 ms |
4712 KB |
Output is correct |
16 |
Execution timed out |
3055 ms |
36472 KB |
Time limit exceeded |
17 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
344 KB |
Output is correct |
3 |
Correct |
3 ms |
548 KB |
Output is correct |
4 |
Correct |
188 ms |
2496 KB |
Output is correct |
5 |
Correct |
347 ms |
2392 KB |
Output is correct |
6 |
Correct |
338 ms |
2496 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
80 ms |
14036 KB |
Output is correct |
9 |
Correct |
64 ms |
10900 KB |
Output is correct |
10 |
Correct |
195 ms |
37032 KB |
Output is correct |
11 |
Correct |
148 ms |
37936 KB |
Output is correct |
12 |
Correct |
179 ms |
36576 KB |
Output is correct |
13 |
Correct |
0 ms |
344 KB |
Output is correct |
14 |
Correct |
98 ms |
13988 KB |
Output is correct |
15 |
Correct |
2052 ms |
4696 KB |
Output is correct |
16 |
Execution timed out |
3073 ms |
36436 KB |
Time limit exceeded |
17 |
Halted |
0 ms |
0 KB |
- |