P5686 100pts
This commit is contained in:
LittleSheep 2024-10-22 22:03:21 +08:00
parent b2505a5361
commit 241c4863c9
4 changed files with 40 additions and 6 deletions

View File

@ -30,4 +30,5 @@ add_executable(Playground
csp-backpack/main.cc
csp-awarding/main.cc
holiday-plan/main.cc
bears-fruit-basket/main.cc)
bears-fruit-basket/main.cc
pre-sum/main.cc)

View File

@ -5,7 +5,7 @@ using namespace std;
const int N = 10005;
pair<int, int> arr[N];
int b[N];
int beta[N];
int main() {
int n, m;
@ -15,23 +15,23 @@ int main() {
arr[i].second = i;
}
sort(arr + 1, arr + n + 1);
for (int i = 1; i <= n; i++) b[arr[i].second] = i;
for (int i = 1; i <= n; i++) beta[arr[i].second] = i;
while (m--) {
int op, x, y;
scanf("%d", &op);
if (op == 1) {
scanf("%d%d", &x, &y);
arr[b[x]].first = y;
arr[beta[x]].first = y;
for (int i = 1; i < n; i++) {
if (arr[i] > arr[i + 1]) swap(arr[i], arr[i + 1]);
}
for (int i = n - 1; i >= 1; i--) {
if (arr[i] > arr[i + 1]) swap(arr[i], arr[i + 1]);
}
for (int i = 1; i <= n; i++) b[arr[i].second] = i;
for (int i = 1; i <= n; i++) beta[arr[i].second] = i;
} else {
scanf("%d", &x);
printf("%d\n", b[x]);
printf("%d\n", beta[x]);
}
}
return 0;

3
pre-sum/data.in Normal file
View File

@ -0,0 +1,3 @@
3
2 3 4
3 4 5

30
pre-sum/main.cc Normal file
View File

@ -0,0 +1,30 @@
#include <iostream>
using namespace std;
long long alpha[500005], beta[500005];
long long pre_alpha[500005], pre_beta[500005];
long long sum_alpha, sum_beta;
long long ans;
const int mod = 1000000007;
int main() {
int n;
cin >> n;
for (int i = 1; i <= n; ++i) {
cin >> alpha[i];
pre_alpha[i] = (pre_alpha[i - 1] + alpha[i]) % mod;
}
for (int i = 1; i <= n; ++i) {
cin >> beta[i];
pre_beta[i] = (pre_beta[i - 1] + beta[i]) % mod;
}
for (int i = 1; i <= n; i++) {
(ans += (((n + 1) * pre_alpha[i]) % mod) * pre_beta[i]) %= mod;
sum_alpha = (sum_alpha + pre_alpha[i]) % mod;
sum_beta = (sum_beta + pre_beta[i]) % mod;
}
long long tot = (sum_alpha * sum_beta) % mod;
ans = (ans - tot + mod) % mod;
cout << ans;
}