結果

問題 No.619 CardShuffle
ユーザー parukiparuki
提出日時 2017-12-31 23:15:23
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,962 bytes
コンパイル時間 2,169 ms
コンパイル使用メモリ 171,396 KB
実行使用メモリ 13,912 KB
最終ジャッジ日時 2023-08-24 15:25:14
合計ジャッジ時間 11,494 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 5 ms
9,528 KB
testcase_01 WA -
testcase_02 AC 4 ms
9,552 KB
testcase_03 WA -
testcase_04 AC 5 ms
9,600 KB
testcase_05 AC 5 ms
9,540 KB
testcase_06 WA -
testcase_07 AC 5 ms
9,792 KB
testcase_08 WA -
testcase_09 AC 5 ms
9,588 KB
testcase_10 AC 5 ms
9,512 KB
testcase_11 WA -
testcase_12 AC 5 ms
9,532 KB
testcase_13 WA -
testcase_14 AC 5 ms
9,540 KB
testcase_15 AC 5 ms
9,592 KB
testcase_16 WA -
testcase_17 AC 388 ms
13,676 KB
testcase_18 WA -
testcase_19 AC 397 ms
13,680 KB
testcase_20 AC 357 ms
13,672 KB
testcase_21 WA -
testcase_22 AC 316 ms
13,700 KB
testcase_23 WA -
testcase_24 AC 310 ms
13,732 KB
testcase_25 AC 273 ms
13,760 KB
testcase_26 WA -
testcase_27 AC 456 ms
13,752 KB
testcase_28 WA -
testcase_29 AC 445 ms
13,688 KB
testcase_30 AC 424 ms
13,688 KB
testcase_31 AC 5 ms
9,580 KB
testcase_32 AC 352 ms
13,668 KB
testcase_33 AC 394 ms
13,676 KB
testcase_34 WA -
testcase_35 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include "bits/stdc++.h"
using namespace std;
#define FOR(i,j,k) for(int (i)=(j);(i)<(int)(k);++(i))
#define rep(i,j) FOR(i,0,j)
#define each(x,y) for(auto &(x):(y))
#define mp make_pair
#define mt make_tuple
#define all(x) (x).begin(),(x).end()
#define debug(x) cout<<#x<<": "<<(x)<<endl
#define smax(x,y) (x)=max((x),(y))
#define smin(x,y) (x)=min((x),(y))
#define MEM(x,y) memset((x),(y),sizeof (x))
#define sz(x) (int)(x).size()
#define pb push_back
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ll> vll;

const int MO = (int)1e9 + 7;

int N, n;
string op="+";
vi va;
const int R = 1 << 18 | 1;
vi z[R];

vi mrg(vi &a, vi &b, char o) {
    if (!sz(a))return b;
    if (!sz(b))return a;

    vi r;
    r.reserve(6);
    each(x, a)r.push_back(x);

    if (o == '+') {
        r.push_back(b[0]);
    } else {
        r.back() = (ll)r.back() * b[0] % MO;
    }

    FOR(i, 1, sz(b))r.push_back(b[i]);

    if (sz(r) > 3)swap(r[2], r.back());
    while (sz(r) > 3) {
        (r[2] += r.back()) %= MO;
        r.pop_back();
    }
    return r;
}

void upd(int k, int l, int r, int idx, int val, char o) {
    if (r - l == 1) {
        z[k][0] = val;
        va[l] = val;
        op[l] = o;
        return;
    }
    
    int kl = 2 * k + 1;
    int kr = 2 * k + 2;
    int m = (l + r) >> 1;

    if (idx < m)upd(kl, l, m, idx, val, o);
    else upd(kr, m, r, idx, val, o);
    z[k] = mrg(z[kl], z[kr], op[m]);
}

vi query(int k, int l, int r, int x, int y) {
    if (r <= x || l >= y)return vi(0);
    if (x <= l && r <= y) return z[k];

    int kl = 2 * k + 1;
    int kr = 2 * k + 2;
    int m = (l + r) >> 1;

    vi a = query(kl, l, m, x, y);
    vi b = query(kr, m, r, x, y);
    return mrg(a, b, op[m]);
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);

    cin >> N;
    rep(i, N) {
        char c;
        cin >> c;
        if (i & 1)op += c;
        else va.push_back(c - '0');
    }

    N = 1;
    while (N < sz(op))N *= 2;
    while (sz(op) < N) {
        op += '+';
        va.push_back(0);
    }

    rep(i, 2 * N + 1) {
        z[i].reserve(6);
        z[i].push_back(0);
    }

    rep(i, N) {
        upd(0, 0, N, i, va[i], op[i]);
    }

    int Q;
    cin >> Q;
    while (Q--) {
        char T;
        int X, Y;
        cin >> T >> X >> Y;
        if (T == '!') {
            int md = X % 2;
            X /= 2;
            Y /= 2;
            if (md == 1) { // num
                int vx = va[X], vy = va[Y];
                upd(0, 0, N, X, vy, op[X]);
                upd(0, 0, N, Y, vx, op[Y]);
            } else {
                char ox = op[X], oy = op[Y];
                upd(0, 0, N, X, va[X], oy);
                upd(0, 0, N, Y, va[Y], ox);
            }
        } else {

            X /= 2;
            Y = Y / 2 + 1;

            ll ans = 0;
            auto w = query(0, 0, N, X, Y);
            each(x, w)ans += x;
            cout << ans%MO << endl;
        }
    }
}
0