답안 #1067112

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1067112 2024-08-20T11:32:27 Z AdamGS 송신탑 (IOI22_towers) C++17
17 / 100
1075 ms 38168 KB
#include "towers.h"
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(a, b) for(int a = 0; a < (b); ++a)
#define st first
#define nd second
#define pb push_back
#define all(a) a.begin(), a.end()
const ll INF=1e18+7;
const int LIM=1e5+7;
ll T[LIM], jaki[LIM], n;
vector<ll>trma[4*LIM];
ll trmi[4*LIM], N=1;
set<pair<ll,ll>>S, P;
vector<pair<ll,ll>>V;
void dodaj(int x) {
	auto it=S.lower_bound({x, -1}); ++it;
	auto a=*it;
	P.insert({abs(T[x]-T[a.st]), x});
}
void usun(int x) {
	auto it=S.lower_bound({x, -1}); ++it;
	auto a=*it;
	P.erase({abs(T[x]-T[a.st]), x});
}
int ile(int v, int x) {
	if(trma[v].size()==0) return 0;
	if(trma[v].back()<=x) return 0;
	int po=0, ko=trma[v].size()-1;
	while(po<ko) {
		int sr=(po+ko)/2;
		if(trma[v][sr]<=x) po=sr+1; else ko=sr;
	}
	return trma[v].size()-po;
}
int licz(int l, int r, int x) {
	l+=N; r+=N;
	int ans=ile(l, x);
	if(l!=r) ans+=ile(r, x);
	while(l/2!=r/2) {
		if(l%2==0) ans+=ile(l+1, x);
		if(r%2==1) ans+=ile(r-1, x);
		l/=2; r/=2;
	}
	return ans;
}
void init(int _n, vector<int>_H) {
	n=_n;
	while(N<n+2) N*=2;
	rep(i, 2*N) trmi[i]=-INF;
	rep(i, n) T[i+1]=_H[i];
	T[0]=T[n+1]=INF;
	int akt=2;
	jaki[0]=jaki[n+1]=1;
	rep(i, n) if((T[i]<T[i+1] && T[i+1]>T[i+2]) || (T[i]>T[i+1] && T[i+1]<T[i+2])) {
		jaki[i+1]=akt;
		akt^=3;
	}
	rep(i, n+2) if(jaki[i]) S.insert({i, jaki[i]});
	rep(i, n+2) if(!jaki[i]) trma[N+i].pb(0);
	auto it=S.begin();
	while(true) {
		auto it2=it; ++it2;
		if(it2==S.end()) break;
		auto a=*it;
		dodaj(a.st);
		++it;
	}
	V.pb({0, S.size()/2});
	while(P.size()>2) {
		auto a=*P.begin();
		usun(a.nd);
		trma[N+a.nd].pb(V.size());
		auto it=S.lower_bound({a.nd, -1});
		++it;
		auto b=*it;
		trma[N+b.st].pb(V.size());
		usun(b.st);
		--it; --it;
		b=*it;
		usun(b.st);
		++it;
		S.erase(it);
		it=S.lower_bound({a.nd, -1});
		S.erase(it);
		it=S.lower_bound({a.nd, -1});
		--it;
		b=*it;
		dodaj(b.st);
		V.pb({a.st, S.size()/2});
	}
	rep(i, n+2) if(trma[N+i].size()==0) trma[N+i].pb(INF);
	rep(i, n+2) trmi[N+i]=T[i];
	for(int i=N-1; i; --i) {
		trmi[i]=min(trmi[2*i], trmi[2*i+1]);
		for(auto j : trma[2*i]) trma[i].pb(j);
		for(auto j : trma[2*i+1]) trma[i].pb(j);
		sort(all(trma[i]));
	}
}
int max_towers(int l, int r, int d) {
	++l; ++r;
	int po=0, ko=V.size()-1;
	while(po<ko) {
		int sr=(po+ko+1)/2;
		if(V[sr].st<d) po=sr; else ko=sr-1;
	}
	int x=licz(l, r, po);
	return (x+1)/2; // l=0, r=n-1
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 362 ms 22356 KB 1st lines differ - on the 1st token, expected: '1', found: '0'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 6 ms 9816 KB 1st lines differ - on the 1st token, expected: '13', found: '14'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 6 ms 9816 KB 1st lines differ - on the 1st token, expected: '13', found: '14'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 753 ms 33792 KB 12th lines differ - on the 1st token, expected: '2813', found: '2814'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 237 ms 15560 KB Output is correct
2 Correct 855 ms 34160 KB Output is correct
3 Correct 966 ms 33988 KB Output is correct
4 Correct 1046 ms 38088 KB Output is correct
5 Correct 1075 ms 38088 KB Output is correct
6 Correct 1026 ms 38080 KB Output is correct
7 Correct 1044 ms 38088 KB Output is correct
8 Correct 661 ms 31792 KB Output is correct
9 Correct 676 ms 31804 KB Output is correct
10 Correct 715 ms 31688 KB Output is correct
11 Correct 732 ms 31896 KB Output is correct
12 Correct 171 ms 33992 KB Output is correct
13 Correct 254 ms 38024 KB Output is correct
14 Correct 254 ms 38092 KB Output is correct
15 Correct 42 ms 31904 KB Output is correct
16 Correct 47 ms 31896 KB Output is correct
17 Correct 165 ms 34152 KB Output is correct
18 Correct 162 ms 34244 KB Output is correct
19 Correct 167 ms 34244 KB Output is correct
20 Correct 263 ms 38088 KB Output is correct
21 Correct 266 ms 38168 KB Output is correct
22 Correct 244 ms 38088 KB Output is correct
23 Correct 253 ms 38088 KB Output is correct
24 Correct 42 ms 31832 KB Output is correct
25 Correct 44 ms 31896 KB Output is correct
26 Correct 41 ms 31896 KB Output is correct
27 Correct 50 ms 31896 KB Output is correct
28 Correct 5 ms 10072 KB Output is correct
29 Correct 6 ms 10196 KB Output is correct
30 Correct 6 ms 10072 KB Output is correct
31 Correct 5 ms 10072 KB Output is correct
32 Correct 4 ms 10164 KB Output is correct
33 Correct 5 ms 9816 KB Output is correct
34 Correct 6 ms 10072 KB Output is correct
35 Correct 6 ms 10072 KB Output is correct
36 Correct 7 ms 10148 KB Output is correct
37 Correct 6 ms 10128 KB Output is correct
38 Correct 7 ms 10072 KB Output is correct
39 Correct 8 ms 10072 KB Output is correct
40 Correct 5 ms 10072 KB Output is correct
41 Correct 5 ms 10072 KB Output is correct
42 Correct 5 ms 10072 KB Output is correct
43 Correct 4 ms 10072 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 6 ms 9816 KB 1st lines differ - on the 1st token, expected: '13', found: '14'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 362 ms 22356 KB 1st lines differ - on the 1st token, expected: '1', found: '0'
2 Halted 0 ms 0 KB -