Submission #204485

# Submission time Handle Problem Language Result Execution time Memory
204485 2020-02-26T02:12:08 Z T0p_ Just Long Neckties (JOI20_ho_t1) C++14
100 / 100
253 ms 18524 KB
#include<bits/stdc++.h>
using namespace std;

#define pb push_back

struct data
{
	long long val;
	long long pos;	
	bool operator < (const data & o) const
	{
		return val < o.val;	
	}
};

long long b[200200], ans[200200], seg[2][800800];
data a[200200];
vector<data> v;

void build(int l, int r, int idx)
{
	if(l == r)
	{
		seg[0][idx] = max(0ll, a[l].val - b[l]);
		seg[1][idx] = max(0ll, a[l+1].val - b[l]);
		return ;
	}
	int mid = (l+r)>>1;
	build(l, mid, idx<<1);
	build(mid+1, r, idx<<1|1);
	for(int i=0 ; i<2 ; i++)
		seg[i][idx] = max(seg[i][idx<<1], seg[i][idx<<1|1]);
}

long long query(int l, int r, int idx, int a, int b, int s)
{
	if(r < a || b < l) return -1e15;
	if(a <= l && r <= b) return seg[s][idx];
	int mid = (l+r)>>1;
	return max(query(l, mid, idx<<1, a, b, s), query(mid+1, r, idx<<1|1, a, b, s));
}

int main()
{
	int n;
	scanf(" %d",&n);
	for(int i=1 ; i<=n+1 ; i++)
	{
		long long d;
		scanf(" %lld",&d);
		a[i] = {d, i};
	}
	for(int i=1 ; i<=n ; i++)
		scanf(" %lld",&b[i]);
	sort(a+1, a+n+2);
	sort(b+1, b+n+1);
	build(1, n, 1);
	for(int i=1 ; i<=n+1 ; i++)
	{
		long long d = max(query(1, n, 1, 1, i-1, 0), query(1, n, 1, i, n, 1));
		v.pb({a[i].pos, d});
	}
	sort(v.begin(), v.end());
	for(int i=0 ; i<=n ; i++)
		printf("%lld ",v[i].pos);
	return 0;
}

Compilation message

ho_t1.cpp: In function 'int main()':
ho_t1.cpp:46:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf(" %d",&n);
  ~~~~~^~~~~~~~~~
ho_t1.cpp:50:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf(" %lld",&d);
   ~~~~~^~~~~~~~~~~~
ho_t1.cpp:54:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf(" %lld",&b[i]);
   ~~~~~^~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 5 ms 376 KB Output is correct
3 Correct 5 ms 376 KB Output is correct
4 Correct 5 ms 376 KB Output is correct
5 Correct 5 ms 376 KB Output is correct
6 Correct 5 ms 376 KB Output is correct
7 Correct 5 ms 376 KB Output is correct
8 Correct 5 ms 376 KB Output is correct
9 Correct 6 ms 376 KB Output is correct
10 Correct 5 ms 376 KB Output is correct
11 Correct 5 ms 376 KB Output is correct
12 Correct 5 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 5 ms 376 KB Output is correct
3 Correct 5 ms 376 KB Output is correct
4 Correct 5 ms 376 KB Output is correct
5 Correct 5 ms 376 KB Output is correct
6 Correct 5 ms 376 KB Output is correct
7 Correct 5 ms 376 KB Output is correct
8 Correct 5 ms 376 KB Output is correct
9 Correct 6 ms 376 KB Output is correct
10 Correct 5 ms 376 KB Output is correct
11 Correct 5 ms 376 KB Output is correct
12 Correct 5 ms 376 KB Output is correct
13 Correct 5 ms 376 KB Output is correct
14 Correct 6 ms 504 KB Output is correct
15 Correct 6 ms 504 KB Output is correct
16 Correct 5 ms 376 KB Output is correct
17 Correct 7 ms 632 KB Output is correct
18 Correct 6 ms 504 KB Output is correct
19 Correct 6 ms 504 KB Output is correct
20 Correct 6 ms 504 KB Output is correct
21 Correct 7 ms 504 KB Output is correct
22 Correct 6 ms 504 KB Output is correct
23 Correct 8 ms 504 KB Output is correct
24 Correct 7 ms 504 KB Output is correct
25 Correct 8 ms 504 KB Output is correct
26 Correct 7 ms 504 KB Output is correct
27 Correct 6 ms 504 KB Output is correct
28 Correct 7 ms 504 KB Output is correct
29 Correct 7 ms 632 KB Output is correct
30 Correct 5 ms 504 KB Output is correct
31 Correct 8 ms 504 KB Output is correct
32 Correct 7 ms 504 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 5 ms 376 KB Output is correct
3 Correct 5 ms 376 KB Output is correct
4 Correct 5 ms 376 KB Output is correct
5 Correct 5 ms 376 KB Output is correct
6 Correct 5 ms 376 KB Output is correct
7 Correct 5 ms 376 KB Output is correct
8 Correct 5 ms 376 KB Output is correct
9 Correct 6 ms 376 KB Output is correct
10 Correct 5 ms 376 KB Output is correct
11 Correct 5 ms 376 KB Output is correct
12 Correct 5 ms 376 KB Output is correct
13 Correct 5 ms 376 KB Output is correct
14 Correct 6 ms 504 KB Output is correct
15 Correct 6 ms 504 KB Output is correct
16 Correct 5 ms 376 KB Output is correct
17 Correct 7 ms 632 KB Output is correct
18 Correct 6 ms 504 KB Output is correct
19 Correct 6 ms 504 KB Output is correct
20 Correct 6 ms 504 KB Output is correct
21 Correct 7 ms 504 KB Output is correct
22 Correct 6 ms 504 KB Output is correct
23 Correct 8 ms 504 KB Output is correct
24 Correct 7 ms 504 KB Output is correct
25 Correct 8 ms 504 KB Output is correct
26 Correct 7 ms 504 KB Output is correct
27 Correct 6 ms 504 KB Output is correct
28 Correct 7 ms 504 KB Output is correct
29 Correct 7 ms 632 KB Output is correct
30 Correct 5 ms 504 KB Output is correct
31 Correct 8 ms 504 KB Output is correct
32 Correct 7 ms 504 KB Output is correct
33 Correct 253 ms 17756 KB Output is correct
34 Correct 218 ms 18012 KB Output is correct
35 Correct 205 ms 17760 KB Output is correct
36 Correct 236 ms 18140 KB Output is correct
37 Correct 224 ms 18524 KB Output is correct
38 Correct 213 ms 18396 KB Output is correct
39 Correct 215 ms 17500 KB Output is correct
40 Correct 217 ms 17380 KB Output is correct
41 Correct 243 ms 17500 KB Output is correct
42 Correct 213 ms 17500 KB Output is correct
43 Correct 224 ms 17500 KB Output is correct
44 Correct 218 ms 17252 KB Output is correct
45 Correct 215 ms 17256 KB Output is correct
46 Correct 214 ms 17336 KB Output is correct
47 Correct 190 ms 17508 KB Output is correct
48 Correct 184 ms 17512 KB Output is correct
49 Correct 222 ms 17756 KB Output is correct
50 Correct 224 ms 17784 KB Output is correct
51 Correct 213 ms 17628 KB Output is correct
52 Correct 223 ms 17756 KB Output is correct
53 Correct 230 ms 17756 KB Output is correct