#include "wall.h"
/*
Author of all code: Pedro BIGMAN Dias
Last edit: 15/02/2021
*/
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#pragma GCC optimize("Ofast")
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <string>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <queue>
#include <deque>
#include <list>
#include <iomanip>
#include <stdlib.h>
#include <time.h>
#include <cstring>
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;
#define REP(i,a,b) for(ll i=(ll) a; i<(ll) b; i++)
#define pb push_back
#define mp make_pair
#define pl pair<ll,ll>
#define ff first
#define ss second
#define whole(x) x.begin(),x.end()
#define DEBUG(i) cout<<"Pedro Is The Master "<<i<<endl
#define INF 500000000LL
#define EPS 0.00000001
#define pi 3.14159
ll mod=1000000007LL;
template<class A=ll>
void Out(vector<A> a) {REP(i,0,a.size()) {cout<<a[i]<<" ";} cout<<endl;}
template<class A=ll>
void In(vector<A> &a, ll N) {A cur; REP(i,0,N) {cin>>cur; a.pb(cur);}}
vector<ll> op;
pl Reduce()
{
while(op.size()>2LL)
{
ll a = op[op.size()-3]; ll b = op[op.size()-2]; ll c = op[op.size()-1];
op.pop_back(); op.pop_back(); op.pop_back();
if(a>0 && b>0) {op.pb(max(a,b)); op.pb(c); continue;}
if(b>0 && c>0) {op.pb(a); op.pb(max(b,c)); continue;}
if(a<0 && b<0) {op.pb(max(a,b)); op.pb(c); continue;}
if(b<0 && c<0) {op.pb(max(a,b)); op.pb(c); continue;}
if(a>0 && b<0 && c>0)
{
if(abs(b)<=abs(a))
{
ll endval = max(-b,c);
op.pb(-1); op.pb(endval);
continue;
}
else if(abs(b)<=abs(c))
{
ll endval = c;
op.pb(-1); op.pb(endval);
continue;
}
else
{
op.pb(b); op.pb(max(a,c));
continue;
}
}
if(a<0 && b>0 && c<0)
{
if(abs(b)>=abs(a))
{
ll endval = min(b,-c);
op.pb(-1); op.pb(endval);
continue;
}
else if(abs(b)>=abs(c))
{
ll endval = -c;
op.pb(-1); op.pb(endval);
continue;
}
else
{
op.pb(b); op.pb(max(a,c));
continue;
}
}
}
op.pb(0LL); op.pb(0LL);
return {op[0],op[1]};
}
ll Reduce_Max(pl opp)
{
ll val = abs(opp.ff);
if(opp.ss>0) {return max(val,opp.ss);}
else {return min(val,abs(opp.ss));}
}
class ST
{
public:
ll N;
class LV //lazy value
{
public:
pl a; //elements are positive if max operation, negative if min operation.
LV() {a={1LL,1LL};}
LV(pl x) {a=x;}
LV operator & (LV X)
{
op[0]=X.a.ff; op[1]=X.a.ss; op[2]=a.ff; op[3]=a.ss;
LV ANS(Reduce());
return ANS;
}
};
LV neutl;
vector<LV> lazy;
vector<pl> range;
ST() {N=0LL;}
ST(ll n)
{
N = (ll) 1<<(ll) ceil(log2(n));
REP(i,0,2*N) {range.pb(mp(0LL,0LL));}
REP(i,0,N) {range[i+N]=mp(i,i);}
ll cur = N-1;
while(cur>0)
{
range[cur]=mp(range[2*cur].ff,range[2*cur+1].ss);
cur--;
}
REP(i,0,2*N) {lazy.pb(neutl);}
}
void prop(ll c) //how lazy values propagate
{
lazy[2*c]=lazy[c]&lazy[2*c]; lazy[2*c+1]=lazy[c]&lazy[2*c+1];
lazy[c]=neutl;
}
void update(LV s, ll a, ll b, ll c=1LL) //update LV, range [a,b], current node, current range. initially: update(s,a,b)
{
ll x=range[c].ff; ll y=range[c].ss;
if(y<a || x>b) {return ;}
if(x>=a && y<=b)
{
lazy[c]=s&lazy[c];
return;
}
prop(c);
update(s,a,b,2*c); update(s,a,b,2*c+1);
}
vector<ll> eject(ll S) //range [a,b], current node. initially: query(a,b)
{
REP(c,1LL,N) {prop(c);}
vector<ll> ans; REP(i,N,N+S) {ans.pb(Reduce_Max(lazy[i].a));}
return ans;
}
};
void buildWall(int N, int K, int oper[], int left[], int right[], int height[], int finalHeight[])
{
REP(i,0,4) {op.pb(0LL);}
ST S(N); S.update((pl) {1,-1},0,N-1);
REP(i,0,K)
{
if(oper[i]==1)
{
S.update((pl) {height[i]+1,1},left[i],right[i]);
}
else
{
S.update((pl) {-(height[i]+1),1},left[i],right[i]);
}
}
vector<ll> ans = S.eject(N);
REP(i,0,N) {finalHeight[i]=ans[i]-1;}
return;
}
Compilation message
wall.cpp:6: warning: ignoring '#pragma GCC optimization' [-Wunknown-pragmas]
6 | #pragma GCC optimization ("O3")
|
wall.cpp:7: warning: ignoring '#pragma GCC optimization' [-Wunknown-pragmas]
7 | #pragma GCC optimization ("unroll-loops")
|
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
3 ms |
332 KB |
Output is correct |
3 |
Correct |
4 ms |
332 KB |
Output is correct |
4 |
Correct |
16 ms |
1740 KB |
Output is correct |
5 |
Correct |
15 ms |
1612 KB |
Output is correct |
6 |
Correct |
15 ms |
1616 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
172 ms |
8032 KB |
Output is correct |
3 |
Correct |
483 ms |
6056 KB |
Output is correct |
4 |
Correct |
1491 ms |
18588 KB |
Output is correct |
5 |
Correct |
761 ms |
28704 KB |
Output is correct |
6 |
Correct |
753 ms |
27124 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
3 ms |
332 KB |
Output is correct |
3 |
Correct |
3 ms |
372 KB |
Output is correct |
4 |
Correct |
15 ms |
1616 KB |
Output is correct |
5 |
Correct |
12 ms |
1616 KB |
Output is correct |
6 |
Correct |
12 ms |
1616 KB |
Output is correct |
7 |
Correct |
0 ms |
204 KB |
Output is correct |
8 |
Correct |
175 ms |
8072 KB |
Output is correct |
9 |
Correct |
487 ms |
6100 KB |
Output is correct |
10 |
Correct |
1524 ms |
18524 KB |
Output is correct |
11 |
Correct |
749 ms |
28700 KB |
Output is correct |
12 |
Correct |
757 ms |
27176 KB |
Output is correct |
13 |
Correct |
1 ms |
204 KB |
Output is correct |
14 |
Correct |
180 ms |
13928 KB |
Output is correct |
15 |
Correct |
84 ms |
3896 KB |
Output is correct |
16 |
Correct |
1565 ms |
28152 KB |
Output is correct |
17 |
Correct |
745 ms |
27576 KB |
Output is correct |
18 |
Correct |
742 ms |
27600 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
2 ms |
332 KB |
Output is correct |
3 |
Correct |
3 ms |
332 KB |
Output is correct |
4 |
Correct |
15 ms |
1616 KB |
Output is correct |
5 |
Correct |
12 ms |
1612 KB |
Output is correct |
6 |
Correct |
13 ms |
1688 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
8 |
Correct |
172 ms |
8032 KB |
Output is correct |
9 |
Correct |
512 ms |
6212 KB |
Output is correct |
10 |
Correct |
1489 ms |
18524 KB |
Output is correct |
11 |
Correct |
755 ms |
28616 KB |
Output is correct |
12 |
Correct |
765 ms |
27048 KB |
Output is correct |
13 |
Correct |
0 ms |
296 KB |
Output is correct |
14 |
Correct |
179 ms |
13892 KB |
Output is correct |
15 |
Correct |
85 ms |
3868 KB |
Output is correct |
16 |
Correct |
1602 ms |
28148 KB |
Output is correct |
17 |
Correct |
762 ms |
27636 KB |
Output is correct |
18 |
Correct |
819 ms |
27556 KB |
Output is correct |
19 |
Correct |
2122 ms |
189732 KB |
Output is correct |
20 |
Correct |
2120 ms |
189736 KB |
Output is correct |
21 |
Correct |
2061 ms |
189740 KB |
Output is correct |
22 |
Correct |
2041 ms |
189748 KB |
Output is correct |
23 |
Correct |
2020 ms |
189864 KB |
Output is correct |
24 |
Correct |
2044 ms |
189736 KB |
Output is correct |
25 |
Correct |
2099 ms |
189788 KB |
Output is correct |
26 |
Correct |
2085 ms |
189732 KB |
Output is correct |
27 |
Correct |
2107 ms |
189732 KB |
Output is correct |
28 |
Correct |
2045 ms |
189732 KB |
Output is correct |
29 |
Correct |
2041 ms |
189736 KB |
Output is correct |
30 |
Correct |
2029 ms |
189752 KB |
Output is correct |