QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#436969 | #8781. Element-Wise Comparison | ucup-team3099# | TL | 1ms | 7784kb | C++23 | 4.0kb | 2024-06-09 03:59:00 | 2024-06-09 03:59:01 |
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<2*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);
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; 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)) = i + n - i - 1 = n - 1
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.
*/
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 7736kb
input:
5 3 5 2 1 3 4
output:
0
result:
ok answer is '0'
Test #2:
score: 0
Accepted
time: 1ms
memory: 7784kb
input:
5 2 3 1 4 2 5
output:
2
result:
ok answer is '2'
Test #3:
score: 0
Accepted
time: 1ms
memory: 7688kb
input:
4 2 1 2 3 4
output:
3
result:
ok answer is '3'
Test #4:
score: 0
Accepted
time: 1ms
memory: 7724kb
input:
4 2 4 3 2 1
output:
0
result:
ok answer is '0'
Test #5:
score: 0
Accepted
time: 1ms
memory: 3708kb
input:
1 1 1
output:
0
result:
ok answer is '0'
Test #6:
score: -100
Time Limit Exceeded
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...