QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#434457 | #8781. Element-Wise Comparison | ucup-team896# | ML | 1ms | 7740kb | C++14 | 2.0kb | 2024-06-08 16:14:44 | 2024-06-08 16:14:44 |
Judging History
answer
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#ifdef dbg
#define D(...) fprintf(stderr, __VA_ARGS__)
#define DD(...) D("[Debug] "#__VA_ARGS__ " = "), \
debug_helper::debug(__VA_ARGS__), D("\n")
#include "C:\Users\wsyear\Desktop\OI\templates\debug.hpp"
#else
#define D(...) ((void)0)
#define DD(...) ((void)0)
#endif
#define rep(i, j, k) for (int i = (j); i <= (k); ++i)
#define per(i, j, k) for (int i = (j); i >= (k); --i)
#define SZ(v) int((v).size())
#define ALL(v) (v).begin(),(v).end()
#define fi first
#define se second
using ll = long long;
using pii = std::pair<int, int>;
using pll = std::pair<ll, ll>;
template<class T> void chkmn(T &x, T y) { if (y < x) x = y; }
template<class T> void chkmx(T &x, T y) { if (y > x) x = y; }
using namespace std;
const int maxn = 50010;
bitset<maxn> f[maxn], o, cur, t[maxn << 2], tmp;
int n, m, a[maxn], pos[maxn];
#define mid ((l + r) >> 1)
void upd(int c, int l, int r, int x, int y) {
if (l == x && r == y) return t[c] &= tmp, void();
if (y <= mid) upd(c << 1, l, mid, x, y);
else if (x > mid) upd(c << 1 | 1, mid + 1, r, x, y);
else upd(c << 1, l, mid, x, mid), upd(c << 1 | 1, mid + 1, r, mid + 1, y);
}
void solve(int c, int l, int r) {
if (l == r) return f[l] &= t[c], void();
t[c << 1] &= t[c], t[c << 1 | 1] &= t[c];
solve(c << 1, l, mid), solve(c << 1 | 1, mid + 1, r);
}
#undef mid
int main() {
cin.tie(nullptr) -> ios::sync_with_stdio(false);
cin >> n >> m;
rep (i, 1, n) cin >> a[i];
rep (i, 1, n - m) o.set(i);
rep (i, 1, n - m) f[i] = o, o.reset(n - m - i + 1);
rep (i, 1, n << 2) t[i].set();
rep (i, 1, n) pos[a[i]] = i;
cur.set();
rep (i, 1, n) {
cur.reset(pos[i]);
tmp = cur >> pos[i];
// rep (p, max(1, pos[i] - m + 1), pos[i]) f[p] &= tmp;
upd(1, 1, n, max(1, pos[i] - m + 1), pos[i]);
}
solve(1, 1, n);
ll ans = 0;
rep (i, 1, n) ans += f[i].count();
cout << ans << '\n';
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 6020kb
input:
5 3 5 2 1 3 4
output:
0
result:
ok answer is '0'
Test #2:
score: 0
Accepted
time: 0ms
memory: 7672kb
input:
5 2 3 1 4 2 5
output:
2
result:
ok answer is '2'
Test #3:
score: 0
Accepted
time: 1ms
memory: 5752kb
input:
4 2 1 2 3 4
output:
3
result:
ok answer is '3'
Test #4:
score: 0
Accepted
time: 1ms
memory: 7632kb
input:
4 2 4 3 2 1
output:
0
result:
ok answer is '0'
Test #5:
score: 0
Accepted
time: 1ms
memory: 7740kb
input:
1 1 1
output:
0
result:
ok answer is '0'
Test #6:
score: -100
Memory 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...
output:
310780127