QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#539584#6820. Youth Finaleucup-team1329#WA 16ms4048kbC++143.2kb2024-08-31 15:10:122024-08-31 15:10:12

Judging History

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

  • [2024-08-31 15:10:12]
  • 评测
  • 测评结果:WA
  • 用时:16ms
  • 内存:4048kb
  • [2024-08-31 15:10:12]
  • 提交

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);
    }
    cout << ans << "\n";
    ll l = 1;
    bool flag = 0;
    for (auto i : s)
    {
        if (i == 'R')
        {
            l = (l + n - 2) % n + 1;
            ans = n * (n - 1) / 2 - ans;
            flag = !flag;
        }
        else
        {
            ans = ans - (p[l] - 1) + n - p[l];
            if (!flag)
                l = l % n + 1;
            else
                l = (l + n - 2) % n + 1;
        }
        cout << 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
*/

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

5 10
5 4 3 2 1
SSSSRSSSSR

output:

10
6446466400

result:

ok 2 tokens

Test #2:

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

input:

1 1
1
R

output:

0
0

result:

ok 2 tokens

Test #3:

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

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: -100
Wrong Answer
time: 16ms
memory: 4048kb

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:

wrong answer 2nd words differ - expected: '961454169096145416909614541690...5694101496569410149656941014965', found: '961454169096145416909614541690...5830903854583090385458309038545'