1.
#include <iostream>
#define N 10
int main()
{
using namespace std;
int count = 0, sum = 0, mult = 1;
int arr[N]{0, 7, 5, 2, -10, -3, 4, 6, 12, -1};
for (const auto i : arr)
if (i < 0)
count++;
sum += i;
mult *= i;
}
cout << "Count = " << count << "\nSum = " << sum
<< "\nMult = " << mult;
return 0;
2.
#define N 3
int arr[N][N]{0, 7, 5, 2, -10, -3, 4, 6, -1};
for (int i = 0; i < N; i++)
for (int j = 0; j < N; j++)
if (arr[i][j] < 0)
sum += arr[i][j];
mult *= arr[i][j];
#include <bits/stdc++.h>
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);cout.tie(0);
int N,k;
int a[1000000];
map <pair <int, int>, int> mem;
cin >> N;
//b.reserve(N);
memset(a,0,sizeof a);
//memset(b,0,b.size()*sizeof int);
for (int i=0;i<N;i++)
cin >> a[i];
cin >> k;
for (int i=0;i<k;i++){
int tmp,tmp2,tmp3,tmp4,sum{0};
cin >> tmp >> tmp2;
tmp--;tmp2--;
if (mem.find({tmp,tmp2})!=mem.end()) {cout<< mem[ {tmp,tmp2} ] << endl; continue;}
tmp3=tmp;
tmp4=tmp2;
for(int x=0;x<(tmp4-tmp3)/2+1;x++){
for(int z=0;z<(tmp2-tmp)/2+1;z++){
if (mem.find({tmp,tmp2})!=mem.end()) {sum= (sum+mem[ {tmp,tmp2} ])%998244353; break;}
for(int j=tmp+z;j<=tmp2-z;j++){
sum=(sum+a[j])%998244353;
}}
tmp++;tmp2--;
cout << sum << endl;
mem[{tmp3,tmp4}]=sum;
Объяснение:
1.
#include <iostream>
#define N 10
int main()
{
using namespace std;
int count = 0, sum = 0, mult = 1;
int arr[N]{0, 7, 5, 2, -10, -3, 4, 6, 12, -1};
for (const auto i : arr)
{
if (i < 0)
{
count++;
sum += i;
mult *= i;
}
}
cout << "Count = " << count << "\nSum = " << sum
<< "\nMult = " << mult;
return 0;
}
2.
#include <iostream>
#define N 3
int main()
{
using namespace std;
int count = 0, sum = 0, mult = 1;
int arr[N][N]{0, 7, 5, 2, -10, -3, 4, 6, -1};
for (int i = 0; i < N; i++)
{
for (int j = 0; j < N; j++)
{
if (arr[i][j] < 0)
{
count++;
sum += arr[i][j];
mult *= arr[i][j];
}
}
}
cout << "Count = " << count << "\nSum = " << sum
<< "\nMult = " << mult;
return 0;
}
#include <bits/stdc++.h>
using namespace std;
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);cout.tie(0);
int N,k;
int a[1000000];
map <pair <int, int>, int> mem;
cin >> N;
//b.reserve(N);
memset(a,0,sizeof a);
//memset(b,0,b.size()*sizeof int);
for (int i=0;i<N;i++)
cin >> a[i];
cin >> k;
for (int i=0;i<k;i++){
int tmp,tmp2,tmp3,tmp4,sum{0};
cin >> tmp >> tmp2;
tmp--;tmp2--;
if (mem.find({tmp,tmp2})!=mem.end()) {cout<< mem[ {tmp,tmp2} ] << endl; continue;}
tmp3=tmp;
tmp4=tmp2;
for(int x=0;x<(tmp4-tmp3)/2+1;x++){
for(int z=0;z<(tmp2-tmp)/2+1;z++){
if (mem.find({tmp,tmp2})!=mem.end()) {sum= (sum+mem[ {tmp,tmp2} ])%998244353; break;}
for(int j=tmp+z;j<=tmp2-z;j++){
sum=(sum+a[j])%998244353;
}}
tmp++;tmp2--;
}
cout << sum << endl;
mem[{tmp3,tmp4}]=sum;
}
return 0;
}
Объяснение: