Submission #793072

# Submission time Handle Problem Language Result Execution time Memory
793072 2023-07-25T13:32:47 Z I_Love_EliskaM_ Wall (IOI14_wall) C++14
100 / 100
803 ms 157808 KB
#include "wall.h"
#include <bits/stdc++.h>
using namespace std;
#define forn(i,n) for(int i=0;i<n;++i)
#define pb push_back

struct sgt {
	vector<int> mx,mn; int sz=1;
	vector<int> lazy;
	vector<int> type;
	void upd(int v, int t, int x) {
		if (v>=2*sz-1) return;
		if (t==3) {
			type[v]=3;
			lazy[v]=x;
			return;
		}
		if (type[v]==0) {
			type[v]=t;
			lazy[v]=x;
			return;
		}
		if (type[v]==1) {
			if (t==1) {
				lazy[v]=max(lazy[v],x);
				return;
			}
			if (x <= lazy[v]) {
				type[v]=3;
				lazy[v]=x;
			} else {
				mn[v]=max(mn[v],lazy[v]);
				mx[v]=max(mx[v],lazy[v]);
				upd(2*v+1,type[v],lazy[v]);
				upd(2*v+2,type[v],lazy[v]);
				type[v]=2;
				lazy[v]=x;
			}
			return;
		}
		if (type[v]==2) {
			if (t==2) {
				lazy[v]=min(lazy[v],x);
				return;
			}
			if (x >= lazy[v]) {
				type[v]=3;
				lazy[v]=x;
			} else {
				mx[v]=min(mx[v],lazy[v]);
				mn[v]=min(mn[v],lazy[v]);
				upd(2*v+1,type[v],lazy[v]);
				upd(2*v+2,type[v],lazy[v]);
				type[v]=1;
				lazy[v]=x;
			}
			return;
		}
		if (type[v]==3) {
			if (t==1) {
				lazy[v]=max(lazy[v],x);
			} else {
				lazy[v]=min(lazy[v],x);
			}
		}
	}
	void push(int v) {
		//if (type[2*v+1]) push(2*v+1);
		//if (type[2*v+2]) push(2*v+2);
		upd(2*v+1,type[v],lazy[v]);
		upd(2*v+2,type[v],lazy[v]);
		if (type[v]==1) {
			mn[v]=max(mn[v],lazy[v]);
			mx[v]=max(mx[v],lazy[v]);
		} else if (type[v]==2) {
			mx[v]=min(mx[v],lazy[v]);
			mn[v]=min(mn[v],lazy[v]);
		} else {
			mn[v]=mx[v]=lazy[v];
		}
		type[v]=0;
		lazy[v]=0;
	}
	sgt(int n) {
		while (sz<n) sz<<=1;
		mx.assign(4*sz,0);
		mn=lazy=type=mx;
	}

	void setmax(int v, int l, int r, int lx, int rx, int x) {
		if (type[v]) push(v);
		if (mn[v]>=x) return;
		if (rx<=l || r<=lx) return;
		if (lx<=l && r<=rx) {
			upd(v,1,x);
			push(v);
			return;
		}
		int m=(l+r)>>1;
		setmax(2*v+1,l,m,lx,rx,x);
		setmax(2*v+2,m,r,lx,rx,x);
		mx[v]=max(mx[2*v+1],mx[2*v+2]);
		mn[v]=min(mn[2*v+1],mn[2*v+2]);
	}
	void setmax(int l, int r, int x) {
		setmax(0,0,sz,l,r,x);
	}

	void setmin(int v, int l, int r, int lx, int rx, int x) {
		if (type[v]) push(v);
		if (mx[v]<=x) return;
		if (rx<=l || r<=lx) return;
		if (lx<=l && r<=rx) {
			upd(v,2,x);
			push(v);
			return;
		}
		int m=(l+r)>>1;
		setmin(2*v+1,l,m,lx,rx,x);
		setmin(2*v+2,m,r,lx,rx,x);
		mx[v]=max(mx[2*v+1],mx[2*v+2]);
		mn[v]=min(mn[2*v+1],mn[2*v+2]);
	}
	void setmin(int l, int r, int x) {
		setmin(0,0,sz,l,r,x);
	}

