Submission #862922

# Submission time Handle Problem Language Result Execution time Memory
862922 2023-10-19T11:27:09 Z Trisanu_Das Measures (CEOI22_measures) C++17
100 / 100
214 ms 34900 KB
#include <bits/stdc++.h>
#define int long long
using namespace std;
 
struct node{
	int mx, mn, ans;
};
 
const int N = 2e5, inf = 1e17;
 
node segt[4 * N + 5];
int lazy[4 * N + 5];
 
node merge(node a, node b){
	node c;
	c.ans = max({a.ans, b.ans, a.mx - b.mn});
	c.mx = max(a.mx, b.mx);
	c.mn = min(a.mn, b.mn);
	return c;
}
 
void update(int idx, int l, int r, int L, int R, int val){
	if (l > R or r < L) return;
	if (l >= L and r <= R){
		if (L == R) segt[idx] = {val + lazy[idx], val + lazy[idx], 0};
		else{
			segt[idx].mx += val;
			segt[idx].mn += val;
			lazy[idx] += val;
		}
		return;
	}
	for (int k : {2 * idx, 2 * idx + 1}){
		segt[k].mn += lazy[idx];
		segt[k].mx += lazy[idx];
		lazy[k] += lazy[idx];
	}
	lazy[idx] = 0;
	int mid = (l + r) / 2;
	update(2 * idx, l, mid, L, R, val);
	update(2 * idx + 1, mid + 1, r, L, R, val);
	segt[idx] = merge(segt[2 * idx], segt[2 * idx + 1]);
}
 
signed main(){
	ios::sync_with_stdio(false); cin.tie(NULL);
	int n, m, d; cin >> n >> m >> d;
	fill_n(segt, 4 * N + 5, node{-INT_MIN, INT_MAX, INT_MIN});
	vector<int> init(n + m), to(n + m);
	vector<pair<int,int>> a(n + m); 
	for (int i = 0; i < n + m; i++){
		cin >> init[i];
		a[i] = {init[i], i};
	}
	sort(a.begin(),a.end());
	for (int i = 0; i < n + m; i++) to[a[i].second] = i;
	for (int i = 0; i < n + m; i++){
		int pos = to[i];
		update(1, 0, n + m + 4, pos, pos, init[i]);
		update(1, 0, n + m + 4, pos + 1, n + m + 4, -d);
		if (i >= n){
			int ans = segt[1].ans;
			cout << ans/2;
			if (ans & 1) cout << ".5";
			cout << ' ';
		}
	}
}

Compilation message

Main.cpp: In function 'int main()':
Main.cpp:48:31: warning: integer overflow in expression of type 'int' results in '-2147483648' [-Woverflow]
   48 |  fill_n(segt, 4 * N + 5, node{-INT_MIN, INT_MAX, INT_MIN});
      |                               ^
# Verdict Execution time Memory Grader output
1 Correct 4 ms 21084 KB Output is correct
2 Correct 4 ms 21084 KB Output is correct
3 Correct 4 ms 21084 KB Output is correct
4 Correct 4 ms 21084 KB Output is correct
5 Correct 4 ms 21084 KB Output is correct
6 Correct 4 ms 21080 KB Output is correct
7 Correct 4 ms 21084 KB Output is correct
8 Correct 4 ms 21084 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 21084 KB Output is correct
2 Correct 4 ms 21084 KB Output is correct
3 Correct 4 ms 21084 KB Output is correct
4 Correct 4 ms 21084 KB Output is correct
5 Correct 4 ms 21084 KB Output is correct
6 Correct 4 ms 21080 KB Output is correct
7 Correct 4 ms 21084 KB Output is correct
8 Correct 4 ms 21084 KB Output is correct
9 Correct 188 ms 31764 KB Output is correct
10 Correct 202 ms 31568 KB Output is correct
11 Correct 152 ms 31596 KB Output is correct
12 Correct 176 ms 32144 KB Output is correct
13 Correct 155 ms 31568 KB Output is correct
14 Correct 167 ms 31568 KB Output is correct
15 Correct 213 ms 31856 KB Output is correct
16 Correct 149 ms 31636 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 161 ms 32592 KB Output is correct
2 Correct 167 ms 34516 KB Output is correct
3 Correct 172 ms 34668 KB Output is correct
4 Correct 161 ms 32368 KB Output is correct
5 Correct 179 ms 33828 KB Output is correct
6 Correct 199 ms 32728 KB Output is correct
7 Correct 177 ms 33896 KB Output is correct
8 Correct 180 ms 32408 KB Output is correct
9 Correct 162 ms 32336 KB Output is correct
10 Correct 169 ms 34812 KB Output is correct
11 Correct 167 ms 33240 KB Output is correct
12 Correct 165 ms 34132 KB Output is correct
13 Correct 163 ms 32512 KB Output is correct
14 Correct 174 ms 34444 KB Output is correct
15 Correct 168 ms 34228 KB Output is correct
16 Correct 164 ms 32640 KB Output is correct
17 Correct 186 ms 33808 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 161 ms 32592 KB Output is correct
2 Correct 167 ms 34516 KB Output is correct
3 Correct 172 ms 34668 KB Output is correct
4 Correct 161 ms 32368 KB Output is correct
5 Correct 179 ms 33828 KB Output is correct
6 Correct 199 ms 32728 KB Output is correct
7 Correct 177 ms 33896 KB Output is correct
8 Correct 180 ms 32408 KB Output is correct
9 Correct 162 ms 32336 KB Output is correct
10 Correct 169 ms 34812 KB Output is correct
11 Correct 167 ms 33240 KB Output is correct
12 Correct 165 ms 34132 KB Output is correct
13 Correct 163 ms 32512 KB Output is correct
14 Correct 174 ms 34444 KB Output is correct
15 Correct 168 ms 34228 KB Output is correct
16 Correct 164 ms 32640 KB Output is correct
17 Correct 186 ms 33808 KB Output is correct
18 Correct 207 ms 32848 KB Output is correct
19 Correct 214 ms 34536 KB Output is correct
20 Correct 184 ms 34704 KB Output is correct
21 Correct 187 ms 32592 KB Output is correct
22 Correct 192 ms 32876 KB Output is correct
23 Correct 169 ms 32628 KB Output is correct
24 Correct 210 ms 33360 KB Output is correct
25 Correct 167 ms 32532 KB Output is correct
26 Correct 203 ms 32336 KB Output is correct
27 Correct 212 ms 34900 KB Output is correct
28 Correct 193 ms 32944 KB Output is correct
29 Correct 202 ms 34208 KB Output is correct
30 Correct 208 ms 32364 KB Output is correct
31 Correct 192 ms 34384 KB Output is correct
32 Correct 186 ms 34132 KB Output is correct
33 Correct 208 ms 32596 KB Output is correct
34 Correct 193 ms 33624 KB Output is correct