QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#776289#9104. Zayin and ForestTauLee01WA 814ms97008kbC++172.3kb2024-11-23 18:06:552024-11-23 18:06:56

Judging History

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

  • [2024-11-23 18:06:56]
  • 评测
  • 测评结果:WA
  • 用时:814ms
  • 内存:97008kb
  • [2024-11-23 18:06:55]
  • 提交

answer

#pragma GCC optimize(2)
#pragma GCC optimize(3,"Ofast","inline")
#include<bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#include "debug.h"
#else
#define debug(...) 42;
#define endl '\n'
#endif

#define ll long long

const int Maxl = 0, Maxr = 1e18 + 10;
struct d_tree {
    struct op {
        ll num;
        int ls, rs;
    } tre[40004000];
    int cnt = 0;

    //使用前新建一个根点'1',即使用一下build()
    //
    int build()//新建节点
    {   ++cnt;
        tre[cnt].num = tre[cnt].ls = tre[cnt].rs = 0;
        return cnt;
    }

    int upd(int x, ll pos, int val, d_tree &tr, ll l = Maxl, ll r = Maxr)
    {   if (!x)x = tr.build();
        if (l == r) {tre[x].num += val; return x;}
        ll mid = (l + r) >> 1;
        if (pos <= mid)tre[x].ls = tr.upd(tre[x].ls, pos, val, tr, l, mid);
        if (pos > mid)tre[x].rs = tr.upd(tre[x].rs, pos, val, tr, mid + 1, r);
        tre[x].num = tre[tre[x].ls].num + tre[tre[x].rs].num;
        return x;
    }
    ll ask(int x, ll ql, ll qr, d_tree &tr, ll l = Maxl, ll r = Maxr)
    {   if (!x)return 0;
        if (l >= ql && r <= qr) {
            return tre[x].num;
        }
        ll mid = (l + r) >> 1, ans = 0;
        if (ql <= mid)ans += tr.ask(tre[x].ls, ql, qr, tr, l, mid);
        if (qr > mid)ans += tr.ask(tre[x].rs, ql, qr, tr, mid + 1, r);
        return ans;
    }
} tr;
ll nex(ll x) {
    ll ans = 0;
    for (int i = 0; i <= 62; ++i) {
        if (((x >> i) & 1) && (((x >> (i + 1)) & 1) == 0)) {
            ans += 1ll << (i + 1);
            for (int j = i + 2; j <= 62; ++j) {
                if ((x >> j) & 1) {
                    ans += 1ll << j;
                }
            }
            break;
        }
    }
    return ans;
}
signed main()
{
    ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
    int m, val, op;
    ll n, l, r, x;
    cin >> n >> m;

    tr.build();

    for (int i = 1; i <= m; ++i) {
        cin >> op;
        if (op == 1) {
            cin >> x >> val;
            while (x <= n && x) {
                tr.upd(1, x, val, tr);
                x = nex(x);
            }
        }
        else {
            cin >> l >> r;
            cout << tr.ask(1, l, r, tr) << "\n";
        }
    }
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 50ms
memory: 23084kb

input:

1000000000 20000
2 384578735 526547442
1 64211261 592970906
1 512065247 448267721
1 44993150 127180320
1 880319036 927623947
1 170536687 572121854
1 896600029 804033011
1 666246328 754201635
1 654066651 179982083
2 240989825 984888006
2 372004567 858916479
2 76127818 98606736
1 181794163 902842353
1...

output:

0
43148875202
17613404710
0
32808578044
28190043566
15641637055
78276219892
14955165236
20262224725
105057452192
17002492367
57916137452
27165464255
72766353838
39458327919
38294102627
264448717384
0
70928519548
279674530483
88885017175
111664599432
69703816663
211506104092
104120007714
34403738515
...

result:

ok 6649 lines

Test #2:

score: -100
Wrong Answer
time: 814ms
memory: 97008kb

input:

1000000000000000000 100000
1 384578735 526547442
1 64211261 592970906
1 512065247 448267721
1 44993150 127180320
1 880319036 927623947
1 170536687 572121854
1 896600029 804033011
2 666246328 931651408754201635
1 654066651 179982083
1 984888006 240989825
1 372004567 858916479
1 76127818 98606736
1 18...

output:

144205553442
510235368311
903930740555
878459229726
730988902615
859703313829
735231510045
1177875391120
1579047809508
1729703171454
2400695785815
1991476058156
2381861014705
2347408950216
2117738140401
3014076396412
2187638958334
3075172126617
2214794034419
2262561461341
3238736617863
3173110554430...

result:

wrong answer 2nd lines differ - expected: '497561506762', found: '510235368311'