Submission #59179

# Submission time Handle Problem Language Result Execution time Memory
59179 2018-07-20T22:14:35 Z TadijaSebez Wall (IOI14_wall) C++11
100 / 100
1512 ms 208664 KB
#include "wall.h"
#include <stdio.h>
#include <vector>
using namespace std;
#define pb push_back
const int N=2000050;
const int M=2*N;
const int inf=2e9+7;
int ls[M],rs[M],val[M],lzy1[M],lzy2[M],tsz,root;
int min(int a, int b){ return a>b?b:a;}
int max(int a, int b){ return a>b?a:b;}
void Build(int &c, int ss, int se)
{
	c=++tsz;lzy1[c]=0;lzy2[c]=inf;
	if(ss==se) return;
	int mid=ss+se>>1;
	Build(ls[c],ss,mid);
	Build(rs[c],mid+1,se);
}
void Push(int c, int ss, int se)
{
	val[c]=max(val[c],lzy1[c]);
	val[c]=min(val[c],lzy2[c]);
	if(ss!=se)
	{
		lzy1[ls[c]]=max(lzy1[ls[c]],lzy1[c]);
		lzy1[ls[c]]=min(lzy1[ls[c]],lzy2[c]);
		lzy2[ls[c]]=max(lzy2[ls[c]],lzy1[c]);
		lzy2[ls[c]]=min(lzy2[ls[c]],lzy2[c]);
		lzy1[rs[c]]=max(lzy1[rs[c]],lzy1[c]);
		lzy1[rs[c]]=min(lzy1[rs[c]],lzy2[c]);
		lzy2[rs[c]]=max(lzy2[rs[c]],lzy1[c]);
		lzy2[rs[c]]=min(lzy2[rs[c]],lzy2[c]);
	}
	lzy1[c]=0;
	lzy2[c]=inf;
}
void Add(int c, int ss, int se, int qs, int qe, int h)
{
	Push(c,ss,se);
	if(qs>se || ss>qe) return;
	if(qs<=ss && qe>=se){ lzy1[c]=h;return;}
	int mid=ss+se>>1;
	Add(ls[c],ss,mid,qs,qe,h);
	Add(rs[c],mid+1,se,qs,qe,h);
}
void Del(int c, int ss, int se, int qs, int qe, int h)
{
	Push(c,ss,se);
	if(qs>se || ss>qe) return;
	if(qs<=ss && qe>=se){ lzy2[c]=h;return;}
	int mid=ss+se>>1;
	Del(ls[c],ss,mid,qs,qe,h);
	Del(rs[c],mid+1,se,qs,qe,h);
}
int sol[N];
void DFS(int c, int ss, int se)
{
	Push(c,ss,se);
	if(ss==se){ sol[ss]=val[c];return;}
	int mid=ss+se>>1;
	DFS(ls[c],ss,mid);
	DFS(rs[c],mid+1,se);
}
void buildWall(int n, int q, int op[], int l[], int r[], int h[], int ans[])
{
	int i;
	Build(root,1,n);
	for(i=0;i<q;i++)
	{
		l[i]++;r[i]++;
		if(op[i]==1) Add(root,1,n,l[i],r[i],h[i]);
		else Del(root,1,n,l[i],r[i],h[i]);
	}
	DFS(root,1,n);
	for(i=1;i<=n;i++) ans[i-1]=sol[i];
}

Compilation message

wall.cpp: In function 'void Build(int&, int, int)':
wall.cpp:16:12: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
  int mid=ss+se>>1;
          ~~^~~
wall.cpp: In function 'void Add(int, int, int, int, int, int)':
wall.cpp:43:12: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
  int mid=ss+se>>1;
          ~~^~~
wall.cpp: In function 'void Del(int, int, int, int, int, int)':
wall.cpp:52:12: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
  int mid=ss+se>>1;
          ~~^~~
wall.cpp: In function 'void DFS(int, int, int)':
wall.cpp:61:12: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
  int mid=ss+se>>1;
          ~~^~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 248 KB Output is correct
2 Correct 4 ms 484 KB Output is correct
3 Correct 4 ms 620 KB Output is correct
4 Correct 10 ms 1212 KB Output is correct
5 Correct 9 ms 1348 KB Output is correct
6 Correct 10 ms 1492 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 1492 KB Output is correct
2 Correct 212 ms 10724 KB Output is correct
3 Correct 271 ms 10724 KB Output is correct
4 Correct 968 ms 25404 KB Output is correct
5 Correct 526 ms 34516 KB Output is correct
6 Correct 514 ms 34516 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 34516 KB Output is correct
2 Correct 5 ms 34516 KB Output is correct
3 Correct 3 ms 34516 KB Output is correct
4 Correct 15 ms 34516 KB Output is correct
5 Correct 10 ms 34516 KB Output is correct
6 Correct 10 ms 34516 KB Output is correct
7 Correct 2 ms 34516 KB Output is correct
8 Correct 240 ms 34516 KB Output is correct
9 Correct 348 ms 34516 KB Output is correct
10 Correct 967 ms 34516 KB Output is correct
11 Correct 468 ms 34572 KB Output is correct
12 Correct 454 ms 34644 KB Output is correct
13 Correct 3 ms 34644 KB Output is correct
14 Correct 201 ms 34644 KB Output is correct
15 Correct 51 ms 34644 KB Output is correct
16 Correct 1030 ms 34644 KB Output is correct
17 Correct 490 ms 34644 KB Output is correct
18 Correct 579 ms 34644 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 34644 KB Output is correct
2 Correct 4 ms 34644 KB Output is correct
3 Correct 4 ms 34644 KB Output is correct
4 Correct 12 ms 34644 KB Output is correct
5 Correct 9 ms 34644 KB Output is correct
6 Correct 10 ms 34644 KB Output is correct
7 Correct 2 ms 34644 KB Output is correct
8 Correct 204 ms 34644 KB Output is correct
9 Correct 303 ms 34644 KB Output is correct
10 Correct 962 ms 34644 KB Output is correct
11 Correct 441 ms 34672 KB Output is correct
12 Correct 436 ms 34672 KB Output is correct
13 Correct 2 ms 34672 KB Output is correct
14 Correct 199 ms 34672 KB Output is correct
15 Correct 44 ms 34672 KB Output is correct
16 Correct 1147 ms 34672 KB Output is correct
17 Correct 468 ms 34672 KB Output is correct
18 Correct 482 ms 34672 KB Output is correct
19 Correct 1210 ms 133124 KB Output is correct
20 Correct 1101 ms 133124 KB Output is correct
21 Correct 1209 ms 133292 KB Output is correct
22 Correct 1275 ms 140840 KB Output is correct
23 Correct 1258 ms 150704 KB Output is correct
24 Correct 1301 ms 150704 KB Output is correct
25 Correct 1176 ms 159844 KB Output is correct
26 Correct 1221 ms 172760 KB Output is correct
27 Correct 1328 ms 183468 KB Output is correct
28 Correct 1218 ms 190388 KB Output is correct
29 Correct 1512 ms 199648 KB Output is correct
30 Correct 1254 ms 208664 KB Output is correct