답안 #1068679

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1068679 2024-08-21T11:19:39 Z n1k 송신탑 (IOI22_towers) C++17
17 / 100
965 ms 13496 KB
#include "towers.h"
#include <bits/stdc++.h>

using namespace std;

using ll = long long;

struct V{
    int lb=0, rb=0;
	ll mx = 0;
    V *l=nullptr, *r=nullptr;
    V(){};
    V(int lb_, int rb_){lb=lb_, rb=rb_;};
    void ext(){
        if(lb!=rb and not l){
            int mb=(lb+rb)/2;
            l=new V(lb, mb);
            r=new V(mb+1, rb);
        }
    }
    void upd(int id, ll x){
        if(lb==rb and lb==id){
			mx = x;
        }
        ext();
        if(l){
            if(id<=l->rb){
                l->upd(id, x);
            }else{
                r->upd(id, x);
            }
			mx = max(l->mx, r->mx);
        }
    }
    ll qry(int lo, int hi){
        if(lo<=lb and rb<=hi){
            return mx;
        }
        if(hi<lb or rb<lo) return 0;
        ext();
        return max(l->qry(lo, hi), r->qry(lo, hi));
    }
};


vector<int> sl, sr;
vector<ll> order;

vector<int> get(vector<int> h){
	vector<int> sl(h.size());
	vector<pair<int, int>> st;
	for(int i=0; i<h.size(); i++){
		while(st.size() and st.back().first>h[i]){
			st.pop_back();
		}
		if(st.empty()){
			sl[i]=i;
		}else{
			sl[i]=st.back().second;
		}
		st.push_back({h[i], i});
	}
	return sl;
}

void init(int N, std::vector<int> H) {
	order.clear();

	sl = get(H);
	reverse(H.begin(), H.end());
	sr = get(H);
	reverse(H.begin(), H.end());
	reverse(sr.begin(), sr.end());
	V seg(0, N-1);
	for(int i=0; i<sr.size(); i++){
		seg.upd(i, H[i]);
		sr[i]=N-sr[i]-1;
	}
	for(int i=0; i<N; i++){
		ll minh = ll(1e18) + 5;
		if(sl[i]!=i){
			minh = min(minh, seg.qry(sl[i]+1, i));
		}
		if(sr[i]!=i){
			minh = min(minh, seg.qry(i, sr[i]-1));
		}
		order.push_back(minh - H[i]);
	}	
	sort(order.begin(), order.end());
	for(auto x:order) cerr<<x<<" ";cerr<<endl;
}

int max_towers(int L, int R, int D) {
	return order.end() - lower_bound(order.begin(), order.end(), D);
}

Compilation message

towers.cpp: In function 'std::vector<int> get(std::vector<int>)':
towers.cpp:52:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   52 |  for(int i=0; i<h.size(); i++){
      |               ~^~~~~~~~~
towers.cpp: In function 'void init(int, std::vector<int>)':
towers.cpp:75:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   75 |  for(int i=0; i<sr.size(); i++){
      |               ~^~~~~~~~~~
towers.cpp:90:2: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
   90 |  for(auto x:order) cerr<<x<<" ";cerr<<endl;
      |  ^~~
towers.cpp:90:33: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
   90 |  for(auto x:order) cerr<<x<<" ";cerr<<endl;
      |                                 ^~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 452 ms 8028 KB 1st lines differ - on the 1st token, expected: '1', found: '2'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 344 KB 1st lines differ - on the 1st token, expected: '13', found: '131'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 344 KB 1st lines differ - on the 1st token, expected: '13', found: '131'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 697 ms 13000 KB 1st lines differ - on the 1st token, expected: '11903', found: '33010'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 250 ms 3416 KB Output is correct
2 Correct 855 ms 12996 KB Output is correct
3 Correct 890 ms 12940 KB Output is correct
4 Correct 838 ms 13188 KB Output is correct
5 Correct 965 ms 13252 KB Output is correct
6 Correct 922 ms 13264 KB Output is correct
7 Correct 907 ms 13220 KB Output is correct
8 Correct 842 ms 13352 KB Output is correct
9 Correct 880 ms 13276 KB Output is correct
10 Correct 904 ms 13352 KB Output is correct
11 Correct 801 ms 13476 KB Output is correct
12 Correct 250 ms 12996 KB Output is correct
13 Correct 244 ms 13424 KB Output is correct
14 Correct 254 ms 13252 KB Output is correct
15 Correct 222 ms 13496 KB Output is correct
16 Correct 238 ms 12728 KB Output is correct
17 Correct 306 ms 12668 KB Output is correct
18 Correct 239 ms 12952 KB Output is correct
19 Correct 244 ms 13000 KB Output is correct
20 Correct 266 ms 13248 KB Output is correct
21 Correct 263 ms 13264 KB Output is correct
22 Correct 258 ms 13208 KB Output is correct
23 Correct 234 ms 13256 KB Output is correct
24 Correct 245 ms 13332 KB Output is correct
25 Correct 227 ms 13364 KB Output is correct
26 Correct 233 ms 12892 KB Output is correct
27 Correct 222 ms 13280 KB Output is correct
28 Correct 5 ms 600 KB Output is correct
29 Correct 5 ms 680 KB Output is correct
30 Correct 7 ms 600 KB Output is correct
31 Correct 4 ms 600 KB Output is correct
32 Correct 5 ms 600 KB Output is correct
33 Correct 3 ms 344 KB Output is correct
34 Correct 5 ms 600 KB Output is correct
35 Correct 5 ms 600 KB Output is correct
36 Correct 5 ms 600 KB Output is correct
37 Correct 5 ms 600 KB Output is correct
38 Correct 5 ms 600 KB Output is correct
39 Correct 6 ms 600 KB Output is correct
40 Correct 5 ms 600 KB Output is correct
41 Correct 4 ms 600 KB Output is correct
42 Correct 5 ms 600 KB Output is correct
43 Correct 5 ms 600 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 344 KB 1st lines differ - on the 1st token, expected: '13', found: '131'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 452 ms 8028 KB 1st lines differ - on the 1st token, expected: '1', found: '2'
2 Halted 0 ms 0 KB -