QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#623163#8781. Element-Wise Comparisonrns_jkTL 0ms3884kbC++141.0kb2024-10-09 10:27:302024-10-09 10:27:32

Judging History

你现在查看的是最新测评结果

  • [2024-10-09 10:27:32]
  • 评测
  • 测评结果:TL
  • 用时:0ms
  • 内存:3884kb
  • [2024-10-09 10:27:30]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
#define N 50000
// #define N 5
using ll = long long;
int main() {
    int n, m;
    cin >> n >> m;
    vector<int> p(n), q(n);
    for (int i = 0; i < n; i++) {
        cin >> p[i];
        p[i]--;
        q[p[i]] = i;  
    }
    vector<bitset<N>> c(n), pre(n + 1), suf(n);
    bitset<N> u;
    for (int i = 0; i < n; i++) u.set(i);
    for (int i = 0; i < n; i++) {
        u.set(q[i], false);
        c[q[i]] = u;
    }
    // for (int i = 0; i < n; i++) cout << c[i] << endl;
       
    for (int i = 1; i < n; i++) c[i] = c[i] >> i;
    for (int i = 0; i < n; i ++) {
        if (i % m == 0) suf[i] = c[i];
        else suf[i] = suf[i - 1] & c[i];
    }
    u = 0;
    for (int i = n - 1; i >= 0; i--) {
        if (i % m == 0) pre[i] = c[i];
        else pre[i] = pre[i + 1] & c[i];
    }
    
    ll ret = 0;
    
    for (int i = 0; i + m <= n; i++) {
        u = pre[i] & suf[i + m - 1];
        ret += u.count();
    }
    
    cout << ret << endl;
    
    return 0;
}

详细

Test #1:

score: 100
Accepted
time: 0ms
memory: 3700kb

input:

5 3
5 2 1 3 4

output:

0

result:

ok answer is '0'

Test #2:

score: 0
Accepted
time: 0ms
memory: 3704kb

input:

5 2
3 1 4 2 5

output:

2

result:

ok answer is '2'

Test #3:

score: 0
Accepted
time: 0ms
memory: 3696kb

input:

4 2
1 2 3 4

output:

3

result:

ok answer is '3'

Test #4:

score: 0
Accepted
time: 0ms
memory: 3884kb

input:

4 2
4 3 2 1

output:

0

result:

ok answer is '0'

Test #5:

score: 0
Accepted
time: 0ms
memory: 3624kb

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...

output:

310780127

result: