QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#530269 | #3276. 出题高手 | liuziao | 15 | 243ms | 22028kb | C++20 | 2.9kb | 2024-08-24 15:45:17 | 2024-08-24 15:45:17 |
Judging History
answer
#include <bits/stdc++.h>
#define int int64_t
const int kMaxN = 5e5 + 5;
struct Frac {
int x, y; // x / y;
Frac(int _x = 0, int _y = 1) {
// int d = std::__gcd(_x, _y);
// x = _x / d, y = _y / d;
x = _x, y = _y;
}
friend bool operator <(Frac a, Frac b) { return a.x * b.y < a.y * b.x; }
friend bool operator <=(Frac a, Frac b) { return a.x * b.y <= a.y * b.x; }
friend bool operator >(Frac a, Frac b) { return a.x * b.y > a.y * b.x; }
friend bool operator >=(Frac a, Frac b) { return a.x * b.y >= a.y * b.x; }
};
int n, m, q;
Frac mx;
int a[kMaxN], sum[kMaxN], ss[kMaxN], unq[kMaxN], pre[kMaxN][2];
std::vector<std::tuple<int, int, Frac>> vec;
struct BIT1 {
int c[kMaxN];
void upd(int x, int v) {
for (; x <= m; x += x & -x) c[x] = std::max(c[x], v);
}
int qry(int x) {
int ret = 0;
for (; x; x -= x & -x) ret = std::max(ret, c[x]);
return ret;
}
} bit1;
struct BIT2 {
int c[kMaxN];
void upd(int x, int v) {
for (; x; x -= x & -x) c[x] = std::max(c[x], v);
}
int qry(int x) {
int ret = 0;
for (; x <= m; x += x & -x) ret = std::max(ret, c[x]);
return ret;
}
} bit2;
void prework() {
for (int i = 1; i <= n; ++i) {
sum[i] = sum[i - 1] + a[i];
unq[i] = sum[i];
}
std::sort(unq + 1, unq + 1 + n);
m = std::unique(unq + 1, unq + 1 + n) - (unq + 1);
for (int i = 1; i <= n; ++i) ss[i] = std::lower_bound(unq + 1, unq + 1 + m, sum[i]) - unq;
pre[0][0] = pre[0][1] = -1;
for (int i = 1; i <= n; ++i) {
pre[i][0] = bit1.qry(ss[i]);
pre[i][1] = bit2.qry(ss[i]);
bit1.upd(ss[i], i), bit2.upd(ss[i], i);
}
for (int i = 1; i <= n; ++i) {
// std::cerr << i << '\n';
Frac now = {-1000000000, 1};
for (int j = pre[i][0]; ~j; j = pre[j][0]) {
Frac tmp = Frac((sum[i] - sum[j]) * (sum[i] - sum[j]), i - j);
// if (tmp > now) vec.emplace_back(j + 1, i, tmp);
mx = std::max(mx, tmp);
}
now = {-1000000000, 1};
for (int j = pre[i][1]; ~j; j = pre[j][1]) {
Frac tmp = Frac((sum[i] - sum[j]) * (sum[i] - sum[j]), i - j);
// if (tmp > now) vec.emplace_back(j + 1, i, tmp);
mx = std::max(mx, tmp);
}
}
}
void dickdreamer() {
std::cin >> n;
for (int i = 1; i <= n; ++i) std::cin >> a[i];
prework();
std::cin >> q;
for (int i = 1; i <= q; ++i) {
int ql, qr;
std::cin >> ql >> qr;
// Frac ans = {0, 1};
// for (auto [l, r, w] : vec)
// if (l >= ql && r <= qr)
// ans = std::max(ans, w);
// std::cout << ans.x << ' ' << ans.y << '\n';
std::cout << mx.x << ' ' << mx.y << '\n';
}
}
int32_t main() {
#ifdef ORZXKR
freopen("in.txt", "r", stdin);
freopen("out.txt", "w", stdout);
#endif
std::ios::sync_with_stdio(0), std::cin.tie(0), std::cout.tie(0);
int T = 1;
// std::cin >> T;
while (T--) dickdreamer();
std::cerr << 1.0 * clock() / CLOCKS_PER_SEC << "s\n";
return 0;
}
详细
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 0
Wrong Answer
time: 13ms
memory: 12224kb
input:
2000 -113 314 -664 697 211 -199 -38 -190 8 -661 910 -811 -113 942 77 433 -261 -368 129 -525 968 -608 -21 38 -562 438 -935 -228 220 333 985 -430 916 586 764 476 794 664 383 503 206 -60 380 -130 -988 -904 -996 -304 -286 31 114 119 850 -942 714 -369 -842 250 -192 -462 -727 -427 -602 126 231 718 121 559...
output:
164480625 33 164480625 33 164480625 33 164480625 33 164480625 33 164480625 33 164480625 33 164480625 33 164480625 33 164480625 33 164480625 33 164480625 33 164480625 33 164480625 33 164480625 33 164480625 33 164480625 33 164480625 33 164480625 33 164480625 33 164480625 33 164480625 33 164480625 33 1...
result:
wrong answer 1st numbers differ - expected: '54826875', found: '164480625'
Subtask #2:
score: 15
Accepted
Test #6:
score: 15
Accepted
time: 92ms
memory: 15892kb
input:
100000 754 792 -680 426 425 347 481 -690 530 378 73 -907 -431 45 -530 -552 440 -890 -15 712 695 -679 -310 13 718 805 193 -291 -877 -74 -355 511 -679 -395 166 -710 -657 -19 874 26 832 507 854 -289 700 -404 472 -302 -977 8 -698 40 766 705 369 838 700 -964 552 -535 -75 -608 -181 -503 468 447 772 904 -2...
output:
466344025 67
result:
ok 2 number(s): "466344025 67"
Test #7:
score: 15
Accepted
time: 124ms
memory: 18320kb
input:
100000 -387 -313 -47 -714 -74 239 8 591 541 -633 -660 981 -230 -148 -813 -802 -108 -543 -640 50 962 137 -972 -936 -975 885 793 -541 932 861 -348 885 -280 -977 -677 964 355 604 54 -977 -548 979 -516 136 437 -697 -23 -748 492 897 -538 785 617 -840 675 -978 307 -288 -493 682 678 -623 613 762 -622 -283 ...
output:
2417885584 385
result:
ok 2 number(s): "2417885584 385"
Test #8:
score: 15
Accepted
time: 110ms
memory: 22028kb
input:
100000 -127 303 92 -235 -794 293 -272 199 -175 693 -799 -750 -501 -283 -358 -657 -867 -152 -399 -299 530 -5 285 959 390 -928 617 -478 -889 -133 -492 -855 986 -664 -984 -690 887 -738 39 -570 -268 -767 640 883 711 -748 -75 426 -268 -541 -926 -792 902 214 561 -428 -285 781 -225 -299 -233 134 -896 569 -...
output:
202236841 30
result:
ok 2 number(s): "202236841 30"
Test #9:
score: 15
Accepted
time: 177ms
memory: 18404kb
input:
100000 -340 -696 48 -515 -584 -60 -888 257 214 -889 782 915 905 -964 -536 459 779 -519 -338 -867 622 -902 655 -153 600 -117 269 -887 -242 -985 -267 132 406 98 -368 400 -871 -908 -489 118 -140 -755 -869 -943 965 609 47 -748 194 -160 994 527 871 119 -891 580 -687 865 826 56 -978 -775 -47 792 313 -944 ...
output:
272184004 39
result:
ok 2 number(s): "272184004 39"
Test #10:
score: 15
Accepted
time: 127ms
memory: 16100kb
input:
100000 -736 -691 738 209 -411 -136 792 -110 -441 -753 254 744 -958 -317 312 856 245 995 912 87 -830 131 393 37 -400 934 279 -784 -308 618 -647 967 527 -162 -874 -770 188 -917 -855 772 482 -373 -749 -40 80 -459 710 -354 221 -343 -132 -947 -445 62 -744 851 848 554 -530 -892 -721 -910 -642 -138 -480 -7...
output:
393070276 51
result:
ok 2 number(s): "393070276 51"
Subtask #3:
score: 0
Time Limit Exceeded
Test #11:
score: 0
Time Limit Exceeded
input:
500000 794 -75 -596 -322 -945 -908 -609 -164 488 626 -877 -710 140 -120 -475 -837 738 669 634 -643 -682 667 816 -785 -608 -836 -860 -932 242 70 -620 268 -121 288 209 -392 732 750 558 -480 565 327 -217 -891 767 211 -690 -66 813 -889 952 615 432 19 411 800 678 718 522 422 940 -510 -544 449 -357 640 40...
output:
result:
Subtask #4:
score: 0
Wrong Answer
Test #16:
score: 0
Wrong Answer
time: 98ms
memory: 18172kb
input:
100000 -496 -233 354 -632 -196 177 -878 -255 -19 -636 685 -70 101 -975 -406 -988 -965 -205 563 -766 763 511 -116 -746 -129 14 106 928 -457 -257 -283 226 3 899 -359 -792 615 490 -57 986 -243 624 -239 931 -555 -821 -72 -611 -380 -397 248 -132 956 -195 -322 -231 319 -214 837 -379 -931 -301 -4 -673 280 ...
output:
111471364 16 111471364 16 111471364 16 111471364 16 111471364 16 111471364 16 111471364 16 111471364 16 111471364 16 111471364 16 111471364 16 111471364 16 111471364 16 111471364 16 111471364 16 111471364 16 111471364 16 111471364 16 111471364 16 111471364 16 111471364 16 111471364 16 111471364 16 1...
result:
wrong answer 1st numbers differ - expected: '1352474176', found: '111471364'
Subtask #5:
score: 0
Wrong Answer
Test #31:
score: 0
Wrong Answer
time: 243ms
memory: 16280kb
input:
100000 139 -485 -497 -818 254 169 -560 22 377 -67 -243 -75 743 -788 -676 -26 -775 371 576 -303 54 733 422 800 445 687 479 -16 -288 259 783 -586 912 616 439 -416 676 -555 172 659 501 -868 337 22 -60 260 603 -982 -149 466 769 -595 -117 949 -544 904 753 20 776 175 -888 937 -792 -647 -615 59 -298 452 -6...
output:
1204784100 141 1204784100 141 1204784100 141 1204784100 141 1204784100 141 1204784100 141 1204784100 141 1204784100 141 1204784100 141 1204784100 141 1204784100 141 1204784100 141 1204784100 141 1204784100 141 1204784100 141 1204784100 141 1204784100 141 1204784100 141 1204784100 141 1204784100 141 ...
result:
wrong answer 1st numbers differ - expected: '401594700', found: '1204784100'