QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#436993 | #8781. Element-Wise Comparison | ucup-team3099# | WA | 279ms | 621828kb | C++23 | 4.1kb | 2024-06-09 04:06:29 | 2024-06-09 04:06:30 |
Judging History
answer
#include <iostream>
#include <vector>
#include <chrono>
#include <random>
#include <cassert>
#include <bitset>
std::mt19937 rng((int) std::chrono::steady_clock::now().time_since_epoch().count());
const int ms = 50500;
std::bitset<ms> prefix[ms], suffix[ms], individual[ms], curBitset;
int main() {
std::ios_base::sync_with_stdio(false); std::cin.tie(NULL);
int n, m;
std::cin >> n >> m;
if(m == 1) {
std::cout << (long long) n * (n - 1) / 2 << '\n';
return 0;
}
std::vector<int> a(n), pos(n);
// for(int i = 0; i < n; i++) {
// a[i] = i + 1;
// }
// std::shuffle(a.begin(), a.end(), rng);
const int bs = m-1;
for(int i = 0; i < n; i++) {
std::cin >> a[i];
a[i]--;
pos[a[i]] = i;
}
for(int i = n-1; i >= 0; i--) {
int curPos = pos[i];
prefix[curPos] = curBitset << curPos;
curBitset[n-curPos-1] = true;
}
// for(int i = 0; i < n; i++) {
// curBitset = prefix[i];
// for(int j = 0; j <= 2 * n; j++) {
// if(curBitset[j]) {
// std::cout << "for individual " << i << " got difference " << j << '\n';
// }
// }
// }
for(int l = 0, r; l < n; l = r) {
r = std::min(n, l + bs);
suffix[r-1] = prefix[r-1];
for(int i = r-2; i >= l; i--) {
suffix[i] &= suffix[i+1];
}
for(int i = l+1; i < r; i++) {
prefix[i] &= prefix[i-1];
}
}
long long ans = 0;
curBitset ^= curBitset;
for(int i = 0; i < n-1; i++) {
curBitset[i] = true;
}
for(int i = 0; i + m <= n; i++) {
// for(int j = 0; j <= 2 * n; j++) {
// if(curBitset[j]) {
// std::cout << "for [" << i << ", " << i+m << ") got difference " << j << '\n';
// }
// }
// need to count starting from i+(n-(i+1)-1) = i + n - i - 2 = n - 2
ans += ((prefix[i] & suffix[i+m-1]) & curBitset).count();
}
std::cout << ans << '\n';
}
/*
NEVER FORGET TO:
Look at the problem's constraints before coding.
How to cheese cf:
Find a lower bound or upper bound for the problem. Have faith that it is the answer of the problem.
If it isn't the answer, have more faith or change to another bound god by looking for a better bound.
Trust guesses. Who has time to think? If people in div2 AC the problem it requires no proof since people don't prove things.
You must draw cases. Thinking gets you nowhere, so draw cases and reach illogical conclusions from them.
Sometimes drawing cases is bad because it takes too much time. Faster is to not think at all and just code a bruteforce solution.
This is called "law of small numbers". If something works for small numbers, surely it works for big numbers.
https://en.wikipedia.org/wiki/Faulty_generalization#Hasty_generalization don't mind the "faulty" part of it, in competitive programming mistakes are lightly punished
Don't think about them being right or not, cf is a battle of intuition only.
Be as stupid as possible in implementation. Trying to be smart is an easy way to get WA.
Think about 2x2 cases for matrix problems and hope that everything works for the general case.
Find a necessary condition and trust it to be sufficient. They're basically the same thing.
Heuristics might speed up your code. Forget about complexity, it's only about ACing and not proving that your solution is good.
For paths in a grid starting at (1, i) or something like that, assume that they never cross and do D&C
Consider doing problems in reverse order of queries/updates
For combinatorics problems, consider symmetry
General strategy (MUST DO):
Try to solve the problem with more restricted constraints.
About testing:
Test n=1, a[i]=1, a[i]=n, etc. Basically, test low values. No need to test if pretests are strong, but if you get WA it's good.
This isn't a joke. Do it if you get stuck. It's shit practice in my opinion, but do it if you want AC.
*/
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 9744kb
input:
5 3 5 2 1 3 4
output:
0
result:
ok answer is '0'
Test #2:
score: 0
Accepted
time: 1ms
memory: 7720kb
input:
5 2 3 1 4 2 5
output:
2
result:
ok answer is '2'
Test #3:
score: 0
Accepted
time: 1ms
memory: 7776kb
input:
4 2 1 2 3 4
output:
3
result:
ok answer is '3'
Test #4:
score: 0
Accepted
time: 1ms
memory: 7928kb
input:
4 2 4 3 2 1
output:
0
result:
ok answer is '0'
Test #5:
score: 0
Accepted
time: 0ms
memory: 3612kb
input:
1 1 1
output:
0
result:
ok answer is '0'
Test #6:
score: 0
Accepted
time: 279ms
memory: 621028kb
input:
50000 2 44045 29783 5389 7756 44022 45140 21967 5478 10868 49226 21775 31669 49836 13511 46116 14229 27206 31168 37389 3158 10658 41154 14635 18526 40540 6451 23197 46719 30593 13517 8604 46666 39189 43746 12778 3684 3194 36979 43020 14652 19549 31178 17144 27177 44336 2849 40220 11751 41993 32209 4...
output:
310780127
result:
ok answer is '310780127'
Test #7:
score: 0
Accepted
time: 244ms
memory: 621828kb
input:
50000 2 44015 31580 38779 29675 3269 12273 40322 471 4551 44568 21486 17093 43442 11483 9686 39913 36953 47673 34066 4943 28304 34228 9197 43349 1974 32227 8177 33236 24942 42131 34294 48071 17452 9633 18281 13817 27423 9880 15629 6991 20035 13601 39212 33548 8865 39161 48449 22164 36815 28852 43065...
output:
317708201
result:
ok answer is '317708201'
Test #8:
score: 0
Accepted
time: 269ms
memory: 621780kb
input:
50000 2 45828 16955 24033 12988 15675 6086 482 27940 30132 39389 14266 35347 46159 8317 24605 9737 30077 32664 6326 43387 7896 17806 20481 8573 8438 36474 33708 42437 8187 12300 13318 48764 34683 14983 40909 34874 47938 31131 12519 21122 22457 21062 32953 47733 46731 18062 1061 28388 27032 47303 390...
output:
309719539
result:
ok answer is '309719539'
Test #9:
score: 0
Accepted
time: 255ms
memory: 620784kb
input:
50000 2 17900 11121 24441 14321 9486 32843 40283 49359 21526 27801 47381 11444 24372 25999 16187 49470 11724 21419 31873 49053 47656 4516 33567 25021 42444 36150 1362 3711 31260 49923 19998 7275 2927 29522 40437 39439 30777 6413 17107 30917 48362 29997 47038 23951 25835 23665 2875 18889 10610 26400 ...
output:
313258830
result:
ok answer is '313258830'
Test #10:
score: 0
Accepted
time: 264ms
memory: 620892kb
input:
50000 2 29869 3482 18962 41513 1378 27297 29435 6651 12343 3742 27703 32031 15628 16084 12571 1726 30037 31904 2642 817 26607 21749 34528 33044 39980 26798 41826 37079 2809 33387 10169 47346 8551 24214 40572 43065 41730 32281 16630 47892 48890 34159 12884 8185 38452 15606 19304 8428 24230 31397 2232...
output:
313582202
result:
ok answer is '313582202'
Test #11:
score: -100
Wrong Answer
time: 274ms
memory: 620768kb
input:
50000 25 24181 9781 31983 1958 1472 39943 17049 26890 16005 42039 40012 41453 7508 47251 35614 5522 27201 31665 6000 49393 17743 30487 44282 1097 39409 39745 43972 13876 33786 40423 41046 227 44642 27611 9775 21229 48475 7795 32834 15085 44154 45504 26464 45685 42844 44948 26372 30941 8490 8094 4343...
output:
0
result:
wrong answer expected '58', found '0'