Submission #626358

# Submission time Handle Problem Language Result Execution time Memory
626358 2022-08-11T12:05:15 Z PoPularPlusPlus Radio Towers (IOI22_towers) C++17
14 / 100
1056 ms 2896 KB
#include "towers.h"

#include <bits/stdc++.h>

using namespace std;

struct Seg {
	int siz = 1;
	vector<int> sums;
	void init(int n){
		while(siz < n)siz*=2;
		
		sums.assign(siz * 2, 0LL);
	}
	
	void build(vector<int>& arr  , int x , int lx , int rx){
		if(rx-lx==1){
			if(lx < (int)arr.size()){
				sums[x] = arr[lx];
			}
			return;
		}
		int m = (lx + rx) / 2;
		build(arr , 2 * x + 1 , lx , m);
		build(arr, 2 * x + 2 , m , rx);
		sums[x] = sums[2 * x + 1] + sums[2 * x + 2];
	}
	
	void build(vector<int>& arr){
		build(arr , 0 , 0 , siz);
	}
	
	void set(int i , int v , int x , int lx , int rx){
		if(rx - lx ==1){
			sums[x] = v;
			return;
		}
		int m = (lx + rx) / 2;
		if(i < m){
			set(i , v , 2 * x + 1 , lx , m);
		}
		else {
			set(i , v , 2 * x + 2 , m , rx);
		}
		sums[x]=sums[2 * x + 1] + sums[2 * x + 2];
	}
	
	void set(int x , int y){
		set(x  ,y , 0 , 0 , siz);
	}
	
	int sum(int l , int r , int x , int lx , int rx){
		if(lx >= l && rx <= r){
			return sums[x];
		}
		if(lx >= r || rx <= l)return 0;
		int m = (lx + rx) / 2;
		return sum(l , r , 2 * x + 1 , lx , m) + sum(l , r , 2 * x + 2 , m , rx);
	}
	
	int sum(int l , int r){
		return sum(l , r , 0 , 0 , siz);
	}
	
};


vector<int> arr;

Seg st;

void init(int n, std::vector<int> h) {
	arr = h;
	st.init(n+1);
	vector<int> a(n,0);
	for(int i = 0; i < n; i++){
		int cnt = 0;
		if(i - 1 < 0 || arr[i] > arr[i-1])cnt++;
		if(i + 1 == n || arr[i + 1] < arr[i])cnt++;
		if(cnt == 2)a[i] = 1;
	}
	st.build(a);
}

int max_towers(int l , int r , int d) {
	int ans = st.sum(l , r + 1) + 1;
	ans -= st.sum(l , l + 1);
	if(l != r)ans -= st.sum(r , r + 1);
	return ans;
}
# Verdict Execution time Memory Grader output
1 Incorrect 436 ms 1744 KB 2nd lines differ - on the 1st token, expected: '1', found: '2'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 208 KB 1st lines differ - on the 1st token, expected: '13', found: '16'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 208 KB 1st lines differ - on the 1st token, expected: '13', found: '16'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 689 ms 2844 KB Output is correct
2 Correct 896 ms 2844 KB Output is correct
3 Correct 1000 ms 2896 KB Output is correct
4 Correct 1056 ms 2836 KB Output is correct
5 Correct 1006 ms 2844 KB Output is correct
6 Correct 894 ms 2860 KB Output is correct
7 Correct 923 ms 2872 KB Output is correct
8 Correct 908 ms 2840 KB Output is correct
9 Correct 853 ms 2840 KB Output is correct
10 Correct 739 ms 2868 KB Output is correct
11 Correct 825 ms 2848 KB Output is correct
12 Correct 691 ms 2760 KB Output is correct
13 Correct 990 ms 2824 KB Output is correct
14 Correct 1 ms 208 KB Output is correct
15 Correct 0 ms 336 KB Output is correct
16 Correct 1 ms 336 KB Output is correct
17 Correct 14 ms 2836 KB Output is correct
18 Correct 21 ms 2844 KB Output is correct
19 Correct 13 ms 2760 KB Output is correct
20 Correct 13 ms 2856 KB Output is correct
21 Correct 21 ms 2856 KB Output is correct
22 Correct 13 ms 2888 KB Output is correct
23 Correct 16 ms 2844 KB Output is correct
24 Correct 17 ms 2844 KB Output is correct
25 Correct 17 ms 2852 KB Output is correct
26 Correct 12 ms 2884 KB Output is correct
27 Correct 1 ms 336 KB Output is correct
28 Correct 1 ms 336 KB Output is correct
29 Correct 1 ms 336 KB Output is correct
30 Correct 1 ms 336 KB Output is correct
31 Correct 1 ms 336 KB Output is correct
32 Correct 1 ms 336 KB Output is correct
33 Correct 0 ms 336 KB Output is correct
34 Correct 1 ms 336 KB Output is correct
35 Correct 1 ms 336 KB Output is correct
36 Correct 1 ms 336 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 164 ms 932 KB 1st lines differ - on the 1st token, expected: '7197', found: '8004'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 208 KB 1st lines differ - on the 1st token, expected: '13', found: '16'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 436 ms 1744 KB 2nd lines differ - on the 1st token, expected: '1', found: '2'
2 Halted 0 ms 0 KB -