QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#840799 | #9902. 求和 | SorahISA# | 100 ✓ | 37ms | 5636kb | C++23 | 11.3kb | 2025-01-03 03:37:17 | 2025-01-03 03:37:18 |
Judging History
answer
#ifndef SorahISA
#define SorahISA
#include SorahISA __FILE__ SorahISA
void solve() {
int N; cin >> N;
vector<int> A(N), B(N);
for (int &x : A) cin >> x;
for (int &x : B) cin >> x;
auto get_sum = [&](const vector<int> &vec) -> int {
vector<int> id(N); iota(ALL(id), 0);
sort(ALL(id), [&](int i, int j) { return vec[i] < vec[j]; });
int sum = 0;
for (int i = 0; i+1 < N; ++i) sum += (i+1) * (N-i-1) * (vec[id[i+1]] - vec[id[i]]);
// debug(vec, sum);
return sum;
};
int sum_all = get_sum(A) + get_sum(B);
for (int i = 0; i < N; ++i) tie(A[i], B[i]) = pii(A[i] + B[i], A[i] - B[i]);
int sum_max = get_sum(A) + get_sum(B);
print(2 * sum_all - sum_max);
}
int32_t main() {
fastIO();
int t = 1; // cin >> t;
for (int _ = 1; _ <= t; ++_) {
// cout << "Case #" << _ << ": ";
solve();
}
return 0;
}
#else
#ifdef local
#define _GLIBCXX_DEBUG 1
#endif
#pragma GCC optimize("Ofast", "unroll-loops")
#include <bits/stdc++.h>
using namespace std;
// #include <bits/extc++.h>
// #include <tr2/dynamic_bitset>
using i64 = long long;
using i128 = __int128;
#define int i64
using f80 = long double;
using f128 = __float128;
#define double f80
using pii = pair<int, int>;
template <typename T> using Prior = std::priority_queue<T>;
template <typename T> using prior = std::priority_queue<T, vector<T>, greater<T>>;
// #define X first
// #define Y second
#define eb emplace_back
#define ef emplace_front
#define ee emplace
#define pb pop_back
#define pf pop_front
#define ALL(x) begin(x), end(x)
#define RALL(x) rbegin(x), rend(x)
#define SZ(x) ((int)(x).size())
#define popcnt(x) __builtin_popcountll(x)
// template <size_t D, typename T> struct Vec : vector<Vec<D-1, T>> {
// static_assert(D >= 1, "Vector dimension must be greater than zero!");
// template <typename... Args> Vec(int n = 0, Args... args) : vector<Vec<D-1, T>>(n, Vec<D-1, T>(args...)) {}
// };
// template <typename T> struct Vec<1, T> : vector<T> {
// Vec(int n = 0, const T& val = T()) : vector<T>(n, val) {}
// };
template <typename T> ostream& operator << (ostream &os, const vector<T> &vec)
{ for (size_t i = 0; i < size(vec); ++i) { if (i) os << " "; os << vec[i]; } return os; }
#ifdef local
#define fastIO() void()
#define debug(...) \
_color.emplace_back("\u001b[31m"), \
fprintf(stderr, "%sAt [%s], line %d: (%s) = ", _color.back().c_str(), __FUNCTION__, __LINE__, #__VA_ARGS__), \
_do(__VA_ARGS__), _color.pop_back(), \
fprintf(stderr, "%s", _color.back().c_str())
#define print(...) \
fprintf(stdout, "%s", "\u001b[36m"), \
_P(__VA_ARGS__), \
fprintf(stdout, "%s", "\u001b[0m")
deque<string> _color{"\u001b[0m"};
template <typename T> concept is_string = is_same_v<T, string&> or is_same_v<T, const string&>;
template <typename T> concept is_iterable = requires (T _t) { begin(_t); };
template <typename T> inline void _print_err(T &&_t);
template <typename T> inline void _print_err(T &&_t) requires is_iterable<T> and (not is_string<T>);
template <size_t I, typename ...U> inline typename enable_if<I == sizeof...(U), void>::type _print_err(const tuple<U...> &);
template <size_t I, typename ...U> inline typename enable_if<I < sizeof...(U), void>::type _print_err(const tuple<U...> &_t);
template <size_t I, typename ...U> inline typename enable_if<I == sizeof...(U), void>::type _print_err(tuple<U...> &);
template <size_t I, typename ...U> inline typename enable_if<I < sizeof...(U), void>::type _print_err(tuple<U...> &_t);
template <typename T, typename U> ostream& operator << (ostream &os, const pair<T, U> &_tu);
inline void _do() { cerr << "\n"; }
template <typename T> inline void _do(T &&_t) { _print_err(_t), cerr << "\n"; }
template <typename T, typename ...U> inline void _do(T &&_t, U &&..._u) { _print_err(_t), cerr << ", ", _do(_u...); }
#else
#define fastIO() cin.tie(0)->sync_with_stdio(0)
#define debug(...) void()
#define print(...) _P(__VA_ARGS__)
#endif
inline void _P() { cout << "\n"; }
template <typename T> inline void _P(T &&_t) { cout << _t << "\n"; }
template <typename T, typename ...U> inline void _P(T &&_t, U &&..._u) { cout << _t << " ", _P(_u...); }
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
inline int getRand(int L, int R) {
if (L > R) swap(L, R);
return (int)(rng() % ((uint64_t)R - L + 1) + L);
}
template <typename T, typename U> bool chmin(T &lhs, U rhs) { return lhs > rhs ? lhs = rhs, 1 : 0; }
template <typename T, typename U> bool chmax(T &lhs, U rhs) { return lhs < rhs ? lhs = rhs, 1 : 0; }
template <typename T> void make_unique(vector<T> &vec) {
if (not is_sorted(ALL(vec))) sort(ALL(vec));
vec.erase(unique(ALL(vec)), end(vec));
}
/// below are Fast I/O and _print_err templates ///
/*
/// Fast I/O by FHVirus ///
/// https://fhvirus.github.io/blog/2020/fhvirus-io/ ///
#include <unistd.h>
const int S = 65536;
int OP = 0;
char OB[S];
inline char RC() {
static char buf[S], *p = buf, *q = buf;
return p == q and (q = (p = buf) + read(0, buf, S)) == buf ? -1 : *p++;
}
inline int RI() {
static char c;
int a;
while (((c = RC()) < '0' or c > '9') and c != '-' and c != -1);
if (c == '-') {
a = 0;
while ((c = RC()) >= '0' and c <= '9') a *= 10, a -= c ^ '0';
}
else {
a = c ^ '0';
while ((c = RC()) >= '0' and c <= '9') a *= 10, a += c ^ '0';
}
return a;
}
inline void WI(int n, char c = '\n') {
static char buf[20], p;
if (n == 0) OB[OP++] = '0';
p = 0;
if (n < 0) {
OB[OP++] = '-';
while (n) buf[p++] = '0' - (n % 10), n /= 10;
}
else {
while (n) buf[p++] = '0' + (n % 10), n /= 10;
}
for (--p; p >= 0; --p) OB[OP++] = buf[p];
OB[OP++] = c;
if (OP > S-20) write(1, OB, OP), OP = 0;
}
/// Fast I/O by FHVirus ///
/// https://fhvirus.github.io/blog/2020/fhvirus-io/ ///
*/
#ifdef local
template <typename T> inline void _print_err(T &&_t) { cerr << _t; }
template <typename T> inline void _print_err(T &&_t) requires is_iterable<T> and (not is_string<T>) {
_color.emplace_back(_color.back()), ++_color.back()[3];
cerr << _color.back() << "[";
for (bool _first = true; auto &_x : _t) {
if (!_first) cerr << ", ";
_print_err(_x), _first = false;
}
cerr << "]" << (_color.pop_back(), _color.back());
}
template <typename T, typename U> ostream& operator << (ostream &os, const pair<T, U> &_tu) {
_color.emplace_back(_color.back()), ++_color.back()[3];
cerr << _color.back() << "(";
_print_err(_tu.first), cerr << ", ", _print_err(_tu.second);
cerr << ")" << (_color.pop_back(), _color.back());
return os;
}
template <size_t I = 0, typename ...U> inline typename enable_if<I == sizeof...(U), void>::type _print_err(const tuple<U...> &) {
cerr << ")" << (_color.pop_back(), _color.back());
}
template <size_t I = 0, typename ...U> inline typename enable_if<I < sizeof...(U), void>::type _print_err(const tuple<U...> &_t) {
if (!I) {
_color.emplace_back(_color.back()), ++_color.back()[3];
cerr << _color.back();
}
cerr << (I ? ", " : "("), _print_err(get<I>(_t)), _print_err<I+1, U...>(_t);
}
template <size_t I = 0, typename ...U> inline typename enable_if<I == sizeof...(U), void>::type _print_err(tuple<U...> &) {
cerr << ")" << (_color.pop_back(), _color.back());
}
template <size_t I = 0, typename ...U> inline typename enable_if<I < sizeof...(U), void>::type _print_err(tuple<U...> &_t) {
if (!I) {
_color.emplace_back(_color.back()), ++_color.back()[3];
cerr << _color.back();
}
cerr << (I ? ", " : "("), _print_err(get<I>(_t)), _print_err<I+1, U...>(_t);
}
#endif
#endif
/**
*
*
*
* iiiiii iiiiiiiiii iiiiiiiiiiiiii
* iiiiiiiiiiiii iiiiiii iiii iiiiiiiiiiiiiii ii iiii
* iiiiiiii iiiiiiiii iiii iiii iii iii iiiiiiiiii
* iiiiiii iiiiii iiii iiii ii iiiiiiiiii iiii iiii
* iiiiii iiiii iiii iiii iii iiii iiiiiiiiiiiiiiiii ii
* iiiiii iiiiiii iiiiiii iiiiiiii iii iiiiiiiiiiiiii iii iiii
* iiiiii iiiiiii iiiii ii iiii iiiiiiiiiii iiii iii iiii iiii iii
* iiiii iiiiiiii ii iiiii iiii iiiiiiiii iii iii iii iii ii iiii
* iiiiii iiiiiiii iiiii iiiii iiiiiiiiiiiiiiii iii iii ii iii iii iiii
* iiiii iiiiii iiii iiiiii iiiiiii iii iii iiii ii i ii iii iii
* iiiiii iiii iiiiiiiiiiiiiii iii iiii iiiii iii ii iii iii ii
* iiiii iiiiiiii iiiiiiiiii iiii iiiiiiiii ii iii ii
* iiiii iiiiii iiii iiiii iii ii ii i
* iiiiii iiiiiiii iiiii iiiii ii ii ii
* iiiii iiii iiii iiiiiiiiiiii ii
* iii iiii iiii iiiiiiii
* iiiii iiii
* iiii iiii
* iiii iiiii
* iii iiiii
* iii iiiii
* iii iiiiii
* iiiiiiiii
* iiiiii
*
*
*
**/
这程序好像有点Bug,我给组数据试试?
Details
Tip: Click on the bar to expand more detailed information
Pretests
Final Tests
Test #1:
score: 10
Accepted
time: 1ms
memory: 3616kb
input:
1000 6858 7266 2204 9448 3411 7466 8694 7815 7932 1414 4877 2123 4249 3992 5960 1527 99 2214 3634 5475 4614 6728 5928 9113 3121 5164 3212 3960 202 5875 3589 1125 8968 6641 1261 8549 6503 4544 6034 4101 1047 3726 2453 4578 8573 7802 5950 9057 209 4059 9286 328 7919 9833 3467 9443 1590 354 6607 7568 2...
output:
1983241576
result:
ok 1 number(s): "1983241576"
Test #2:
score: 10
Accepted
time: 1ms
memory: 3572kb
input:
1000 514483 623943 95786 5162 480063 469510 40617 147410 457621 203184 153117 682815 995705 146286 86645 91921 294948 993207 209940 442107 987138 90138 482128 7494 520629 982073 115316 173004 797328 449480 273534 388733 718556 216466 373217 648349 586070 718644 901125 66372 915183 62752 91266 203293...
output:
197768260412
result:
ok 1 number(s): "197768260412"
Test #3:
score: 10
Accepted
time: 0ms
memory: 3644kb
input:
1000 597907 140084 876340 667344 796613 139774 845304 331398 391777 540071 380853 209855 828499 748527 56968 572542 766862 497661 640662 739052 83591 237916 622341 849173 834486 324985 209537 565161 254744 716646 16952 642107 60847 159899 175326 242949 453504 916015 488362 823778 98580 456675 289751...
output:
200454518772
result:
ok 1 number(s): "200454518772"
Test #4:
score: 10
Accepted
time: 19ms
memory: 5468kb
input:
100000 39 41 6 41 37 4 3 31 11 23 12 45 15 5 34 41 43 20 25 34 21 30 32 8 3 16 29 11 49 17 9 33 19 42 44 24 41 29 44 44 4 12 18 37 7 50 3 20 6 40 30 31 32 47 32 29 45 48 1 49 48 38 26 27 9 31 32 45 27 24 25 43 14 11 17 7 23 9 49 46 47 27 40 28 8 4 38 46 28 13 22 19 31 31 44 13 2 3 46 34 20 19 42 20 ...
output:
99779331604
result:
ok 1 number(s): "99779331604"
Test #5:
score: 10
Accepted
time: 23ms
memory: 5496kb
input:
100000 18 35 5 18 36 23 33 15 16 5 6 43 9 46 49 8 23 33 44 24 24 8 42 41 14 29 42 22 12 38 36 7 14 28 6 24 21 46 32 1 47 23 49 46 4 33 19 10 28 48 40 36 18 21 28 13 36 19 10 3 13 47 11 1 41 39 17 22 26 12 20 29 29 19 43 38 29 46 44 4 1 29 20 2 1 25 14 43 28 36 10 35 38 46 4 49 10 50 38 4 43 43 47 15...
output:
100001868666
result:
ok 1 number(s): "100001868666"
Test #6:
score: 10
Accepted
time: 35ms
memory: 5504kb
input:
100000 527194 477800 752839 180167 191874 389516 36225 830569 268550 174287 567002 62920 413688 164227 609932 825264 260957 338574 240390 666689 97260 424232 802475 425711 539346 265633 753489 222400 391024 841304 417667 626065 777244 665797 529408 865362 195996 120688 528569 405445 252590 98423 304...
output:
3328288024082832
result:
ok 1 number(s): "3328288024082832"
Test #7:
score: 10
Accepted
time: 34ms
memory: 5484kb
input:
100000 935271 64094 419766 967410 987200 672980 992196 981416 474184 738909 354481 198562 816020 928280 252364 745096 13133 241046 711161 803190 308786 455327 784368 613951 196115 637358 496763 361573 148311 660401 447164 478627 62967 444042 926116 70500 260801 938000 905917 378952 86806 690831 3709...
output:
3336745272733726
result:
ok 1 number(s): "3336745272733726"
Test #8:
score: 10
Accepted
time: 31ms
memory: 5564kb
input:
100000 451411 844648 49244 316664 498681 636452 176184 915572 811070 999349 946929 998652 609749 931307 700281 992818 484884 639064 8106 91131 232372 562837 658751 927808 506323 764283 954328 75886 448181 403819 765946 596726 6399 246151 329229 905229 490876 525238 406428 819245 448024 856612 571544...
output:
3338427607942440
result:
ok 1 number(s): "3338427607942440"
Test #9:
score: 10
Accepted
time: 33ms
memory: 5636kb
input:
100000 945922 870287 139920 474749 874211 112088 630085 399075 696722 834935 812682 466419 626600 487984 598259 925625 340435 783993 396774 342902 11860 775614 370080 659039 446337 949595 92401 976732 334788 493541 550267 296394 137241 576226 912439 357626 807892 970443 105584 312431 401817 791505 3...
output:
1998848192031322
result:
ok 1 number(s): "1998848192031322"
Test #10:
score: 10
Accepted
time: 37ms
memory: 5476kb
input:
100000 996642 419131 144666 328419 966569 590864 626261 583063 630878 139117 73122 26162 393986 281713 535878 373542 845053 288448 827496 382951 75609 923391 477590 533422 792898 292508 186622 434297 16396 728003 69493 582472 512237 486954 747252 728034 642622 200518 692821 102542 874814 185428 3708...
output:
2001013327678236
result:
ok 1 number(s): "2001013327678236"
Extra Test:
score: 0
Extra Test Passed