#include <iostream>
#include <vector>
#include <set>
#define ll long long
using namespace std;
signed main() {
ll n;
cin >> n;
vector<pair<ll,ll>> a(n);
vector<ll> pref(n,0),d(n,0),ans(n,0);
set<ll> s;
for(ll i = 0; i < n; i++){
cin >> a[i].first;
a[i].second = i;
s.insert(a[i].first);
if(i == 0)
pref[i] = a[i].first;
else
pref[i] = pref[i-1] + a[i].first;
d[i] = s.size();
}
if(d[n-1] > 1 || n == 1)
ans[a[n-1].second] = 1;
for(ll i = n - 2; i >= 0; i--){
if(pref[i] > a[i + 1].first && ans[a[i+1].second] == 1 && d[i] > 1)
ans[a[i].second] = 1;
}
for(ll i = 0; i < n; i++)
cout << ans[i] << " ";
}
Поделитесь своими знаниями, ответьте на вопрос:
Показать, что высказывание ( a↔b)→( a→ b) логически истинно, а высказывание (a↔b)→( a∨ b) – нет
N = int(input())
if N == 1:
exit(0)
bacteria = [0] * N
for i in range(0, N):
bacteria[i] = int(input())
prefix_sum = [bacteria[0]] * N
for i in range(1, N):
prefix_sum[i] = prefix_sum[i - 1] + bacteria[i]
ans = [0] * N
if bacteria[N-1] > bacteria[0]:
ans[N - 1] = 1
for i in reversed(range(2, N)):
if ans[i] == 1:
prev = i - 1
if prefix_sum[prev] > bacteria[i] and bacteria[0] < bacteria[prev]:
ans[prev] = 1
for i in range(N):
print(ans[i])
Объяснение:
g++