QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#132440 | #6409. Classical Data Structure Problem | UFRJ# | WA | 1ms | 3576kb | C++20 | 2.2kb | 2023-07-29 22:03:28 | 2023-07-29 22:03:30 |
Judging History
answer
#include "bits/stdc++.h"
using namespace std;
using lint = int64_t;
int n, m;
int lo, hi;
int mod = (1<<30);
struct segtree{
vector<lint> s, lazy;
vector<int>lid, rid;
int create(){
int id = int(s.size());
s.push_back(0);
lazy.push_back(0);
lid.push_back(-1);
rid.push_back(-1);
return id;
}
segtree(int n) {
s.reserve(30 * n);
lazy.reserve(30 * n);
lid.reserve(30 * n);
rid.reserve(30 * n);
create();
}
void push(int v, int l, int r){
assert(v < lid.size() and v < rid.size());
assert(v < lid.size() and v < rid.size());
s[v] += (r - l + 1) * lazy[v];
s[v] %= mod;
if(l != r) {
if(lid[v] == -1) lid[v] = create();
if(rid[v] == -1) rid[v] = create();
lazy[lid[v]] += lazy[v];
lazy[lid[v]] %= mod;
lazy[rid[v]] += lazy[v];
lazy[rid[v]] %= mod;
}
lazy[v] = 0;
}
void update(int v, int l, int r, int a, int b, lint x){
assert(v >= 0 and v < s.size());
if(a <= l && r <= b){
lazy[v] += x;
lazy[v] %= mod;
push(v, l, r);
return;
}
if(r < a || l > b) return;
int m = (l + r) >> 1;
push(v, l, r);
update(lid[v], l, m, a, b, x);
update(rid[v], m + 1, r, a, b, x);
s[v] = s[lid[v]] + s[rid[v]];
s[v] %= mod;
}
lint query(int v, int l, int r, int a, int b){
push(v, l, r);
if(a <= l && r <= b) return s[v];
if(r < a || l > b) return 0;
int m = (l + r) >> 1;
return (query(lid[v], l, m, a, b) + query(rid[v], m+1, r, a, b)) % mod;
}
};
int main() {
cin>>n>>m;
lo = 0, hi = (1<<m) - 1;
segtree seg(n);
lint x = 0;
for(int i=1;i<=n;i++){
int p, q, md = (1 << m);
cin>>p>>q;
p = (p + x) % md;
q = (q + x) % md;
int l = min(p, q), r = max(p, q);
seg.update(0, lo, hi, l, r, i);
x = (x + seg.query(0, lo, hi, l, r)) % mod;
// cout<<i<<" "<<x<<"\n";
}
cout<<x<<"\n";
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3532kb
input:
5 2 2 1 1 3 3 2 1 0 0 2
output:
87
result:
ok 1 number(s): "87"
Test #2:
score: 0
Accepted
time: 1ms
memory: 3464kb
input:
1 1 1 1
output:
1
result:
ok 1 number(s): "1"
Test #3:
score: 0
Accepted
time: 1ms
memory: 3460kb
input:
1 2 3 1
output:
3
result:
ok 1 number(s): "3"
Test #4:
score: 0
Accepted
time: 0ms
memory: 3484kb
input:
1 5 31 15
output:
17
result:
ok 1 number(s): "17"
Test #5:
score: 0
Accepted
time: 1ms
memory: 3476kb
input:
1 20 366738 218765
output:
147974
result:
ok 1 number(s): "147974"
Test #6:
score: 0
Accepted
time: 1ms
memory: 3576kb
input:
1 30 86669484 41969116
output:
44700369
result:
ok 1 number(s): "44700369"
Test #7:
score: -100
Wrong Answer
time: 1ms
memory: 3504kb
input:
10 5 20 31 2 2 14 18 13 25 26 4 22 9 15 9 19 16 15 27 9 20
output:
1772
result:
wrong answer 1st numbers differ - expected: '1414', found: '1772'