QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#539632#6820. Youth Finaleucup-team1329#AC ✓40ms9816kbC++143.5kb2024-08-31 15:17:282024-08-31 15:17:31

Judging History

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

  • [2024-08-31 15:17:31]
  • 评测
  • 测评结果:AC
  • 用时:40ms
  • 内存:9816kb
  • [2024-08-31 15:17:28]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;

#define all(x) x.begin(), x.end()
#define all1(x) x.begin() + 1, x.end()
#define bit1(x) __builtin_popcountll(x)
#define Pqueue priority_queue
#define lc p << 1
#define rc p << 1 | 1
#define IOS ios::sync_with_stdio(false), cin.tie(0);
#define fi first
#define se second
#define lowbit(x) (x & -x)

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef pair<ll, ll> PII;

const ll mod = 1000000007;
const ll N = 1e6 + 10;
const ld eps = 1e-9;
const ll inf = 1e18;
const ll P = 131;
const ll dir[8][2] = {1, 0, 0, 1, -1, 0, 0, -1, 1, 1, 1, -1, -1, 1, -1, -1};

struct BIT
{
    int n;
    vector<ll> tr;

    BIT() {};
    BIT(int N) : n(N)
    {
        tr.resize(n + 1);
    };

    void change(int pos, int k)
    {
        int x = pos;
        while (x <= n)
        {
            tr[x] += k;
            x += lowbit(x);
        }
    }
    ll query(int pos)
    {
        ll sum = 0, x = pos;
        while (x)
        {
            sum += tr[x];
            x -= lowbit(x);
        }
        return sum;
    }
    ll query(int l, int r)
    {
        return query(r) - query(l - 1);
    }
};

void solve()
{
    ll n, m;
    cin >> n >> m;
    vector<ll> p(n + 1);
    for (ll i = 1; i <= n; i++)
        cin >> p[i];
    string s;
    cin >> s;
    BIT bit(n);
    ll ans = 0;
    for (ll i = 1; i <= n; i++)
    {
        ans += bit.query(p[i] + 1, n);
        bit.change(p[i], 1);
    }
    deque<int> sq;
    for (int i = 1; i <= n; i++)
        sq.push_back(p[i]);
    cout << ans << "\n";
    ll l = 1;
    bool flag = 0;
    for (auto i : s)
    {
        if (i == 'S')
        {
            if (!flag)
            {
                ll x = sq.front();
                sq.pop_front();
                ans -= x - 1;
                ans += n - x;
                sq.push_back(x);
            }
            else
            {
                ll x = sq.back();
                sq.pop_back();
                ans += x - 1;
                ans -= n - x;
                sq.push_front(x);
            }
        }
        else
            flag = !flag;
        if (!flag)
            cout << ans % 10;
        else
            cout << (n * (n - 1) - ans) % 10;
    }
    cout << "\n";
}

int main()
{
    IOS int T = 1;
    // cin>>T;
    while (T--)
        solve();
    return 0;
}

/*
oxoxoxoxoxoxoxoxoxoxoxoxoxoxoxoxoxoxoxoxoxoxoxoxoxoxoxoxoxoxoxoxoxoxoxoxoxoxoxoxoxoxoxox
x                                                                                      o
o       _/_/_/_/                                                              _/       x
x      _/                                                                              o
o     _/_/_/_/ _/  _/_/   _/_/   _/_/_/ _/_/   _/_/_/     _/_/    _/_/_/    _/ _/   _/ x
x    _/       _/_/     _/    _/ _/   _/   _/  _/    _/ _/    _/  _/    _/  _/   _/ _/  o
o   _/       _/       _/    _/ _/   _/   _/  _/    _/ _/    _/  _/    _/  _/    _/_/   x
x  _/       _/         _/_/   _/   _/   _/  _/_/_/     _/_/ _/ _/    _/  _/      _/    o
o                                          _/                           _/      _/     x
x                                         _/                        _/_/       _/      o
o                                                                                      x
xoxoxoxoxoxoxoxoxoxoxoxoxoxoxoxoxoxoxoxoxoxoxoxoxoxoxoxoxoxoxoxoxoxoxoxoxoxoxoxoxoxoxoxo
*/

这程序好像有点Bug,我给组数据试试?

詳細信息

Test #1:

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

input:

