QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#665998 | #6604. Kobolds and Catacombs | lonelywolf# | WA | 395ms | 26804kb | C++20 | 1.7kb | 2024-10-22 16:12:21 | 2024-10-22 16:12:31 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define int long long
template <typename T>
struct Fenwick {
int n;
vector<T> a;
Fenwick(int n_ = 0) {
init(n_);
}
void init(int n_) {
n = n_;
a.assign(n + 1, T{});
}
void add(int x, const T &v) {
for (int i = x; i <= n; i += i & -i) {
a[i] = a[i] + v;
}
}
T sum(int x) {
T ans{};
for (int i = x; i > 0; i -= i & -i) {
ans = ans + a[i];
}
return ans;
}
T rangeSum(int l, int r) {
return sum(r) - sum(l - 1);
}
// 权值树状数组,查询第k小
int select(const T &k) {
int x = 0;
T cur{};
for (int i = 1 << __lg(n); i; i /= 2) {
if (x + i < n && cur + a[x + i] < k) {
x += i;
cur = cur + a[x];
}
}
return x + 1;
}
};
vector<int> discrete(const vector<int> &a) {
auto tmp = a;
sort(tmp.begin(), tmp.end());
sort(tmp.begin() + 1, tmp.end());
tmp.erase(unique(tmp.begin() + 1, tmp.end()), tmp.end());
vector<int> ret(a.size());
for (int i = 1; i < a.size(); i++) {
ret[i] = lower_bound(tmp.begin() + 1, tmp.end(), a[i]) - tmp.begin();
}
return ret;
}
signed main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n;
cin >> n;
vector<int> a(n + 1);
for (int i = 1; i <= n; i++) {
cin >> a[i];
}
a = discrete(a);
auto ta = a;
sort(ta.begin(), ta.end());
Fenwick<int> f(n);
int ans = 0;
for (int i = 1; i <= n; i++) {
f.add(a[i], 1);
if (f.sum(ta[i]) == i) {
ans++;
}
}
cout << ans << "\n";
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3484kb
input:
5 1 3 2 7 4
output:
3
result:
ok 1 number(s): "3"
Test #2:
score: 0
Accepted
time: 387ms
memory: 26804kb
input:
1000000 524227301 431992275 758916082 293029389 719487809 413407585 7533705 414925441 87316769 639877621 980912701 739058961 277730843 958292661 778325685 500280161 782766985 339709027 1968001 842653531 847517701 989893001 97622801 728458741 612188545 787566057 981715521 281901909 804267925 89113887...
output:
1
result:
ok 1 number(s): "1"
Test #3:
score: 0
Accepted
time: 389ms
memory: 26584kb
input:
1000000 917949585 857260961 756665311 378355301 764449441 412507811 172034129 259899788 32062001 770226301 952621053 541484449 569936821 627592441 215749889 859777895 354928623 873704001 816399789 991063481 915131641 712367896 390917421 345695004 999782016 716109223 361816825 689562663 101790565 284...
output:
1
result:
ok 1 number(s): "1"
Test #4:
score: 0
Accepted
time: 73ms
memory: 26568kb
input:
1000000 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ...
output:
1000000
result:
ok 1 number(s): "1000000"
Test #5:
score: 0
Accepted
time: 105ms
memory: 26536kb
input:
1000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 100000...
output:
1000000
result:
ok 1 number(s): "1000000"
Test #6:
score: 0
Accepted
time: 130ms
memory: 26464kb
input:
1000000 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 ...
output:
1000000
result:
ok 1 number(s): "1000000"
Test #7:
score: 0
Accepted
time: 121ms
memory: 26504kb
input:
1000000 1000000 999999 999998 999997 999996 999995 999994 999993 999992 999991 999990 999989 999988 999987 999986 999985 999984 999983 999982 999981 999980 999979 999978 999977 999976 999975 999974 999973 999972 999971 999970 999969 999968 999967 999966 999965 999964 999963 999962 999961 999960 9999...
output:
1
result:
ok 1 number(s): "1"
Test #8:
score: 0
Accepted
time: 196ms
memory: 26504kb
input:
1000000 644593 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 644101 26 27 28 29 30 31 32 643568 34 35 330711 339005 38 39 40 578571 42 43 44 45 46 47 48 49 50 683111 52 53 54 936601 56 26971 58 59 60 909777 62 63 64 479605 66 67 68 69 216503 71 72 133286 74 75 76 77 78 950161 80 81 82...
output:
5
result:
ok 1 number(s): "5"
Test #9:
score: 0
Accepted
time: 211ms
memory: 26644kb
input:
1000000 925960 484918 999998 999997 999996 999995 999994 999993 999992 999991 396232 999989 999988 999987 999986 909136 999984 999983 999982 999981 546797 999979 999978 999977 370720 999975 999974 999973 889900 999971 999970 999969 428403 999967 999966 999965 941125 999963 999962 999961 999960 99995...
output:
1
result:
ok 1 number(s): "1"
Test #10:
score: 0
Accepted
time: 0ms
memory: 3584kb
input:
1 1
output:
1
result:
ok 1 number(s): "1"
Test #11:
score: 0
Accepted
time: 0ms
memory: 3536kb
input:
1 1000000000
output:
1
result:
ok 1 number(s): "1"
Test #12:
score: 0
Accepted
time: 0ms
memory: 3528kb
input:
2 1 2
output:
2
result:
ok 1 number(s): "2"
Test #13:
score: 0
Accepted
time: 0ms
memory: 3584kb
input:
2 999999999 1
output:
1
result:
ok 1 number(s): "1"
Test #14:
score: 0
Accepted
time: 375ms
memory: 26648kb
input:
1000000 586342723 439528582 534325601 527397441 69111047 708525733 964567125 797408989 657663242 361074481 351855001 683394036 768478938 866430981 391488941 139668993 315700283 301683796 950938618 652811201 895030718 762246051 758513505 431480309 505858381 868633425 709348153 39897089 874006729 1198...
output:
1
result:
ok 1 number(s): "1"
Test #15:
score: 0
Accepted
time: 395ms
memory: 26600kb
input:
1000000 954794397 659831876 690237901 61500881 278431281 156748253 446041221 842695161 546785671 773749926 485956147 609494627 400435921 8377321 766721779 136618697 931232625 872057921 658877059 522113233 796888245 82127761 841077901 652095691 764639540 484453926 33179521 433549441 760785241 3486318...
output:
1
result:
ok 1 number(s): "1"
Test #16:
score: 0
Accepted
time: 394ms
memory: 26632kb
input:
1000000 128840331 879801121 670528493 901520277 287501561 470233351 378643431 513453281 682933401 790677901 165011489 984840511 127177501 429591681 278342801 752147841 692314989 832989249 467306522 456552948 423884289 191857613 158974681 426788513 149616705 324894881 957251929 843413581 77455801 979...
output:
1
result:
ok 1 number(s): "1"
Test #17:
score: 0
Accepted
time: 394ms
memory: 26532kb
input:
1000000 161013121 664403189 614216489 698442181 219647457 436165251 998498409 287752251 300275311 329438101 56648611 639847201 79783786 5691119 696920001 52923297 311784066 955714611 683832021 689830541 968313713 402592241 253942497 83948056 913972223 937838081 473079781 824166351 597287105 96825832...
output:
1
result:
ok 1 number(s): "1"
Test #18:
score: -100
Wrong Answer
time: 0ms
memory: 3528kb
input:
8 1 3 2 3 6 2 5 6
output:
4
result:
wrong answer 1st numbers differ - expected: '3', found: '4'