답안 #799256

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
799256 2023-07-31T11:18:31 Z IvanJ Measures (CEOI22_measures) C++17
100 / 100
287 ms 28588 KB
#include<bits/stdc++.h>

#define pb push_back
#define x first
#define y second
#define all(a) (a).begin(), (a).end()

using namespace std;

typedef long long ll;
typedef pair<int, int> ii;

const int maxn = 4e5 + 5;
const ll inf = 1e18;

struct Data {
	ll ans, cnt, mini, maxi;
};

Data merge(Data A, Data B) {
	if(B.cnt == 0) return A;
	if(A.cnt == 0) return B;
	Data ret;
	ret.ans = max(A.ans, B.ans);
	ret.ans = max(ret.ans, B.maxi - A.mini);
	ret.cnt = A.cnt + B.cnt;
	ret.mini = min(A.mini, B.mini);
	ret.maxi = max(A.maxi, B.maxi);
	return ret;
}

int n, m, d;
int A[maxn];
int B[maxn];
vector<int> vals;

struct Seg {
	int pot;
	vector<ll> L;
	vector<Data> T;
	void init(int sz) {
		pot = 1;
		while(pot < sz) pot <<= 1;
		L = vector<ll>(pot << 1, 0);
		T = vector<Data>(pot << 1, {0, 0, 0, 0});
	}
	
	void prop(int x) {
		if(L[x] == 0) return;
		T[x].mini += L[x], T[x].maxi += L[x];
		if(x < pot) 
			L[x * 2] += L[x], L[x * 2 + 1] += L[x];
		L[x] = 0;
	}
	
	void update(int x, int lo, int hi, int a, int b, ll v) {
		prop(x);
		if(hi < a || b < lo) return;
		if(a <= lo && hi <= b) {
			if(v < 0) T[x].cnt = 1;
			L[x] += v;
			prop(x);
			return;
		}
		int mid = (lo + hi) / 2;
		update(x * 2, lo, mid, a, b, v);
		update(x * 2 + 1, mid + 1, hi, a, b, v);
		T[x] = merge(T[x * 2], T[x * 2 + 1]);
	}
	
	void add(int x) {
		update(1, 0, pot - 1, x, x, -vals[x]);
		update(1, 0, pot - 1, x + 1, pot - 1, d);
	}
	
	ll query(int x, int lo, int hi, int a) {
		prop(x);
		if(lo == hi) return T[x].mini;
		int mid = (lo + hi) / 2;
		if(a <= mid)
			return query(x * 2, lo, mid, a);
		return query(x * 2 + 1, mid + 1, hi, a);
	}
	
	void get() {
		ll sol = T[1].ans;
		if(sol & 1) printf("%lld.5 ", sol / 2);
		else printf("%lld ", sol / 2);
	}
} S;

void compress() {
	vector<pair<int, ii>> v;
	for(int i = 0;i < n;i++) 
		v.pb({A[i], {0, i}});
	for(int i = 0;i < m;i++) 
		v.pb({B[i], {1, i}});
	sort(all(v));
	for(int i = 0;i < n + m;i++) {
		vals.pb(v[i].x);
		if(v[i].y.x == 0) A[v[i].y.y] = i;
		if(v[i].y.x == 1) B[v[i].y.y] = i;
	} 
}

int main() {
	scanf("%d%d%d", &n, &m, &d);
	for(int i = 0;i < n;i++) 
		scanf("%d", A + i);
	for(int i = 0;i < m;i++) 
		scanf("%d", B + i);
	
	compress();
	S.init(n + m + 1);
	for(int i = 0;i < n;i++) S.add(A[i]);
	for(int i = 0;i < m;i++) S.add(B[i]), S.get();
	printf("\n");
	return 0;
}

Compilation message

Main.cpp: In function 'int main()':
Main.cpp:107:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
  107 |  scanf("%d%d%d", &n, &m, &d);
      |  ~~~~~^~~~~~~~~~~~~~~~~~~~~~
Main.cpp:109:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
  109 |   scanf("%d", A + i);
      |   ~~~~~^~~~~~~~~~~~~
