diff --git a/CMakeLists.txt b/CMakeLists.txt index f608864..fd4135c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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) diff --git a/insert-sort/main.cc b/insert-sort/main.cc index f4ffb92..fe9bc19 100644 --- a/insert-sort/main.cc +++ b/insert-sort/main.cc @@ -5,7 +5,7 @@ using namespace std; const int N = 10005; pair 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; diff --git a/pre-sum/data.in b/pre-sum/data.in new file mode 100644 index 0000000..31966e2 --- /dev/null +++ b/pre-sum/data.in @@ -0,0 +1,3 @@ +3 +2 3 4 +3 4 5 diff --git a/pre-sum/main.cc b/pre-sum/main.cc new file mode 100644 index 0000000..a987b08 --- /dev/null +++ b/pre-sum/main.cc @@ -0,0 +1,30 @@ +#include + +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; +} \ No newline at end of file