5 10
5 4 3 2 1
SSSSRSSSSR

output:

10
6446466400

result:

ok 2 tokens

Test #2:

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

input:

1 1
1
R

output:

0
0

result:

ok 2 tokens

Test #3:

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

input:

1000 2000
313 691 343 806 897 516 38 769 391 353 43 55 246 7 65 790 185 362 60 203 642 66 731 64 760 780 266 920 805 48 724 788 730 560 766 491 748 986 439 904 619 749 652 571 617 785 202 588 234 5 717 113 84 823 399 282 269 894 703 745 886 364 258 177 622 621 573 322 487 422 413 58 39 436 543 756 9...

output:

251209
43874381050107890783098123234927898721470309674923058363694547296507416143876969292321676989034983038541030987896725616943010543872367252169438969430743696107694147678721892527816985092189692785010789030107898907692961674507816763438529678381214145296929276765098723496107898943450929092765672...

result:

ok 2 tokens

Test #4:

score: 0
Accepted
time: 17ms
memory: 4124kb

input:

1000 600000
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 ...

output:

0
9614541690961454169096145416909614541690961454169096145416909614541690961454169096145416909614541690961454169096145416909614541690961454169096145416909614541690961454169096145416909614541690961454169096145416909614541690961454169096145416909614541690961454169096145416909614541690961454169096145416...

result:

ok 2 tokens

Test #5:

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

input:

1000 2000
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 10...

output:

0
9614541690961454169096145416909614541690961454169096145416909614541690961454169096145416909614541690961454169096145416909614541690961454169096145416909614541690961454169096145416909614541690961454169096145416909614541690961454169096145416909614541690961454169096145416909614541690961454169096145416...

result:

ok 2 tokens

Test #6:

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

input:

1000 2000
150 443 960 545 218 487 896 382 519 944 26 699 275 12 715 906 956 513 495 297 501 843 269 378 132 7 758 216 344 660 400 708 9 778 131 803 61 852 746 305 953 354 805 502 601 407 24 189 458 861 17 622 210 500 617 403 650 379 673 943 6 677 196 161 902 743 375 428 723 100 51 614 535 719 780 66...

output:

250097
83450763698129098341058307214561498329894785414721856749038329874905010347832743016943894929492589674569432745416385658569830323278525834143676161670903650345854749414367692929234383210763838129490921254905294583814907656567818349630325814769870507234541478147890327650783412563254523490989252...

result:

ok 2 tokens

Test #7:

score: 0
Accepted
time: 36ms
memory: 9816kb

input:

300000 600000
59593 244970 183397 263692 143501 110537 3864 101843 1080 104527 47380 223219 88791 12167 155830 135504 187349 12430 104143 118721 192905 131555 80271 1440 232446 220093 111239 220148 22134 269720 31720 4511 60938 127008 57672 144594 165595 88632 203696 126332 4331 276338 12191 164758 ...

output:

22488549666
129652501892189256101212169478983858965216501074707832381458963252107090301050109450169292961092165052183254521032967652747816749216901258905616707858549232943814925070701810349416929250129090761070561630709034165054923438385670363616369230107214961216925018367290125434907878747270581876...

result:

ok 2 tokens

Test #8:

score: 0
Accepted
time: 35ms
memory: 9744kb

input:

300000 600000
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 9...

output:

0
9614541690961454169096145416909614541690961454169096145416909614541690961454169096145416909614541690961454169096145416909614541690961454169096145416909614541690961454169096145416909614541690961454169096145416909614541690961454169096145416909614541690961454169096145416909614541690961454169096145416...

result:

ok 2 tokens

Test #9:

score: 0
Accepted
time: 40ms
memory: 9748kb

input:

300000 600000
256714 282921 213569 167450 279657 195033 47299 86621 75700 204165 55521 58785 99140 55086 10559 56761 258898 111717 26169 80370 121033 15029 190330 179354 275543 99358 232270 276133 261366 31764 283311 254699 90077 39580 30549 146621 283862 157645 7990 1250 284849 76808 122147 282676 ...

output:

22561618259
214527090101214385894781612769818921890149654567650927854163078349010765232903832345094167076323438385438149498145892165056787058381076183432549476347432109876745816789618589274921454143852101810125616145252987030525894729076907496925612783698781054583096909412145814167612389054187894181...

result:

ok 2 tokens