Main.cpp:111:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
  111 |   scanf("%d", B + i);
      |   ~~~~~^~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 448 KB Output is correct
2 Correct 1 ms 468 KB Output is correct
3 Correct 2 ms 468 KB Output is correct
4 Correct 2 ms 468 KB Output is correct
5 Correct 2 ms 468 KB Output is correct
6 Correct 2 ms 468 KB Output is correct
7 Correct 2 ms 468 KB Output is correct
8 Correct 2 ms 444 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 448 KB Output is correct
2 Correct 1 ms 468 KB Output is correct
3 Correct 2 ms 468 KB Output is correct
4 Correct 2 ms 468 KB Output is correct
5 Correct 2 ms 468 KB Output is correct
6 Correct 2 ms 468 KB Output is correct
7 Correct 2 ms 468 KB Output is correct
8 Correct 2 ms 444 KB Output is correct
9 Correct 244 ms 25272 KB Output is correct
10 Correct 238 ms 25360 KB Output is correct
11 Correct 180 ms 25392 KB Output is correct
12 Correct 206 ms 25272 KB Output is correct
13 Correct 174 ms 24904 KB Output is correct
14 Correct 180 ms 25288 KB Output is correct
15 Correct 234 ms 24696 KB Output is correct
16 Correct 174 ms 25368 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 189 ms 26340 KB Output is correct
2 Correct 201 ms 28284 KB Output is correct
3 Correct 201 ms 28324 KB Output is correct
4 Correct 189 ms 26108 KB Output is correct
5 Correct 192 ms 27300 KB Output is correct
6 Correct 193 ms 26468 KB Output is correct
7 Correct 191 ms 27396 KB Output is correct
8 Correct 193 ms 26208 KB Output is correct
9 Correct 193 ms 26276 KB Output is correct
10 Correct 198 ms 28452 KB Output is correct
11 Correct 189 ms 26836 KB Output is correct
12 Correct 202 ms 27924 KB Output is correct
13 Correct 188 ms 26072 KB Output is correct
14 Correct 192 ms 28080 KB Output is correct
15 Correct 193 ms 27848 KB Output is correct
16 Correct 186 ms 25724 KB Output is correct
17 Correct 193 ms 27384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 189 ms 26340 KB Output is correct
2 Correct 201 ms 28284 KB Output is correct
3 Correct 201 ms 28324 KB Output is correct
4 Correct 189 ms 26108 KB Output is correct
5 Correct 192 ms 27300 KB Output is correct
6 Correct 193 ms 26468 KB Output is correct
7 Correct 191 ms 27396 KB Output is correct
8 Correct 193 ms 26208 KB Output is correct
9 Correct 193 ms 26276 KB Output is correct
10 Correct 198 ms 28452 KB Output is correct
11 Correct 189 ms 26836 KB Output is correct
12 Correct 202 ms 27924 KB Output is correct
13 Correct 188 ms 26072 KB Output is correct
14 Correct 192 ms 28080 KB Output is correct
15 Correct 193 ms 27848 KB Output is correct
16 Correct 186 ms 25724 KB Output is correct
17 Correct 193 ms 27384 KB Output is correct
18 Correct 257 ms 26476 KB Output is correct
19 Correct 255 ms 28116 KB Output is correct
20 Correct 201 ms 28196 KB Output is correct
21 Correct 224 ms 26288 KB Output is correct
22 Correct 235 ms 26620 KB Output is correct
23 Correct 199 ms 26380 KB Output is correct
24 Correct 262 ms 26972 KB Output is correct
25 Correct 191 ms 26008 KB Output is correct
26 Correct 255 ms 26100 KB Output is correct
27 Correct 264 ms 28588 KB Output is correct
28 Correct 228 ms 26492 KB Output is correct
29 Correct 245 ms 27884 KB Output is correct
30 Correct 225 ms 26112 KB Output is correct
31 Correct 228 ms 28000 KB Output is correct
32 Correct 206 ms 27872 KB Output is correct
33 Correct 287 ms 25624 KB Output is correct
34 Correct 233 ms 27404 KB Output is correct