	void dfs(int v, int l, int r) {
		if (type[v]) push(v);
		if (r-l==1) return;
		int m=(l+r)>>1;
		dfs(2*v+1,l,m);
		dfs(2*v+2,m,r);
	}
	void dfs() {
		dfs(0,0,sz);
	}

};

void buildWall(int n, int k, int t[], int l[], int r[], int a[], int ans[]) {

	sgt st(n);
	forn(i,k) {
		if (t[i]==1) {
			st.setmax(l[i],r[i]+1,a[i]);
		} else {
			st.setmin(l[i],r[i]+1,a[i]);
		}

		//st.dfs();
		//forn(j,2*st.sz-1) cout<<j<<": "<<st.mn[j]<<' '<<st.mx[j]<<' '<<st.type[j]<<' '<<st.lazy[j]<<'\n';
		//forn(j,n) cout<<st.mn[st.sz-1+j]<<' '; cout<<'\n';
		//forn(j,n) cout<<st.mx[st.sz-1+j]<<' '; cout<<'\n';
		//cout<<'\n';
	}
	st.dfs();
	forn(i,n) ans[i]=st.mn[st.sz-1+i];

}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 2 ms 340 KB Output is correct
3 Correct 2 ms 312 KB Output is correct
4 Correct 6 ms 1492 KB Output is correct
5 Correct 5 ms 1516 KB Output is correct
6 Correct 5 ms 1492 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 106 ms 8360 KB Output is correct
3 Correct 55 ms 5848 KB Output is correct
4 Correct 131 ms 16976 KB Output is correct
5 Correct 137 ms 16972 KB Output is correct
6 Correct 181 ms 17016 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 296 KB Output is correct
2 Correct 2 ms 440 KB Output is correct
3 Correct 2 ms 340 KB Output is correct
4 Correct 6 ms 1492 KB Output is correct
5 Correct 5 ms 1492 KB Output is correct
6 Correct 5 ms 1492 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 107 ms 13884 KB Output is correct
9 Correct 55 ms 9420 KB Output is correct
10 Correct 144 ms 26336 KB Output is correct
11 Correct 147 ms 26784 KB Output is correct
12 Correct 170 ms 25220 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 118 ms 13940 KB Output is correct
15 Correct 28 ms 3428 KB Output is correct
16 Correct 529 ms 26340 KB Output is correct
17 Correct 244 ms 25768 KB Output is correct
18 Correct 238 ms 25768 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 2 ms 340 KB Output is correct
3 Correct 2 ms 328 KB Output is correct
4 Correct 5 ms 1492 KB Output is correct
5 Correct 4 ms 1492 KB Output is correct
6 Correct 4 ms 1492 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 113 ms 13868 KB Output is correct
9 Correct 55 ms 9452 KB Output is correct
10 Correct 136 ms 26324 KB Output is correct
11 Correct 148 ms 26856 KB Output is correct
12 Correct 158 ms 25384 KB Output is correct
13 Correct 0 ms 304 KB Output is correct
14 Correct 114 ms 13872 KB Output is correct
15 Correct 28 ms 3432 KB Output is correct
16 Correct 473 ms 26276 KB Output is correct
17 Correct 237 ms 25672 KB Output is correct
18 Correct 239 ms 25764 KB Output is correct
19 Correct 720 ms 157688 KB Output is correct
20 Correct 730 ms 157720 KB Output is correct
21 Correct 711 ms 157716 KB Output is correct
22 Correct 745 ms 157808 KB Output is correct
23 Correct 740 ms 157712 KB Output is correct
24 Correct 748 ms 157780 KB Output is correct
25 Correct 726 ms 157712 KB Output is correct
26 Correct 728 ms 157712 KB Output is correct
27 Correct 741 ms 157608 KB Output is correct
28 Correct 803 ms 157684 KB Output is correct
29 Correct 748 ms 157744 KB Output is correct
30 Correct 769 ms 157712 KB Output is correct