QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#776310 | #9104. Zayin and Forest | TauLee01 | WA | 973ms | 97228kb | C++20 | 2.3kb | 2024-11-23 18:11:44 | 2024-11-23 18:11:44 |
Judging History
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
// #define int 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(__int128 x, ll n) {
__int128 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;
}
}
if (ans > n)return 0;
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, n);
}
}
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: 64ms
memory: 24660kb
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: 973ms
memory: 97228kb
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'