QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#460076#8781. Element-Wise Comparisonucup-team2307#TL 1ms5604kbC++201.7kb2024-06-30 21:14:162024-06-30 21:14:17

Judging History

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

  • [2024-06-30 21:14:17]
  • 评测
  • 测评结果:TL
  • 用时:1ms
  • 内存:5604kb
  • [2024-06-30 21:14:16]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;

#define fi first
#define se second
#define pb push_back

typedef long long ll;
//#define int ll

int n, m;
int p[50500];
int q[50500];
bitset<50500> bs[50500];
bitset<50500> b;

#define C 5000

main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    cin>>n>>m;
    for (int i=1; i<=n; i++)
        cin>>p[i], q[p[i]] = i;

    for (int i=1; i<=n; i++)
        b[i] = 1;
    for (int i=1; i<=n; i++)
    {
        b[q[i]] = 0;
        if (i%C == 0)
        {
            for (int d=1; d<=n-1; d++)
                bs[d] |= (b & ((~b) >> d));
        }
    }
    for (int i=1; i<=n; i++)
        for (int j=i; ; j++)
    {
        if (i!=j)
            if (q[j] < q[i])
                bs[q[i]-q[j]][q[j]] = 1;

        if (j%C == 0)
            break;
    }
    for (int i=1; i+1<=n; i++)
        bs[i] >>= 1;
//    for (int i=1; i+1<=n; i++, cout<<"\n")
//        for (int j=1; j<=n; j++)
//            cout<<bs[i][j];

    ll ans = 0;
    for (int i=1; i+1<=n; i++)
    {
        int D = n-i-m+1;
        if (D <= 0)
            continue;

//        for (int j=0; j<D; j++)
//            cout<<bs[i][j];
//        cout<<"\n";

        int mleft = m-1;
        for (int j=1; mleft > 0; j*=2)
        {
            j = min(j, mleft);
            bs[i] |= (bs[i] << j);
            mleft -= j;
        }

//        for (int j=0; j<D; j++)
//            cout<<bs[i][j];
//        cout<<"\n";

        int all = bs[i].count();
        int lt = (bs[i]>>D).count();
        int ones = all-lt;
        int zeroes = D - ones;
        ans += zeroes;
    }
    cout<<ans<<"\n";
}



詳細信息

Test #1:

score: 100
Accepted
time: 1ms
memory: 3712kb

input:

5 3
5 2 1 3 4

output:

0

result:

ok answer is '0'

Test #2:

score: 0
Accepted
time: 1ms
memory: 3460kb

input:

5 2
3 1 4 2 5

output:

2

result:

ok answer is '2'

Test #3:

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

input:

4 2
1 2 3 4

output:

3

result:

ok answer is '3'

Test #4:

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

input:

4 2
4 3 2 1

output:

0

result:

ok answer is '0'

Test #5:

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

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:


result: